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

ah~~~疯了... 不知道错哪里啊!!!!!!! help

Posted by uncleD at 2008-03-01 11:47:26 on Problem 1029 and last updated at 2008-03-01 11:49:18
#include<iostream.h>

const int sumOfWheights=110;
const int sumOfCoins=1010;
int coinNumber[sumOfCoins];

void creatRecord(int record[sumOfWheights][sumOfCoins],char flag[sumOfWheights],int totalWheights)
{
	int i;
	int j;
	int sumCoins;	

	for(i=0;i<totalWheights;i++)
	{
		cin>>record[i][0];
		sumCoins=record[i][0]*2;
		for(j=1;j<=sumCoins;j++)
			cin>>record[i][j];
		cin>>flag[i];
	}	
}

void judgeHeavy(int record[sumOfWheights][sumOfCoins],char flag[sumOfWheights],int totalWheights,int totalCoins)
{
	int i;
	int j;
	int coins;
	char actualFlag;
	int coinsInPan;
	int canFindTheCoin;

	for(coins=1;coins<=totalCoins;coins++)
	{
		canFindTheCoin=0;
		for(i=0;i<totalWheights;i++)
		{
			coinsInPan=record[i][0]*2;
			actualFlag='=';
			for(j=1;j<=coinsInPan;j++)
			{
				if(record[i][j]==coins)
				{
					if(j<=record[i][0])
						actualFlag='>';
					else 
						actualFlag='<';	
					break;
				}
			}
			if(flag[i]!=actualFlag)
			{
				canFindTheCoin=0;
				break;
			}
			else
				canFindTheCoin=1;
		}
		if(canFindTheCoin)
			coinNumber[coins]=1;
	}
}

void judgeLight(int record[sumOfWheights][sumOfCoins],char flag[sumOfWheights],int totalWheights,int totalCoins)
{
	int i;
	int j;
	int coins;
	char actualFlag;
	int coinsInPan;
	int canFindTheCoin;

	for(coins=1;coins<=totalCoins;coins++)
	{
		canFindTheCoin=0;
		for(i=0;i<totalWheights;i++)
		{
			coinsInPan=record[i][0]*2;
			actualFlag='=';
			for(j=1;j<=coinsInPan;j++)
			{
				if(record[i][j]==coins)
				{
					if(j<=record[i][0])
						actualFlag='<';
					else 
						actualFlag='>';	
					break;
				}
			}
			if(flag[i]!=actualFlag)
			{
				canFindTheCoin=0;
				break;
			}
			else
				canFindTheCoin=1;
		}
		if(canFindTheCoin)
			coinNumber[coins]=1;
	}
}

int printAnswer(int totalCoins,int turn)
{
	int i;
	int ans=0;
	int numOfFalseCoin=0;
	int positionOfFalseCoin=0;

	for(i=1;i<=totalCoins;i++)
	{
		if(coinNumber[i])
		{
			numOfFalseCoin++;
			positionOfFalseCoin=i;
		}
	}
	if(numOfFalseCoin==1)
	{
		cout<<positionOfFalseCoin<<endl;
		return 1;
	}
	else if(turn==2)
	{
		cout<<ans<<endl;
		return 0;
	}
	else 
		return 0;
}

void initialCoinArray()
{
	int i;

	for(i=0;i<sumOfCoins;i++)
		coinNumber[i]=0;
}

int main()
{
	int totalCoins;
	int totalWheights;
	int record[sumOfWheights][sumOfCoins];
	char flag[sumOfWheights];

	cin>>totalCoins>>totalWheights;
	creatRecord(record,flag,totalWheights);
	judgeHeavy(record,flag,totalWheights,totalCoins);
	if(!printAnswer(totalCoins,1))
	{
		initialCoinArray();
		judgeLight(record,flag,totalWheights,totalCoins);
		printAnswer(totalCoins,2);
	}
	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