TASK: fence8LANG: C++Compiling...Compile: OKExecuting... Test 1: TEST OK [0.000 secs, 3032 KB] Test 2: TEST OK [0.000 secs, 3032 KB] Test 3: TEST OK [0.000 secs, 3032 KB] Test 4: TEST OK [0.000 secs, 3032 KB] Test 5: TEST OK [0.000 secs, 3032 KB] Test 6: TEST OK [0.027 secs, 3032 KB] Test 7: TEST OK [0.000 secs, 3032 KB] Test 8: TEST OK [0.000 secs, 3032 KB] Test 9: TEST OK [0.000 secs, 3032 KB] Test 10: TEST OK [0.000 secs, 3032 KB] Test 11: TEST OK [0.000 secs, 3032 KB] Test 12: TEST OK [0.000 secs, 3032 KB]All tests OK.
1 /* 2 ID: jiafeim1 3 LANG: C++ 4 TASK: fence8 5 */ 6 #include7 #include 8 using namespace std; 9 int n,r,m; 10 11 int orig[52],target[1055]; 12 int prett[1055]; 13 int total=0; 14 int tempOrig[52]; 15 int mid; 16 int minTarget; 17 int space; 18 bool doit(int targetpos,int origpos) 19 { 20 if(targetpos<=0) return true; 21 if(space + prett[mid]>total) return false; 22 for(int i = origpos ;i<=n;++i) 23 if(target[targetpos]<=tempOrig[i]) 24 { 25 tempOrig[i]-=target[targetpos]; 26 if(tempOrig[i] total) --m; 72 int left=0,right=m; 73 mid = (left+right)/2; 74 75 while(left<=right) 76 { 77 space = 0; 78 for(int i = 1;i<=n;++i) tempOrig[i] = orig[i]; 79 if(doit(mid,1)) 80 { 81 left = mid + 1; 82 mid = (right+left)/2; 83 } 84 else 85 { 86 right = mid - 1; 87 mid = (right +left)/2; 88 } 89 90 } 91 fprintf(fout,"%d\n",mid); 92 fclose(fin); 93 fclose(fout); 94 95 return 0; 96 }