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

不爽啊,暴力法过了,参照各位的思路又写了一个,但老是WA,麻烦大家帮忙看下还有什么问题,改如何修改。

Posted by yzx at 2007-05-06 16:25:00 on Problem 1013
/*
不爽啊,暴力法过了,参照各位的思路又写了一个,但老是WA,麻烦大家帮忙看下还有什么问题,改如何修改。
其中下面的三组数据都可以通过,还没有BT一点的,好让我看看到底是哪里想错了
3
ABCD EFGH even
ABCI EFJK up
ABIJ EFGH even
ABCD EFGH even
ABCI EFJK down
ABIJ EFGH even
ABCD EFGK up
EFDL ABGK up
GHIJ EFDK up
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

char left[3][7];
char right[3][7];
char result[3][5];
char light[12],heavy[12];
char good[12];

void check()
{
	int i,j;
	int index;
	for(i = 0;i < 3;i++)
	{
		if(strcmp(result[i], "even") == 0)
		{
			for(j = strlen(left[i]) - 1;j >= 0;j--)
			{
				good[left[i][j] - 'A'] = 1;
			}
			for(j = strlen(right[i]) - 1;j >= 0;j--)
			{
				good[right[i][j] - 'A'] = 1;
			}
		} else if(strcmp(result[i], "up") == 0){
			for(j = strlen(left[i]) - 1;j >= 0;j--)
			{
				if(good[left[i][j] - 'A'] == 0)
				{
					heavy[left[i][j] - 'A']++;
				}
			}
			for(j = strlen(right[i]) - 1;j >= 0;j--)
			{
				if(good[right[i][j] - 'A'] == 0)
				{
					light[right[i][j] - 'A']++;
				}
			}
		} else if(strcmp(result[i], "down") == 0){
			for(j = strlen(left[i]) - 1;j >= 0;j--)
			{
				if(good[left[i][j] - 'A'] == 0)
				{
					light[left[i][j] - 'A']++;
				}
			}
			for(j = strlen(right[i]) - 1;j >= 0;j--)
			{
				if(good[right[i][j] - 'A'] == 0)
				{
					heavy[right[i][j] - 'A']++;
				}
			}
		}
	}
	index = 0;
	for(i = 0;i < 12;i++)
	{
		if(good[i] == 0)
		{
			if(fabs(light[i] - heavy[i]) > fabs(light[index] - heavy[index]))
			{
				index = i;
			}			
		}
	}
	if(light[index] > heavy[index])
	{
		printf("%c is the counterfeit coin and it is light.\n", index + 'A');
	} else if(light[index] < heavy[index]) {
		printf("%c is the counterfeit coin and it is heavy.\n", index + 'A');
	}
}

int main()
{
	int n,j;
	
	//freopen("1013.in","r",stdin);
	scanf("%d", &n);
	for(;n > 0;n--)
	{
		memset(light, 0, sizeof(char) * 12);
		memset(heavy, 0, sizeof(char) * 12);
		memset(good, 0, sizeof(char) * 12);
		for(j = 0;j < 3;j++)
		{
			scanf("%s %s %s", left[j], right[j], result[j]);
		}
		check();
	}
	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