usaco-1.3-combo-pass

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

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

/*
ID: qq104801
LANG: C++
TASK: combo
QQ: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 Training
Grader Results     
15 users online
CHN/6 TWN/1 USA/8

USER: cn tom [qq104801]
TASK: combo
LANG: C++

Compiling...
Compile: OK

Executing...
   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] ----
50
1 2 3
5 6 7
------- test 2 [length 14 bytes] ----
1
1 1 1
1 1 1
------- test 3 [length 14 bytes] ----
4
1 2 3
2 3 4
------- test 4 [length 15 bytes] ----
10
9 9 9
3 3 3
------- test 5 [length 18 bytes] ----
50
49 50 1
50 1 2
------- test 6 [length 18 bytes] ----
95
5 6 7
70 80 90
------- test 7 [length 22 bytes] ----
100
100 100 100
1 1 1
------- test 8 [length 21 bytes] ----
100
1 50 100
2 51 99
------- test 9 [length 22 bytes] ----
100
1 100 99
1 100 98
------- test 10 [length 18 bytes] ----
100
100 1 2
4 5 6

Keep up the good work!
Thanks for your submission!
View Code
/***********************************************

看书看原版,原汁原味。

不会英文?没关系,硬着头皮看下去慢慢熟练,才会有真正收获。

没有原书,也要网上找PDF来看。

网上的原版资料多了去了,下载东西也到原始下载点去看看。

你会知其所以然,呵呵。

***********************************************/

原文地址:https://www.cnblogs.com/dpblue/p/4004840.html