标签:
题目链接:
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 418 Accepted Submission(s): 123
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int k,a[12],vis[12]; int check1() { if(k<4)return 0; memset(vis,0,sizeof(vis)); for(int i=1;i<=k;i++) { if(a[i]>9||a[i]<1||vis[a[i]]==1) { return 0; } else { vis[a[i]]=1; } } return 1; } int check2() { memset(vis,0,sizeof(vis)); for(int i=1;i<k;i++) { if(a[i]==1&&a[i+1]==3&&vis[2]==0)return 0; if(a[i]==3&&a[i+1]==1&&vis[2]==0)return 0; if(a[i]==1&&a[i+1]==7&&vis[4]==0)return 0; if(a[i]==7&&a[i+1]==1&&vis[4]==0)return 0; if(a[i]==1&&a[i+1]==9&&vis[5]==0)return 0; if(a[i]==9&&a[i+1]==1&&vis[5]==0)return 0; if(a[i]==3&&a[i+1]==9&&vis[6]==0)return 0; if(a[i]==9&&a[i+1]==3&&vis[6]==0)return 0; if(a[i]==7&&a[i+1]==3&&vis[5]==0)return 0; if(a[i]==3&&a[i+1]==7&&vis[5]==0)return 0; if(a[i]==7&&a[i+1]==9&&vis[8]==0)return 0; if(a[i]==9&&a[i+1]==7&&vis[8]==0)return 0; if(a[i]==4&&a[i+1]==6&&vis[5]==0)return 0; if(a[i]==6&&a[i+1]==4&&vis[5]==0)return 0; if(a[i]==2&&a[i+1]==8&&vis[5]==0)return 0; if(a[i]==8&&a[i+1]==2&&vis[5]==0)return 0; vis[a[i]]=1; } return 1; } int main() { int t; scanf("%d",&t); while(t--) { scanf("%d",&k); for(int i=1;i<=k;i++) { scanf("%d",&a[i]); } if(check1()==0||check2()==0)cout<<"invalid"<<"\n"; else cout<<"valid"<<"\n"; } return 0; }
标签:
原文地址:http://www.cnblogs.com/zhangchengc919/p/5270835.html