Counterfeit Dollar 模拟-枚举

版权声明:原创文章转载时请注明出处 https://blog.csdn.net/weixin_42856843/article/details/88891974

Counterfeit Dollar 模拟-枚举

Time limit:1000 ms Memory limit:10000 kB Source: East Central North America 1998 http://poj.org/searchproblem?field=source&key=East+Central+North+America+1998

描述

Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are true silver dollars; one coin is counterfeit even though its color and size make it indistinguishable from the real silver dollars. The counterfeit coin has a different weight from the other coins but Sally does not know if it is heavier or lighter than the real coins.
Happily, Sally has a friend who loans her a very accurate balance scale. The friend will permit Sally three weighings to find the counterfeit coin. For instance, if Sally weighs two coins against each other and the scales balance then she knows these two coins are true. Now if Sally weighs
one of the true coins against a third coin and the scales do not balance then Sally knows the third coin is counterfeit and she can tell whether it is light or heavy depending on whether the balance on which it is placed goes up or down, respectively.
By choosing her weighings carefully, Sally is able to ensure that she will find the counterfeit coin with exactly three weighings.

输入

The first line of input is an integer n (n > 0) specifying the number of cases to follow. Each case consists of three lines of input, one for each weighing. Sally has identified each of the coins with the letters A–L. Information on a weighing will be given by two strings of letters and then one of the words "up’’, "down’’, or "even’’. The first string of letters will represent the coins on the left balance; the second string, the coins on the right balance. (Sally will always place the same number of coins on the right balance as on the left balance.) The word in the third position will tell whether the right side of the balance goes up, down, or remains even.

输出

For each case, the output will identify the counterfeit coin by its letter and tell whether it is heavy or light. The solution will always be uniquely determined.

题目大意

描述

莎莉琼斯有十几个Voyageur银元。然而,只有十一个硬币是真正的银元; 一枚硬币是伪造的,即使它的颜色和大小使它与真正的银元无法区分。假币与其他硬币的重量不同,但Sally不知道它是否比真币更重或更轻。
令人高兴的是,莎莉有一位朋友向她提供了非常准确的余额。这位朋友将允许Sally三次称重来找到伪造的硬币。例如,如果莎莉相互称重两个硬币并且秤平衡,那么她知道这两个硬币是真的。现在,如果莎莉称重
对于第三枚硬币的真正硬币之一并且秤没有平衡然后Sally知道第三枚硬币是伪造的,并且她可以分辨它是轻还是重,这取决于它所放置的平衡是分别上升还是下降。
通过仔细选择她的称重,莎莉能够确保她将找到三个称重的假币。
输入

第一行输入是整数n(n> 0),指定要遵循的案例数。每个案例由三行输入组成,每个称重一个。莎莉用字母A - L识别出每个硬币。关于称重的信息将由两串字母给出,然后是“向上”,“向下”或“偶数”之一。第一串字母代表左边的硬币; 第二个字符串,右边的硬币平衡。(Sally将始终将相同数量的硬币放在正确的余额上,与左边的余额相同。)第三个位置的单词将指示天平的右侧是上升,下降还是保持均匀。
输出

对于每种情况,输出将通过其字母识别伪造硬币并判断它是重还是轻。解决方案始终是唯一确定的。

Input

1
ABCD EFGH even
ABCI EFJK up
ABIJ EFGH even

Output

K is the counterfeit coin and it is light.

代码

#include <iostream>
#include <algorithm>
#define _for(i, a) for(int i = 0; i < (a); i++)
#define _rep(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std;
struct poi {
	char left[20], right[20], ress[20];
};
poi d[3];
bool che(char a, int sym) {
	_for(i, 3) {
		int ans[2] = { 0 };
		for (int j = 0; d[i].left[j]; j++) {
			if (d[i].left[j] == a) ans[0] += sym;
		}
		for (int j = 0; d[i].right[j]; j++) {
			if (d[i].right[j] == a) ans[1] += sym;
		}
		if (ans[0] == ans[1] && d[i].ress[0] != 'e') return false;
		if (ans[0] > ans[1] && d[i].ress[0] != 'u') return false;
		if (ans[0] < ans[1] && d[i].ress[0] != 'd') return false;
	}
	return true;
}
int main() {
	//freopen("input.txt", "r", stdin);
	int T = 0;
	cin >> T;
	while (T--) {
		_for(i, 3) cin >> d[i].left >> d[i].right >> d[i].ress;
		for (char i = 'A'; i <= 'Z'; i++)
			for (int j = -1; j < 2; j += 2)
				if (che(i, j))
					printf("%c is the counterfeit coin and it is %s. \n", i, j == -1 ? "light" : "heavy");
	}
	return 0;
}


本人也是新手,也是在学习中,勿喷

转载请注明出处

扫描二维码关注公众号,回复: 5795138 查看本文章

欢迎有问题的小伙伴一起交流哦~

猜你喜欢

转载自blog.csdn.net/weixin_42856843/article/details/88891974