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

Re:一个通过的思路

Posted by zhangyingshuo at 2008-05-06 16:20:15 on Problem 1013
In Reply To:一个通过的思路 Posted by:wrong123 at 2005-12-05 17:31:39
我是按照你说的思想写的,所有数据都正确,可就是wa,麻烦你给我看一下,谢谢。
#include <iostream>
#include <string>
using namespace std;
const int num=12;
struct Coin
{
	int real;
	int hOrl;
	Coin():real(0),hOrl(0){}
};
int maxAbs(Coin *coins)
{
	int maxA=abs(coins[0].hOrl);
	int maxCoin=0;
	for(int i=1;i<num;i++)
		if(abs(coins[i].hOrl)>maxA)
		{
			maxA=abs(coins[i].hOrl);
			maxCoin=i;
		}
	return maxCoin;
}
void Mark(string **str)
{
	Coin coins[num];
	int i,j;
	for(i=0;i<3;i++)
	{
		if(str[i][2]=="even")
			for(j=0;j<str[i][0].length();j++)
			{
				coins[str[i][0][j]-'A'].real=1;
				coins[str[i][1][j]-'A'].real=1;
			}
		if(str[i][2]=="up")
			for(j=0;j<str[i][0].length();j++)
			{
				coins[str[i][0][j]-'A'].hOrl--;
				coins[str[i][1][j]-'A'].hOrl++;
			}
		if(str[i][2]=="down")
			for(j=0;j<str[i][0].length();j++)
			{
				coins[str[i][0][j]-'A'].hOrl++;
				coins[str[i][0][j]-'A'].hOrl--;
			}
	}
	for(i=0;i<num;i++)
	{
		if(coins[i].real)
			coins[i].hOrl=0;
	}
	int counterfeit=maxAbs(coins);
	cout<<static_cast<char>('A'+counterfeit)<<" is the counterfeit coin and it is ";
	if(coins[counterfeit].hOrl>0) cout<<"light."<<endl;
	else cout<<"heavy."<<endl;
}

int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		string **str=new string*[3];
		for(int j=0;j<3;j++)
		{
			str[j]=new string[3];
			for(int k=0;k<3;k++)
				cin>>str[j][k];
		}
		Mark(str);
	}
	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