本文主要是介绍Codeforces Round #241 (Div. 2) A,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:A. Guess a number!
题意:给定一些式子,求出满足范围的任意一个y。
思路:水题,模拟题意即可
代码:
#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
using namespace std;
#define INF 0x3f3f3f3f
int q, num, flag = 1, down, up;
string s1, s2;int main() {cin >> q;down = -INF; up =INF;while (q--) {cin >> s1 >> num >> s2;if (s1 == ">=" && s2 == "Y") {if (down < num)down = num;}if (s1 == ">" && s2 == "Y") {if (down <= num)down = num + 1;}if (s1 == "<=" && s2 == "Y") {if (up > num)up = num;}if (s1 == "<" && s2 == "Y") {if (up >= num)up = num - 1;}if (s1 == ">=" && s2 == "N") {if (up >= num)up = num - 1;}if (s1 == ">" && s2 == "N") {if (up > num)up = num;}if (s1 == "<=" && s2 == "N") {if (down <= num)down = num + 1;}if (s1 == "<" && s2 == "N") {if (down < num)down = num;}}if (down > up) printf("Impossible\n");else printf("%d\n", down);return 0;
}
这篇关于Codeforces Round #241 (Div. 2) A的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!