UVa 10530 - Guessing Game

题目:两个人玩猜数字游戏(1~10),A选择一个数字,B不断报数,A对应说:高、低、对;

现在B怀疑A作弊,在这个过程中改变数字,他想判断A是否作弊。

分析:简单题。可以把所有的序列存起来,然后比较判断是否存在矛盾即可。

这里利用一个数组做10个数字的标记;

如果A说小,就把所有小于等于当前数字n的数字标记成小(-1);

如果A说大,就把所有小于等于当前数字n的数字标记成大(1);

标记过程中判断是否有矛盾即可(已有标记的值和新标记是否相同);

最后判断,所猜数字是否被标记即可。

说明:(⊙v⊙)。

#include <cstdlib>
#include <cstring>
#include <cstdio>

int  used[11];
char buf1[9],buf2[9];

int main()
{
	int n;
	while (scanf("%d",&n) && n) {
		memset(used, 0, sizeof(used));
		scanf("%s%s",buf1,buf2);
		int flag = 0;
		while (buf1[0] != 'r') {
			if (!flag) {
				if (buf2[0] == 'h') {
					for (int i = n ; i <= 10 ; ++ i)
						if (used[i] == -1) flag = 1;
						else used[i] = 1;
				}else {
					for (int i = n ; i >= 1 ; -- i)
						if (used[i] == 1) flag = 1;
						else used[i] = -1;
				}
			}
			scanf("%d%s%s",&n,buf1,buf2);
		}
		if (used[n]) flag = 1;
		if (!flag)
			printf("Stan may be honest\n");
		else printf("Stan is dishonest\n");
	}
    return 0;
}
时间: 2024-08-22 01:16:10

UVa 10530 - Guessing Game的相关文章

uva 1521 - GCD Guessing Game(贪心)

题目链接:uva 1521 - GCD Guessing Game 题目大意:给定一个数N,现在又一个数x,在1~N之间,现在每次可以猜一个数a,返回gcd(x,a),问说最少猜几次可以确定x. 解题思路:其实就将1~N里面的素数都要考虑一遍,因为有一个N的限制,所以每次选出来的素数的积不大于N即可. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const

UVA 1521 - GCD Guessing Game(数论+贪心)

UVA 1521 - GCD Guessing Game 题目链接 题意:一个数字x在1-n之间,现在猜数字,每次猜一个数字a,告知gcd(x, a)的答案,问最坏情况下需要猜几次 思路:在素数上考虑,猜一组素数的乘积的数字,就可以把这些素数组成的数字都猜出来,答案就是组数,这样问题就是如何分组使得组数最小,每次取最后一个,尽量和前面小的合并,就能使得组数最小 代码: #include <cstdio> #include <cstring> #include <algorit

UVA 322 ships (POJ 1138)

题目地址: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=258 http://poj.org/problem?id=1138 题目描写叙述:  Ships  Probably everyone who ever attended school knows the game where two opposing players place

UVA 489-- Hangman Judge--暴力串处理

 Hangman Judge  In ``Hangman Judge,'' you are to write a program that judges a series of Hangman games. For each game, the answer to the puzzle is given as well as the guesses. Rules are the same as the classic game of hangman, and are given as follo

UVa 489 Hangman Judge(字符串)

 Hangman Judge  In ``Hangman Judge,'' you are to write a program that judges a series of Hangman games. For each game, the answer to the puzzle is given as well as the guesses. Rules are the same as the classic game of hangman, and are given as follo

uva 489

In ``Hangman Judge,'' you are to write a program that judges a series of Hangman games. For each game, the answer to the puzzle is given as well as the guesses. Rules are the same as the classic game of hangman, and are given as follows: The contesta

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f