백준 2798번: 블랙잭
해결 X
My Solution:
예제 1번 통과
예제 2번 실패 - #2 출력 X
import copy as c
N, M = [int(i) for i in input().split()]
cards = [int(j) for j in input().split()]
cards.sort(reverse=True)
result = 0
count = 0 # max count = 3
for a in range(len(cards)-1):
sample = 0
cards2 = c.deepcopy(cards)
print('\n-------------------\ncards2 = {}'.format(cards2))
for item in cards2:
if item <= M:
sample += item
count += 1
cards2.pop(0)
print('\n#1')
print('cards2 = {}\n'.format(cards2) +
'item = {}\n'.format(item) +
'sample = {}'.format(sample))
break
for item2 in cards2:
if (sample + item) <= M:
sample += item2
count += 1
cards2.pop(0)
print('\n#2')
print('cards2 = {}\n'.format(cards2) +
'item2 = {}\n'.format(item2) +
'sample = {}'.format(sample))
break
for item3 in cards2:
if (sample + item3) <= M:
sample += item3
count += 1
cards2.pop(0)
print('\n#3')
print('cards2 = {}\n'.format(cards2) +
'item3 = {}\n'.format(item3) +
'sample = {}'.format(sample))
break
if (result < sample) and (sample <= M) and (count == 3):
result = sample
del cards[1]
count = 0
print("\n===================")
print(result)
밥먹고 학원다녀오겠읍니다
1 Like
여전히 해결 X,
너무 오랜만에 학교 가기도 했고
고등학교라 그런지 평상시보다 조금 피곤하네요…
My Solution
#include <iostream>
#include <algorithm>
int fctrl(int fn);
bool cmp_s(int a, int b);
void print_array(int* f_array, int a_len);
int main()
{
using namespace::std;
int N, M, result = 0, r_max = 0;
int sample = 0, count = 0;
cin >> N >> M;
int* cards = new int[N];
for (int i = 0; i != N; i++)
cin >> cards[i];
sort(cards, cards + N, cmp_s);
// print_array(cards, N);
for (int j = 0; j != N-2; j++)
{
sample = cards[j];
count++;
for (int l = j; l != N-1; l++)
{
sample += cards[l];
count++;
for (int q = l; q != N; q++)
{
sample += cards[q];
count++;
if ((r_max < sample) && (sample <= M) && (count == 3))
r_max = sample;
sample -= cards[q];
count--;
}
sample -= cards[l];
count--;
}
sample -= cards[j];
count--;
}
result = r_max;
cout << result << "\n";
return 0;
}
int fctrl(int fn)
{
if (1 >= fn)
return 1;
return fn * fctrl(fn-1);
}
bool cmp_s(int a, int b)
{
return a > b;
}
void print_array(int* f_array, int a_len)
{
using namespace::std;
for (int i = 0; i != a_len; i++)
{
cout << f_array[i] << " ";
}
cout << "\n";
}
막상 다시 학교공부하려니까
프로그래밍이 너무 재밌네요…
Cpp로 한 번 시도해봤습니다만
어딘가 오류는 있는데
찾기에는 시간이 늦어서
다음에 이어서 하겠슴다
드뎌해결
My Correct Answer
#include <iostream>
#include <algorithm>
bool cmp_s(int a, int b);
void print_array(int* f_array, int a_len);
int main()
{
using namespace::std;
int N, M, result = 0, r_max = 0;
int sample = 0, smpl1 = 0, smpl2 = 0, smpl3 = 0;
cin >> N >> M;
int* cards = new int[N];
// 배열 입력받고 내림차순으로 정렬
for (int i = 0; i != N; i++)
cin >> cards[i];
sort(cards, cards + N, cmp_s);
// print_array(cards, N);
// 제일 역겨운 부분
for (int j = 0; j != N-2; j++)
{
smpl1 = cards[j];
for (int l = j+1; l != N-1; l++)
{
smpl2 = cards[l];
for (int q = l+1; q != N; q++)
{
smpl3 = cards[q];
sample = smpl1 + smpl2 + smpl3;
// cout << smpl1 << " + " << smpl2 << " + " << smpl3 << " = " << sample << "\n";
if ((r_max < sample) && (sample <= M))
r_max = sample;
}
}
}
result = r_max;
cout << result << "\n";
delete[] cards;
return 0;
}
bool cmp_s(int a, int b)
{
return a > b;
}
void print_array(int* f_array, int a_len)
{
using namespace::std;
for (int i = 0; i != a_len; i++)
{
cout << f_array[i] << " ";
}
cout << "\n";
}
학교 야자시간에 자습하다가 갑자기 아이디어 생각나서
참다가 죽는 줄 알았습니다
2 Likes
ㅊㅊㅊ
1 Like
너희 두분이 같은사람이 아니었나요?
1 Like
Nope
1 Like
원래 같은 사람이었는데, 제 영혼 일부가 분리되서 저는 지박령되고 저거는 사람으로 환생한거에요
한삶두생?
1 Like