这个题目比较抽象:
/* ID: qq104801 LANG: C++ TASK: milk3 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #define NMAX 21 #define min(a,b) (a>b?b:a) int a,b,c; int v[21][21][21]={0}; void dfs(int x,int y,int z) { if (x<0 || y<0 || z<0)return; if(!v[x][y][z]) { v[x][y][z]=1; dfs(x+min(y,a-x),y-min(y,a-x),z); dfs(x+min(z,a-x),y,z-min(z,a-x)); dfs(x-min(x,b-y),y+min(x,b-y),z); dfs(x,y+min(z,b-y),z-min(z,b-y)); dfs(x-min(x,c-z),y,z+min(x,c-z)); dfs(x,y-min(y,c-z),z+min(y,c-z)); } } int k[21]; int t=0; void test() { FILE *fin = fopen ("milk3.in", "r"); FILE *fout = fopen ("milk3.out", "w"); fscanf(fin,"%d %d %d",&a,&b,&c); dfs(0,0,c); for(int i=0;i<21;i++) for(int j=0;j<21;j++) { if(v[0][j][i])k[t++]=i; //printf("%d\n",k[t-1]); } int i; for(i=0;i<t-1;++i)fprintf(fout,"%d ",k[i]); if(i)fprintf(fout,"%d\n",k[i]); fclose(fin); fclose(fout); } main () { test(); exit (0); }
测试用例:
USER: ll tom [qq104801] TASK: milk3 LANG: C++ Compiling... Compile: OK Executing... Test 1: TEST OK [0.008 secs, 3532 KB] Test 2: TEST OK [0.005 secs, 3532 KB] Test 3: TEST OK [0.003 secs, 3532 KB] Test 4: TEST OK [0.011 secs, 3532 KB] Test 5: TEST OK [0.008 secs, 3532 KB] Test 6: TEST OK [0.008 secs, 3532 KB] Test 7: TEST OK [0.008 secs, 3532 KB] Test 8: TEST OK [0.011 secs, 3532 KB] Test 9: TEST OK [0.008 secs, 3532 KB] Test 10: TEST OK [0.008 secs, 3532 KB] All tests OK. YOUR PROGRAM (‘milk3‘) WORKED FIRST TIME! That‘s fantastic -- and a rare thing. Please accept these special automated congratulations. Here are the test data inputs: ------- test 1 ---- 2 5 10 ------- test 2 ---- 20 20 20 ------- test 3 ---- 5 11 15 ------- test 4 ---- 2 12 20 ------- test 5 ---- 19 4 11 ------- test 6 ---- 5 11 13 ------- test 7 ---- 3 20 20 ------- test 8 ---- 7 16 20 ------- test 9 ---- 20 10 9 ------- test 10 ---- 7 12 18 Keep up the good work! Thanks for your submission!
usaco-milk3-mother's milk-pass
时间: 2024-12-20 05:49:21