呵呵,通过:
/* ID: qq104801 LANG: 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 ",k[i].a,k[i].b); } //printf(" "); qsort(k,n,sizeof(kk),cmp); for(i=0;i<n;i++) { //printf("%d %d ",k[i].a,k[i].b); } milk(); //printf("max1:%d max2:%d ",max1,max2); fprintf(fout,"%d %d ",max1,max2); fclose(fin); fclose(fout); exit (0); }
呵呵,测试数据:
USER: ll tom [qq104801] TASK: milk2 LANG: C++ Compiling... Compile: OK Executing... 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 ---- 1 100 200 ------- test 2 ---- 4 100 200 201 301 302 402 403 503 ------- test 3 ---- 10 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 1 20 ------- test 4 ---- 3 100 102 64100 64102 128100 128102 ------- test 5 ---- 100 99000 101000 98000 102000 97000 103000 96000 104000 95000 105000 94000 106000 93000 107000 92000 108000 91000 109000 90000 110000 89000 111000 88000 112000 87000 113000 86000 114000 85000 115000 84000 116000 83000 117000 82000 118000 81000 119000 80000 120000 79000 121000 78000 122000 77000 123000 76000 124000 75000 125000 74000 126000 73000 127000 72000 128000 71000 129000 70000 130000 69000 131000 68000 132000 67000 133000 66000 134000 65000 135000 64000 136000 63000 137000 62000 138000 61000 139000 60000 140000 59000 141000 58000 142000 57000 143000 56000 144000 55000 145000 54000 146000 53000 147000 52000 148000 51000 149000 50000 150000 49000 151000 48000 152000 47000 153000 46000 154000 45000 155000 44000 156000 43000 157000 42000 158000 41000 159000 40000 160000 39000 161000 38000 162000 37000 163000 36000 164000 35000 165000 34000 166000 33000 167000 32000 168000 31000 169000 30000 170000 29000 171000 28000 172000 27000 173000 26000 174000 25000 175000 24000 176000 23000 177000 22000 178000 21000 179000 20000 180000 19000 181000 18000 182000 17000 183000 16000 184000 15000 185000 14000 186000 13000 187000 12000 188000 11000 189000 10000 190000 9000 191000 8000 192000 7000 193000 6000 194000 5000 195000 4000 196000 3000 197000 2000 198000 1000 199000 0 200000 ------- test 6 ---- 6 100 200 200 400 400 800 800 1600 50 100 1700 3200 ------- test 7 ---- 1000 26022 26065 17435 17463 17766 17811 6543 6575 19436 19516 17161 17174 11704 11736 11040 11088 8106 8142 19810 19855 9464 9473 13056 13082 20364 20421 19954 19959 2697 2765 3465 3548 9267 9282 26107 26138 20459 20550 14267 14358 14968 15068 12099 12156 21594 21616 7965 8023 11094 11171 453 480 15105 15113 26944 27006 11120 11126 21755 21819 24531 24628 26838 26900 18740 18760 14038 14044 24321 24322 1917 1971 14251 14321 14145 14146 8207 8225 18448 18454 8917 8949 1116 1180 29584 29606 28081 28127 7356 7428 31553 31555 21880 21893 5218 5231 5903 5983 27001 27100 6937 6962 24391 24466 26994 27055 13325 13381 19376 19381 21636 21639 29536 29630 12074 12081 2985 3033 7868 7884 15284 15331
。。。。。。