본문 바로가기

Solutions

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 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 Problem Ever. [판정:AC] 인증 포스트를 수정하다보니 결과에는 이상이 없지만 알고리즘은 잘못된부분이 있어서 그 부분을 수정하고 제출했는데 pku 서버가 맛이 갔는지 어쩐지 지금 Waiting하는 사람들만 2page를 채우는듯 -_-; 소스 #include #include #include int compare( char *src, char *des ) { int i; for( i = 0; des[i] != '\0'; i++ ) { if( src[i] != des[i] ) return 0; } if( strlen(src) == strlen(des) ) { return 1; } else return 0; } void main() { char str[201]; int progress = 0; while( gets(str) ) { int .. 더보기
PKU [3438]. Look and Say. [AC] #include #include char input[1001]; int main() { int n, i; int cnt = 1; int temp; scanf("%d", &n); while(n--) { scanf("%s", input); temp = strlen(input); for(i=0 ; i 더보기
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. [판정:AC] 난! 올라온 문제를 풀 뿐이고! 난이도는 아직 그대로일 뿐이고! 얼떨결에 sparking군 불지르는데 동참하고 있을 뿐이고! #include void main() { char str[1001] = ""; int cases; scanf("%d", &cases); while( cases > 0 ) { int count; char num; int i; scanf("%s", str); count = 1; num = str[0]; for( i = 1; str[i] != '\0'; i++ ) { if( num != str[i] ) { printf("%d%c", count, num); count = 1; num = str[i]; } else { count++; } } printf("%d%c\n", count, num.. 더보기
PKU 2521. How much did the businessman lose. AC #include main() { int n, m, p, c; while(scanf("%d %d %d %d",&n,&m,&p,&c)) { if(n+m+c+p==0) break; printf("%d\n",n-m+p); } } 흠..... 똑같네요 ㅇㅅㅇ 더보기
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 [2636]. Electrical Outlets. [AC] #include int main() { int n, k, i; int sum = 0, temp; scanf("%d", &n); while(n--) { scanf("%d", &k); for(i=0 ; i 더보기
PKU [3030]. Nasty Hacks. [AC] #include int main() { int n, r, e, c; scanf("%d", &n); while(n--) { scanf("%d%d%d", &r, &e, &c); if((e - r) > c) { printf("advertise\n"); } else if((e - r) == c) { printf("does not matter\n"); } else { printf("do not advertise\n"); } } return 0; } In PKU Judge system. 흠... 굳이 코드를 설명할 필요는 없을듯? -_- 잠이 안오는지라... 뒹굴대다 굴러나와서 풀었음. 더보기
PKU 3030. Nasty Hacks. [판정:AC] 문제를 번역하는 지군에게는 미안하지만 이거, 사업가 문제(pku 2521)와 매우 유사한 문제인듯 -ㅠ- #include void main() { int n; int r; int e; int c; scanf("%d", &n); while( n > 0 ) { scanf("%d %d %d", &r, &e, &c); if( r > e-c ) { printf("do not advertise\n"); } else if( r < e-c ) { printf("advertise\n"); } else { printf("does not matter\n"); } n--; } } 더보기
PKU [2521]. How much did the businessman lose. [AC] #include int main() { int N, M, P, C; while(1) { scanf("%d%d%d%d", &N, &M, &P, &C); if((N == 0) && (M == 0) && (P == 0) && (C == 0) ) { return 0; } printf("%d\n", N - M + P); } return 0; } In PKU Judge system. ... 지군 혹사시키는 것 같아서 미안하구려. 더보기
PKU 2521. How much did the businessman lose. [판정:AC] 처음에 소스 완성을 하고 나서 보니 문제도 쉬운 것 같고, 심심하기도 하고 해서 숏코딩을 했습니다 그 결과가 147B이고, 아래 코드는 먼저 완성된 314B짜리입니다 아, 개인적으로 전 숏코딩 싫어합니다, 오해 없으시길 #include void main() { int n; int m; int p; int c; int lose = 0; while( scanf("%d %d %d %d", &n, &m, &p, &c) ) { if( n == m && m == p && p == c && c == 0 ) break; lose += n; if( m >= p ) lose -= m - p; else lose += p - m; printf("%d\n", lose); lose = 0; } } 더보기
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 2636. Electrical Outlets. [판정:AC] 아 이런 어처구니없는 실수를 하다니; #include void main() { int n; int k; int o[11] = {0}; int i; int able; scanf("%d", &n); while( n > 0 ) { able = 1; scanf("%d", &k); able -= k; for( i = 0; i < k; i++ ) { scanf("%d", &o[i]); } o[i] = -1; for( i = 0; o[i] != -1; i++ ) { able += o[i]; } printf("%d\n", able); n--; } } ..님이 지적해주신 부분을 수정하고나서 보니 able변수를 매 케이스마다 초기화해주는걸 깜빡했군요; 요즘 유독 exception 잡는 것에 신경쓰고 있는데 이런걸 놓치다니.. 더보기
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. Electrical Outlets. AC 숏코딩 main(i,j,k,sum){for(scanf("%d",&i);i--;printf("%d\n",sum+1))for(sum=0,scanf("%d",&j);j--;scanf("%d",&k),sum+=k-1);} 정상소스 #include main() { int i, j, k, sum=0; scanf("%d",&i); while(i--) { sum=0; scanf("%d",&j); while(j--) { scanf("%d",&k); if(j) k--; sum+=k; } printf("%d\n",sum); } } Run ID User Problem Result Memory Time Language Code Length Submit Time 4433684 jht009 2636 Accepted 204K 0MS.. 더보기
PKU 2636. Electrical Outlets. [판정:RE] why?! #include void main() { int n; int k; int o[10] = {0}; int i; int able = 1; scanf("%d", &n); while( n > 0 ) { scanf("%d", &k); able -= k; for( i = 0; i < k; i++ ) { scanf("%d", &o[i]); } o[i] = -1; for( i = 0; o[i] != -1; i++ ) { able += o[i]; } printf("%d\n", able); n--; } } 그냥 쉬운 문제겠거니 하고 코딩했는데 이게 왠? -_-; 더보기
PKU 1979. Red and Black. [판정:AC] 발견 하나, 제목을 줄이면 R&B가 됩니다 :D #include #include int getRow( int position ); int getCol( int position ); void search( char *fld, char *brd, int position ); void RedNBlack( char *fld, int ara, int origin ); int row; int column; void main() { char *field; while(1) { scanf("%d %d", &column, &row); if( row == 0 && column == 0 ) break; else if( row > 0 && column > 0 ) { int area = row * column; int i; ch.. 더보기
PKU 3094. Quicksum. [판정:AC] #include void main() { char str[256]; do { gets( str ); if( str[0] == '#' ) break; else { int sum = 0; int i; for( i = 0; str[i] != '\0'; i++ ) { if( str[i] == ' ' ) continue; else sum += (str[i] - 'A' + 1) * (i + 1); } printf("%d\n", sum); } } while(1); } 매우 오랜만에 문제를 풀어보는 것 같군요 그동안 학교일이 바쁘다는 핑계로 안했었는데 -_-; 더보기
PKU 1979. Red and Black. AC #include char string[20][20]; int y,x=1; int cnt; void back(int yy,int xx) { cnt++; string[yy][xx]='#'; if(yy>0 && string[yy-1][xx]=='.') back(yy-1,xx); if(yy0 && string[yy][xx-1]=='.') back(yy,xx-1); if(xx 더보기
PKU 1979. Red and Black. AC get~ #include #include #include using namespace std; char a[101][101]; int b[101][101]; int total, m, n; void __fastcall isMovable(int x, int y) { total++; b[x][y] = 1; if (x - 1 >= 0) { if (a[x - 1][y] == '.' && b[x - 1][y] == 0) { isMovable(x - 1,y); } } if (x + 1 = 0) { if (a[x][y - 1] == '.' && b[x][y - 1] ==.. 더보기
PKU 3094. Quicksum AC 네요~ #include #include int main(void) { char index[1000]; int i=0,temp=0; while(1){ gets(index); temp=0; i=0; if(strcmp(index,"#")==0) break; while(index[i]!='\0'){ if(index[i]==' ') temp=temp; else temp=temp+((i+1)*(index[i]-64)); i++; } printf("%d\n",temp); } return 0; } 일단 문자열값을 입력받습니다. "#"인지 판별한뒤 맞다면 종료 아니라면 프로그램이 진행됩니다. 일단 문자열의 끝이 아니라면, 입력받은 값이 ' '(공백문자)인지 판별하여 맞으면 그냥 다음으로 넘어가고, 아니라면 temp에 해당 배열.. 더보기
PKU 3077. Rounders AC 네요~ include #include int main(void) { char index[10]; int i=0,j,k,count,out; scanf("%d",&count); for(k=0;k=1 ; j--){ if(j==1){ if(index[1]==':'){ index[1]='0'; index[0]='1'; } } else if(index[j] >= '5' || index[j]==':'){ index[j-1]++; index[j]='0'; } else index[j]='0'; } } out=atoi(index); printf("%d\n",out); } return 0; } 음 이상하게 짠듯하긴한데... 우선 저는 문자열 형태로 배열에 값을 입력 받았습니다. index[0]은 0으로 넣어두고 index[1]부터.. 더보기