首页 > 代码库 > usaco-milk2-pass
usaco-milk2-pass
呵呵,通过:
/*ID: qq104801LANG: C++TASK: milk2*/#include <stdio.h>#include <stdlib.h>#include <string.h>/* for debug only:counter*/void debug_dummy(void){ return;}typedef struct _kk{ int a; int b;}kk,*pkk;kk k[5050];int n;int max1,max2;int cmp(const void *a,const void *b){ kk *p=(kk*)a,*q=(kk*)b; if (p->a!=q->a) return p->a - q->a; return p->b - q->b; }void milk(){ int m,end,i; max2=0; max1=m=k[0].b-k[0].a; end=k[0].b; for (i=1;i<n;i++) { if(k[i].a>end) { if((k[i].a-end)>max2) { max2=k[i].a-end; } m=k[i].b-k[i].a; } if(k[i].a<=end && k[i].b>end) { m+=k[i].b-end; } if(m>max1) max1=m; if(k[i].b>end) end=k[i].b; } }main () { FILE *fin = fopen ("milk2.in", "r"); FILE *fout = fopen ("milk2.out", "w"); fscanf(fin,"%d",&n); int i; for(i=0;i<n;i++) { fscanf(fin,"%d %d",&k[i].a,&k[i].b); //printf("%d %d\n",k[i].a,k[i].b); } //printf("\n"); qsort(k,n,sizeof(kk),cmp); for(i=0;i<n;i++) { //printf("%d %d\n",k[i].a,k[i].b); } milk(); //printf("max1:%d max2:%d\n",max1,max2); fprintf(fout,"%d %d\n",max1,max2); fclose(fin); fclose(fout); exit (0);}
呵呵,测试数据:
USER: ll tom [qq104801]TASK: milk2LANG: C++Compiling...Compile: OKExecuting... Test 1: TEST OK [0.003 secs, 3532 KB] Test 2: TEST OK [0.008 secs, 3532 KB] Test 3: TEST OK [0.008 secs, 3532 KB] Test 4: TEST OK [0.003 secs, 3532 KB] Test 5: TEST OK [0.003 secs, 3532 KB] Test 6: TEST OK [0.005 secs, 3532 KB] Test 7: TEST OK [0.014 secs, 3532 KB] Test 8: TEST OK [0.024 secs, 3532 KB]All tests OK.Your program (‘milk2‘) produced all correct answers! This is your submission #5 for this problem. Congratulations!Here are the test data inputs:------- test 1 ----1100 200------- test 2 ----4100 200201 301302 402403 503------- test 3 ----102 34 56 78 910 1112 1314 1516 1718 191 20------- test 4 ----3100 10264100 64102128100 128102------- test 5 ----10099000 10100098000 10200097000 10300096000 10400095000 10500094000 10600093000 10700092000 10800091000 10900090000 11000089000 11100088000 11200087000 11300086000 11400085000 11500084000 11600083000 11700082000 11800081000 11900080000 12000079000 12100078000 12200077000 12300076000 12400075000 12500074000 12600073000 12700072000 12800071000 12900070000 13000069000 13100068000 13200067000 13300066000 13400065000 13500064000 13600063000 13700062000 13800061000 13900060000 14000059000 14100058000 14200057000 14300056000 14400055000 14500054000 14600053000 14700052000 14800051000 14900050000 15000049000 15100048000 15200047000 15300046000 15400045000 15500044000 15600043000 15700042000 15800041000 15900040000 16000039000 16100038000 16200037000 16300036000 16400035000 16500034000 16600033000 16700032000 16800031000 16900030000 17000029000 17100028000 17200027000 17300026000 17400025000 17500024000 17600023000 17700022000 17800021000 17900020000 18000019000 18100018000 18200017000 18300016000 18400015000 18500014000 18600013000 18700012000 18800011000 18900010000 1900009000 1910008000 1920007000 1930006000 1940005000 1950004000 1960003000 1970002000 1980001000 1990000 200000------- test 6 ----6100 200200 400400 800800 160050 1001700 3200------- test 7 ----100026022 2606517435 1746317766 178116543 657519436 1951617161 1717411704 1173611040 110888106 814219810 198559464 947313056 1308220364 2042119954 199592697 27653465 35489267 928226107 2613820459 2055014267 1435814968 1506812099 1215621594 216167965 802311094 11171453 48015105 1511326944 2700611120 1112621755 2181924531 2462826838 2690018740 1876014038 1404424321 243221917 197114251 1432114145 141468207 822518448 184548917 89491116 118029584 2960628081 281277356 742831553 3155521880 218935218 52315903 598327001 271006937 696224391 2446626994 2705513325 1338119376 1938121636 2163929536 2963012074 120812985 30337868 788415284 15331
。。。。。。
usaco-milk2-pass
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。