标签:des style class blog code java
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1172
6 4815 2 1 5716 1 0 7842 1 0 4901 0 0 8585 3 3 8555 3 2 2 4815 0 0 2999 3 3 0
3585 Not sure
从1000到9999进行暴力枚举。。。
需要满足两个条件:
1:题目所给的条件和目前枚举的值要有相同的位数的值要相等。。
2:将目前枚举的数和题目所给的数进行枚举,看所给的条件的数与目前枚举的的数的出现相同的数相等的数有多少个。。但是重复的书不算。。所以开个标志变量。。。
所以我的暴力枚举解法如下:
#include<cstdio>
#include<cstring>
const int maxn=100+10;
struct node
{
int a,b,c;
}point[maxn];
int a[5],b[5];
int mark[5];
void pre_deal(int c,int d)
{
a[1]=c/1000;
a[2]=c/100%10;
a[3]=c/10%10;
a[4]=c%10;
b[1]=d/1000;
b[2]=d/100%10;
b[3]=d/10%10;
b[4]=d%10;
}
int judge(int x,int y)
{
int count1,count2;
count1=count2=0;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(mark,0,sizeof(mark));
pre_deal(x,point[y].a);
for(int i=1;i<=4;i++)
{
if(a[i]==b[i])
count1++;
}
// printf("count1:%d\n",count1);
if(count1!=point[y].c)
return 0;
for(int i=1;i<=4;i++)
for(int j=1;j<=4;j++)
{
if(a[i]==b[j]&&!mark[j])
{
mark[j]=1;
count2++;
break;
}
}
//printf("count2:%d\n",count2);
if(count2!=point[y].b)
return 0;
else
return 1;
}
int main()
{
int n,ok;
int count,ans;
while(scanf("%d",&n)!=EOF&&n)
{
count=0;
for(int i=1;i<=n;i++)
scanf("%d%d%d",&point[i].a,&point[i].b,&point[i].c);
for(int i=1000;i<=9999;i++)
{
ok=1;
for(int j=1;j<=n;j++)
{
ok=judge(i,j);
if(!ok)
break;
}
if(ok)
{
count++;
ans=i;
}
if(count==2)
break;
}
// printf("count:%d\n",count);
if(count==1)
printf("%d\n",ans);
else
printf("Not sure\n");
}
return 0;
}
标签:des style class blog code java
原文地址:http://blog.csdn.net/u014303647/article/details/31879585