Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

why WA?

Posted by BJ05301155 at 2007-04-21 10:55:47 on Problem 1601
#include <iostream.h>
#include <string.h>

int res[16];
int a[12][16];
int p;

int check(int id)
{
	int i=0,j,sign;
	while(id)
	{
		res[i++]=id%2;//求出该种策略中各种食物是否添加
		id=id/2;
	}
	while(i<16)
		res[i++]=0;
	for(i=0;i<p;i++)//测试该种策略能否满足各客人的至少一项要求
	{
		sign=0;
		for(j=0;j<16&&sign==0;j++)
			if(res[j]==a[i][j]||a[i][j]==2)
				sign=1;//该种策略满足了第i个客人一种要求
		if(!sign)
			return 0;
	}
	return 1;

}

int main(int argc, char* argv[])
{
	char r[100],c;
	int i,id;
	while(cin>>r)
	{
		p=0;//客人数
		for(i=0;i<16;i++)
			a[p][i]=-1;//表示该客人尚未对该食物未提出要求
		for(i=1;i<strlen(r);i+=2)
			if(a[p][r[i]-65]==-1)//该客人尚未对该食物未提出要求
				a[p][r[i]-65]=(r[i-1]=='+'?1:0);
			else//该客人对该食物已提出要求
			{	
				if(a[p][r[i]-65]==1&&r[i-1]=='+')
					a[p][r[i]-65]=1;
				else
				{
					if(a[p][r[i]-65]==0&&r[i-1]=='-')
						a[p][r[i]-65]=0;
					else
						a[p][r[i]-65]=2;//该种食物添加不添加均可以满足客人的一种要求
				}
			}
		p=1;
		while(cin>>r)
		{
			if(r[0]=='.')
				break;
			for(i=0;i<16;i++)
				a[p][i]=-1;
			for(i=1;i<strlen(r);i+=2)
				if(a[p][r[i]-65]==-1)//该客人尚未对该食物未提出要求
				a[p][r[i]-65]=(r[i-1]=='+'?1:0);
			else//该客人对该食物已提出要求
			{
				if(a[p][r[i]-65]==1&&r[i-1]=='+')
					a[p][r[i]-65]=1;
				else
				{
					if(a[p][r[i]-65]==0&&r[i-1]=='-')
						a[p][r[i]-65]=0;
					else
						a[p][r[i]-65]=2;//该种食物添加不添加均可以满足客人的一种要求
				}
			}
			p++;
		}
		id=0;
		while(id<=65535)
		{
			if(check(id))//检测第id种方法是否可行,将id转化为二进制,得到的各位为每种食物是否添加,0不添加,1添加
				//例如id=3转化为0000000000000011表示只添加A,B
				break;
			id++;
		}
		if(id>65535)
			cout<<"No pizza can satisfy these requests."<<endl;
		else
		{
			if(!id)
				cout<<"Toppings: ";
			else
			{
				cout<<"Toppings: ";
				for(i=0;i<16;i++)
				if(res[i])
				{
					
					c=i+65;
					cout<<c;
				}
			}
			cout<<endl;
		}
			
	}
	return 0;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator