• HDU 1172 猜数字


    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1172

    把1000~9999间的数字遍历一遍,如果只有一个符合条件的话,就输出,否则 not sure

    #include <iostream>
    using namespace std;
    char data[105][5];
    int a[105],b[105];
    int main()
    {
    	bool judge(int m,int n);
    	int n;
    	int ans;
    	int count;
    	int i,j;
    	bool sign;
    	while(cin>>n&&n)
    	{
    		count=0;
    		sign=false;
    		for(i=0;i<n;i++)
    		{
    			cin>>data[i]>>a[i]>>b[i];
    		}
    		for(i=1000;i<=9999;i++)
    		{
    			for(j=0;j<n;j++)
    			{
    				sign=judge(i,j);			//判断i是否符合第j个条件
    				if(!sign)
    					break;
    							
    			}
    			if(sign)
    			{
    				count++;
    				ans=i;
    			}
    		}
    		if(count==1)
    			cout<<ans<<endl;
    		else
    			cout<<"Not sure"<<endl;
    
    
    	}
    	return 0;
    }
    
    bool judge(int m,int n)		//判断m是否符合条件n
    {
    	int i,j,k;
    	bool mark[4];
    	char tem[5];
    	sprintf(tem,"%d",m);
    	int count=0;
    	for(i=0;i<4;i++)
    		mark[i]=false;
    	for(i=0;i<4;i++)
    		if(tem[i]==data[n][i])
    			count++;
    	if(count!=b[n])
    		return false;
    	count=0;
    	for (i=0;i<4;i++)
    		for(j=0;j<4;j++)
    		{
    			if(tem[i]==data[n][j]&&!mark[j])
    			{
    				mark[j]=true;
    				count++;
    				break;
    			}
    		}
    
    	if(count!=a[n])
    		return false;
    	
    	
    	return true;
    }


     

  • 相关阅读:
    matlab cell
    matlab linux 快捷键设置——有问题还是要解决
    latex 小结
    TOJ 1258 Very Simple Counting
    TOJ 2888 Pearls
    HDU 1248 寒冰王座
    TOJ 3486 Divisibility
    TOJ 3635 过山车
    TOJ 1840 Jack Straws
    HDU 4460 Friend Chains
  • 原文地址:https://www.cnblogs.com/frankM/p/4399527.html
Copyright © 2020-2023  润新知