首页 > 代码库 > usaco-1.3-combo-pass

usaco-1.3-combo-pass

水题,极水,列举,但要小心哦,开始判断那用了个循环,居然从249变成了250,查找了好一会才明白,条件复用是有条件的,虽然代码看起来漂亮了,但结果不对,又有何用。

居然从第五层跳回第一层了,不知道为什么,呵呵:

/*ID: qq104801LANG: C++TASK: comboQQ:104804687*/#include <iostream>#include <fstream>#include <cstring>#include <vector>#include <queue>#include <stack>#include <algorithm>#include <cmath>using namespace std;#define loop(i,n) for(int i=0;i<(n);i++)#define loop2(i,n) for(int i=1;i<=(n);i++)const int maxn=205;const int inf=1<<30;struct combo_key{  int x,y,z;}key[2];int n,ans;bool close(int a,int b){  if(abs(a-b)<=2)return true;  if(abs(a-b)>=n-2)return true;  return false;}void test(){     freopen("combo.in","r",stdin);    freopen("combo.out","w",stdout);   cin>>n;    loop(i,2)      cin>>key[i].x>>key[i].y>>key[i].z;  ans=0;  loop2(i,n)    loop2(j,n)      loop2(k,n)                               if((close(i,key[0].x) && close(j,key[0].y) && close(k,key[0].z))           ||(close(i,key[1].x) && close(j,key[1].y) && close(k,key[1].z)))            ans++;   cout<<ans<<endl;  }int main () {            test();            return 0;}

test data:

USACO TrainingGrader Results     15 users onlineCHN/6 TWN/1 USA/8USER: cn tom [qq104801]TASK: comboLANG: C++Compiling...Compile: OKExecuting...   Test 1: TEST OK [0.005 secs, 3376 KB]   Test 2: TEST OK [0.005 secs, 3376 KB]   Test 3: TEST OK [0.008 secs, 3376 KB]   Test 4: TEST OK [0.005 secs, 3376 KB]   Test 5: TEST OK [0.005 secs, 3376 KB]   Test 6: TEST OK [0.008 secs, 3376 KB]   Test 7: TEST OK [0.008 secs, 3376 KB]   Test 8: TEST OK [0.011 secs, 3376 KB]   Test 9: TEST OK [0.008 secs, 3376 KB]   Test 10: TEST OK [0.019 secs, 3376 KB]All tests OK.Your program (‘combo‘) produced all correct answers! This is your submission #2 for this problem. Congratulations!Here are the test data inputs:------- test 1 [length 15 bytes] ----501 2 35 6 7------- test 2 [length 14 bytes] ----11 1 11 1 1------- test 3 [length 14 bytes] ----41 2 32 3 4------- test 4 [length 15 bytes] ----109 9 93 3 3------- test 5 [length 18 bytes] ----5049 50 150 1 2------- test 6 [length 18 bytes] ----955 6 770 80 90------- test 7 [length 22 bytes] ----100100 100 1001 1 1------- test 8 [length 21 bytes] ----1001 50 1002 51 99------- test 9 [length 22 bytes] ----1001 100 991 100 98------- test 10 [length 18 bytes] ----100100 1 24 5 6Keep up the good work!Thanks for your submission!
View Code

 

usaco-1.3-combo-pass