본문 바로가기

pku

PKU 1953. World Cup Noise. AC 정상코드 #include int fib(int a) { int bef=1, sum=1, cnt; for(cnt=1; cnt 더보기
PKU 2845. 01000001. WA #include #include void scan(int *a) { int i, len; char tmp[90]; scanf("%s",tmp); len=strlen(tmp); len--; i=89; while(len>=0) { a[i--]=tmp[len--]-'0'; } } void sum(int *a, int *b) { int i, j; i=89;//a,b while(i) { a[i]+=b[i]; for(j=i; a[j]>=2; j--) { a[j-1]++; a[j]-=2; } i--; } } void print(int *a) { int i=0; while(a[i]==0)i++; while(i 더보기
PKU 1953. World Cup Noise 월드컵 소음 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5818 Accepted: 2851 설명 배경지식 "KO-RE-A, KO-RE-A" 54000명의 행복에 가득찬 축구 팬들이, 한국 팀이 조국에서 열린 FIFA 월드컵 준결승에 올랐을때 소리쳤다. 그러나 비록 그들의 그런 흥분감이 정말이었더라도, 한국 사람들은 여전히 조직적이었다. 예를 들면 그들은 배의 고동소리와 비슷하게 들릴 정도의, 큰 트럼펫들을 준비하여 경기장에서 뛰는 한국팀을 응원했다. 팬들은 경기가 진행되는 내내 소음의 수준을 유지하려 했다. 트럼펫은 압축가스로 작동되었다. 그러나 만약 트럼펫을 2초 이상 쉬지 않고 분다면 그것은 고장날 것이다. 그래서 트럼펫으로 소리를 낼 때.. 더보기
PKU 1953. World Cup Noise World Cup Noise Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5818 Accepted: 2851 Description Background "KO-RE-A, KO-RE-A" shout 54.000 happy football fans after their team has reached the semifinals of the FIFA World Cup in their home country. But although their excitement is real, the Korean people are still very organized by nature. For example, they have organized huge trumpets.. 더보기
PKU 2845. 01000001 01000001 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5031 Accepted: 1654 설명 이진수를 더하는 것은 매우 쉬운 일이며, 일반적인 십진수의 덧셈과 매우 유사합니다. 십진수를 더할때와 같이, 당신은 한 번에 한 줄에 있는 비트(아라비아 숫자)들을 오른쪽에서 왼쪽으로 씁니다. 십진수끼리의 덧셈과는 달리, 이진수들을 더할때에 기억해야 할 것이 몇가지 있습니다 : 0 + 0 = 0 1 + 0 = 1 0 + 1 = 1 1 + 1 = 10 1 + 1 + 1 = 11 십진수의 덧셈과 같이, 한 줄에 더해진 총합이 두 자리 비트(두 자리 수)일 경우 의미가 적은 숫자는 총 합의 부분으로 쓰여지고 의미가 큰 숫자는 왼쪽 줄로 '옮겨집니다'.. 더보기
PKU 2845. 01000001 01000001 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5031 Accepted: 1654 Description Adding binary numbers is a very simple task, and very similar to the longhand addition of decimal numbers. As with decimal numbers, you start by adding the bits (digits) one column at a time, from right to left. Unlike decimal addition, there is little to memorize in the way of rules for the addit.. 더보기
PKU 1298. The Hardest Probelm Ever. AC #include int main() { char string[101]; int i; while(1) { gets(string); if(strcmp("ENDOFINPUT",string)==0) return 0; if(strcmp("START",string)==0 || strcmp("END",string)==0) continue; for(i=0; string[i]!=0; i++) { if (string[i]='A') printf("%c",string[i]+21); else if (string[i]>'E' && string[i] 더보기
PKU 1089. Intervals. AC #include typedef struct { int start,end; }inter; int fcmp(inter *a, inter *b) { return a->start-b->start; } main() { int i, n; inter input[50000], *p; while(scanf("%d",&n)!=EOF) { for(i=0; iend) { printf("%d %d\n",p->start,p->end); p->start=input[i].start; p->end=input[i].end; } if(input[i].end > p->end) p->end=input[i].end; } printf("%d %d\n",p->start,p->end); } } Run ID User Problem Result Mem.. 더보기
PKU 1089. Intervals. TLE #include typedef struct { int start,end; }inter; int fcmp(inter *a, inter *b) { return a->start-b->start; } main() { int i, j, n; inter input[50000]; while(scanf("%d",&n)!=EOF) { for(i=0; i 더보기
PKU 1089. Intervals. AC get.... -_-; #include #include #include using namespace std; typedef struct { int start, end; }dis; int cmp(const void * a, const void * b) { dis * first = (dis *)a; dis * second = (dis *)b; if (first->start == second->start) { return first->end - second->end; } return first->start - second->start; } dis list[50000]; int main() { int n, i, min, max; cin >> n; i = 0; while(i < n) { scanf("%d%d", &(list[i].sta.. 더보기
PKU 1089. Intervals. WA. #include #include #include using namespace std; typedef struct { int start, end; }dis; int main() { list a; list::iterator InnerIt, OuterIt; bool isIn; dis temp; int n; cin >> n; while(n--) { isIn = false; cin >> temp.start >> temp.end; a.push_back(temp); } for (OuterIt = a.begin(); OuterIt != a.end(); OuterIt++) { for (InnerIt = a.begin(); InnerIt != a.end(); InnerIt++) { if (OuterIt == InnerIt.. 더보기
PKU 1089. Intervals 구간 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2973 Accepted: 1158 설명 n개의 폐구간 [ai; b i], i=1,2,...,n 이 주어졌습니다. 이 구간들의 합은 교차하지 않는 폐구간들의 쌍으로 표현될 수 있습니다. 당신이 해야 할 일은 이러한 구간들의 표현을 최소한의 숫자로 하는 것입니다. 이렇게 표현할 구간들은 오름차순으로 출력되어야 합니다. 오름차순이란 a 더보기
PKU 1089. Intervals Intervals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2973 Accepted: 1158 Description There is given the series of n closed intervals [ai; b i], where i=1,2,...,n. The sum of those intervals may berepresented as a sum of closed pairwise non−intersecting intervals. The task is to find such representation with the minimal number of intervals. The intervals of this representation sho.. 더보기
PKU 3685. Matrix. Solution. #include #include int main() { int n; __int64 N, M; __int64 min, max; __int64 x, j; __int64 sum; __int64 det, cal_1, cal_2; const __int64 w = 100000; scanf("%d", &n); while (n--) { scanf("%I64d%I64d", &N, &M); max = w * w * 10; min = -1 * max; while (min < max) { x = (min + max) / 2; if (x == max) { x--; } sum = 0; for (j = 1 ;(j = cal_1) { sum += (cal_2 - cal_1 + 1); } } if (sum < M) { min = x .. 더보기
UVa. 112, PKU 1145. Tree Summing. AC #include int num,yes; char ch; int func(int sum) { int n,leaf=0; if(scanf(" %d",&n)) { sum+=n; scanf(" %c",&ch); leaf+=func(sum); scanf(" %c",&ch); leaf+=func(sum); if(leaf==2 && sum==num) { yes=1; } } else { if(scanf(" %c",&ch)) { if(ch==')') return 1; } } if(scanf(" %c",&ch)) { if(ch==')') return 0; } } main() { while (scanf("%d", &num) != EOF) { scanf(" %c",&ch); func(0); if(yes==1) puts("yes.. 더보기
PKU 3438. Look and Say. AC #include #include main() { char string[1001]; int n, i, cnt, lenth; scanf("%d",&n); while(n--) { scanf("%s",string); lenth=strlen(string); for(i=0, cnt=1; i 더보기
PKU 1298. The hardest problem ever. AC get -_- #include #include int main() { char start[256], temp[256]; int i; while(gets(start)) { if (!strcmp(start, "ENDOFINPUT")) { break; } gets(temp); for (i = 0; i 'E' && temp[i] 더보기
PKU 1298. The Hardest Probelm Ever 지금껏 가장 힘들었던 문제 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8523 Accepted: 4866 설명 Julius Caesar는 음모와 위험이 살아숨쉬는 시대에 살았습니다. Caesar가 겪었던 가장 힘들었던 상황은 그 스스로 살아남는 것이었습니다. 살아남기 위해서 그는 최초의 암호라고 불릴 수 있는 것을 만들었습니다. 이 암호는 믿을수 없을 정도로 완벽해서 어떻게 작동하는지 알지 않고서는 누구도 그 원리를 밝혀내지 못했습니다. 당신은 Caesar의 군대의 부사령관입니다. 당신의 임무는 Ceasar에게 온 메세지를 해독하여 사령관에게 전달하는 것입니다. 암호는 간단합니다. 평문의 각 문자를 오른쪽으로 다섯번 움직이면 안전한 메시지, .. 더보기
PKU 1298. The Hardest Problem Ever The Hardest Problem Ever Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8523 Accepted: 4866 Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. In order for him to survive, he decided to create one of the first ciphers. This cipher was so incredibly sound, that no one could figure it out without knowing .. 더보기
PKU 3438. Look and Say. AC get~ -_-! #include #include using namespace std; int main() { string temp; int cases, i, cnt, lastindex; cin >> cases; while (cases--) { i = 1; cnt = 1; getline(cin, temp); if (temp == "") { cases++; continue; } while (temp[i] != '\0') { if (temp[i - 1] == temp[i]) { cnt++; } else { cout 더보기
PKU 3438. Look and Say 본 뒤 말하기 Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2978 Accepted: 1905 설명 본 뒤 말하는 수열은 다음과 같습니다. 아무 숫자열 하나를 가지고 시작하는데, 그 다음으로 오는 각각의 부분열 원소는 그 전의 숫자열을 하나씩 '음성으로' 표현하는 것입니다. 예를 들면, 숫자열 122344111 은 "한 개의 1, 두 개의 2, 한 개의 3, 두 개의 4, 세 개의 1." 로 읽어지므로 그 다음에 올 수열은 1122132431입니다. 비슷하게, 숫자열 101은 1111111111 다음으로 오게 됩니다. 하지만, 어떤 숫자열을 보고 그 전의 숫자열이 유일한 표현을 가질것이라는 생각은 잘못된 것입니다. 예를 들어, 112213243.. 더보기
PKU 3438. Look and Say Look and Say Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2978 Accepted: 1905 Description The look and say sequence is defined as follows. Start with any string of digits as the first element in the sequence. Each subsequent element is defined from the previous one by "verbally" describing the previous element. For example, the string 122344111 can be described as "one 1, two 2's, .. 더보기
PKU 3030. Nasty Hacks. AC Get -_-.. #include using namespace std; int main() { int N, RespectNot, Respect, AdvPay; cin >> N; while(N--) { cin >> RespectNot >> Respect >> AdvPay; if((Respect - RespectNot) > AdvPay) { cout 더보기
PKU 3030. Nasty Hacks 더러운 핵프로그램(?) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3479 Accepted: 2596 설명 당신은 Nasty Hacks 회사라는, 십대들이 그들의 멍청한 친구들을 골탕먹일때 쓸 수 있는 간단한 소프트웨어를 만드는 곳의 CEO 입니다. 이제서야 첫 상품을 개발하여 판매를 시작해야 합니다. 당신은 가능한한 많은 돈을 벌고 싶고 판매량을 늘리기 위해 광고하는 것을 생각해봅니다. 당신은 기업 분석가를 찾아가, 광고를 할 경우와 광고를 하지 않을 경우 두 경우에 대해서 각각 어떤 수익이 기대되는지를 알고자 합니다. 이제 당신은 주어진 기대 수익을 가지고, 광고를 할 것인지, 하지 않을 것인지를 결심해야 합니다. 입력 입력은 n 케이스들.. 더보기
PKU 3030. Nasty Hacks Nasty Hacks Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3479 Accepted: 2596 Description You are the CEO of Nasty Hacks Inc., a company that creates small pieces of malicious software which teenagers may use to fool their friends. The company has just finished their first product and it is time to sell it. You want to make as much money as possible and consider advertising in order.. 더보기
PKU 2521. How much did the businessman lose. AC get~ main(N,M,P){for(;scanf("%d%d%d%*d",&N,&M,&P),N;printf("%d\n",N-M+P));} 낄낄. 전에 지군 앞에서 숏코딩 보여줬던 문제였는데 이걸 번역하다니 -_-a 더보기
PKU 2521. How much did the businessman lose 사업가는 얼마를 잃었을까 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5019 Accepted: 3449 설명 사업가는 돈을 많이 벌 수 있습니다. 그러나 때때로 거래과정에서 돈을 많이 잃을 수도 있습니다. 예를 들어 한 사업가 Jame 은 몇몇 물품을 개당 40위안에 사서 개당 70위안에 팔 생각을 했습니다. 그리고 한 고객이 와서 물건을 사면서 Jame에게 100위안을 냈고 Jame은 30위안을 거슬러 주었습니다. 당신은 아마도, "Jame이 30위안을 벌었다"라고 할 지 모릅니다. 그러나 불행하게도 Jame은 고객에게 받은 100위안이 가짜였다는 것을 발견합니다. 참 불쌍하지요? 이 경우 Jame은 70위안을 잃었습니다.(40위안(물건의 .. 더보기
PKU 2521. How much did the businessman lose How much did the businessman lose Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5019 Accepted: 3449 Description Businessmen, of course, can make much money. However, sometimes, they would lose money in trading. For example, Jame, a businessman, brought in some goods each cost him 40 yuan and he decided to sell at the price of 70 yuan. Then a customer came to buy one, gave Jame 100 y.. 더보기
PKU 2636. 전기콘센트(?) AC get~-_- #include using namespace std; int main() { int N, K, sum, s; cin >> N; while(N--) { cin >> K; sum = 0; while (K--) { cin >> s; sum += s; sum--; } cout 더보기
PKU 2636. Elecrical Outlets Electrical Outlets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3730 Accepted: 2806 Description Roy has just moved into a new apartment. Well, actually the apartment itself is not very new, even dating back to the days before people had electricity in their houses. Because of this, Roy's apartment has only one single wall outlet, so Roy can only power one of his electrical applianc.. 더보기