the reason of failure:1、《数据》因为环形,用%判断当这个环后面几个数+某个数大于N时对应的一个循环后是哪个数,但是当环为1时,任何数%1都为0.
2、《数据》当环为50 %50的时候,得到的值为0,而一个环的开始是从1开始的.
坑在的数据为:
1
1 1 1
1 1 1
---------
50
49 50 1
50 1 2
题意:有一个3个数字的环形的锁头,从1开始到N, 给出2种解锁钥匙,如1 2 3 ,5 6 7 , 但是这把锁可以模糊打开,也就是每位钥匙的数与锁的数相差值不超过2.
注意2把锁为互相独立的,也就是1 2 9是打不开的.
thinking:枚举所以可能,然后把所有数+l(-2<=l<=2),看其是否可以符合其中一把钥匙,如果符合则能打开锁的钥匙种数+1,
代码:
/*
PROG: combo
LANG: C++
ID: me
*/
#include <bits/stdc++.h>
using namespace std;
int main(){
freopen("combo.in","r",stdin);
freopen("combo.out","w",stdout);
int n,m,o,sum=0;
cin >> n ;
int i,j,k,l,i1,j1,k1,i2;
int a1,a2,a3,b1,b2,b3;
cin >> a1 >> a2 >> a3;
cin >> b1 >> b2 >> b3;
int f1,f2,f3;
int t1,t2,t3;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
for(k=1;k<=n;k++){
t1=0,t2=0,t3=0;
f1=0,f2=0,f3=0;
for(l=-2;l<=2;l++){ //任何数余1都为0
if((i+l+n)%n==a1%n)t1=1;
if((j+l+n)%n==a2%n)t2=1;
if((k+l+n)%n==a3%n)t3=1;
if((i+l+n)%n==b1%n)f1=1;
if((j+l+n)%n==b2%n)f2=1;
if((k+l+n)%n==b3%n)f3=1;}
if((t1&&t2&&t3)||(f1&&f2&&f3)){
// cout << i <<" "<< j <<" "<< k << endl;
sum++;
}
}
if(n!=1)
cout << sum << endl;
else
cout << 1 << endl;
return 0;
}