A. Guess a number!
time limit per test1 second
memory limit per test256 megabytes

A TV show called “Guess a number!” is gathering popularity. The whole Berland, the old and the young, are watching the show.

The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:

Is it true that y is strictly larger than number x?
Is it true that y is strictly smaller than number x?
Is it true that y is larger than or equal to number x?
Is it true that y is smaller than or equal to number x?
On each question the host answers truthfully, “yes” or “no”.

Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn’t such value, print “Impossible”.

Input
The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: “sign x answer”, where the sign is:

“>” (for the first type queries),
“<” (for the second type queries),
“>=” (for the third type queries),
“<=” (for the fourth type queries).
All values of x are integer and meet the inequation  - 10^9 ^≤ x ≤ 109. The answer is an English letter “Y” (for “yes”) or “N” (for “no”).

Consequtive elements in lines are separated by a single space.

Output
Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation  - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn’t exist, print word “Impossible” (without the quotes).

Examples
input
4
>= 1 Y
< 3 N
<= -3 N
> 55 N
output
17
input
2
> 100 Y
< -100 Y
output
Impossible

问题链接:CodeForces - 416A Guess a number!
问题简述:(略)
问题分析:(略)

AC的C语言程序如下:

/* CodeForces - 416A Guess a number! */#include <stdio.h>#define Y 2000000000int main()
{int n, x, miny = -Y, maxy = Y;char sign[3], ans[2];scanf("%d", &n);while (n--) {scanf("%s%d%s", sign, &x, ans);if (ans[0] == 'Y') {if (sign[0] =='>' && sign[1] == '=') {if (miny < x) miny = x;} else if (sign[0] == '>') {if (miny <= x) miny = x + 1;} else if (sign[0] == '<' && sign[1] == '=') {if (maxy > x) maxy = x;} else if (sign[0] == '<') {if (maxy >= x) maxy = x - 1;}} else if (ans[0] == 'N') {if (sign[0] =='<' && sign[1] == '=') {if (miny <= x) miny = x + 1;} else if (sign[0] == '<') {if (miny < x) miny = x;} else if (sign[0] == '>' && sign[1] == '=') {if (maxy >= x) maxy = x - 1;} else if (sign[0] == '>') {if (maxy > x) maxy = x;}}}if (miny <= maxy) printf("%d\n", miny);else printf("Impossible\n");return 0;
}

AC的C++语言程序如下:

/* CodeForces - 416A Guess a number! */#include <bits/stdc++.h>using namespace std;const int Y = 2000000000;
int main()
{ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);int n, x, miny = -Y, maxy = Y;string sign;char ans;cin >> n;while (n--) {cin >> sign >> x >> ans;if (ans == 'N') {if (sign == ">") sign = "<=";else if (sign == "<") sign = ">=";else if (sign == ">=") sign ="<";else if (sign == "<=") sign = ">";}if (sign == ">" && miny <= x) miny = x + 1;else if (sign == "<" && maxy >= x) maxy = x - 1;else if (sign == ">=" && miny < x) miny = x;else if (sign == "<=" && maxy > x) maxy = x;}if (miny <= maxy)cout << miny << endl;elsecout << "Impossible" << endl;return 0;
}

CodeForces - 416A Guess a number相关推荐

  1. Codeforces 724 G Xor-matic Number of the Graph 线性基+DFS

    G. Xor-matic Number of the Graph http://codeforces.com/problemset/problem/724/G 题意:给你一张无向图.定义一个无序三元组 ...

  2. CodeForces - 1560F2 Nearest Beautiful Number (hard version)(二分+数位dp)

    题目链接:点击查看 题目大意:给出一个十进制数字 nnn 和一个约束 kkk,问大于等于 nnn 且满足不同的数位个数小于等于 kkk 的最小的数字是多少 题目分析:自己写的贪心太丑了,就不放上来丢人 ...

  3. CodeForces 389A Fox and Number Game

    链接:http://codeforces.com/problemset/problem/389/A Fox and Number Game time limit per test:1 second m ...

  4. Codeforces 1070A Find a Number(BFS) 2018-2019 ICPC, NEERC, Southern Subregional Contest Problem A

    Description You are given two positive integers ddd and sss. Find minimal positive integer nnn which ...

  5. 【Codeforces 1426 F】Number of Subsequences,字符串计数DP

    problem F. Number of Subsequences time limit per test1 second memory limit per test256 megabytes inp ...

  6. 【Codeforces】835B The number on the board (贪心)

    把所有字符串上的数字加起来,看是否超过k,没有超过k的话,把字符串sort,从第一位开始,将字符变成9,直到sum大于等于k为止. #include <iostream> #include ...

  7. CodeForces 518A - Chewbaсca and Number(思路)

    题意:给你两个长度相同的字符串,输出一个长度与它俩相同,且字典序位于两者之间(不可与其中一者相同)的字符串,若不存在则输出"No such string".(输入保证字典序第一个严 ...

  8. CodeForces 392C Yet Another Number Sequence 矩阵快速幂

    题意: \(F_n\)为斐波那契数列,\(F_1=1,F_2=2\). 给定一个\(k\),定义数列\(A_i=F_i \cdot i^k\). 求\(A_1+A_2+ \cdots + A_n\). ...

  9. CodeForces - 946E Largest Beautiful Number(贪心+模拟)

    题目链接:点击查看 题目大意:给出一个数位长度为偶数的数字 n,需要求出一个比 n 小的,且所有数位重新排列后可以形成回文串,要求这个数字尽可能大 题目分析:从最低位开始贪心,依次枚举每一位的数字,然 ...

最新文章

  1. getprivateprofilestring读不到数据_电商系列(三)如何构建数据库的主从架构!
  2. 数仓 调度_网易实时数仓实践
  3. ubuntu swift mysql_使用 Swift 3.0 操作 MySQL 数据库
  4. 如何在SAP云平台上创建Redis实例
  5. iview form 表单 自定义参数验证 validate
  6. linux脚本多个条件比较大小,shell脚本-比较两个整数大小
  7. Ubuntu 16.04中vim编辑报错E138: Can‘t write viminfo file /root/.viminfo!
  8. mule esb_Mule ESB –入门
  9. java web登录代码_Java Web 登录页面的实现代码实例
  10. linux 软件装哪个目录下,Linux查看软件安装目录及位置 方法
  11. SANGFOR SCSA——网络基础(下)
  12. PDF文件如何自动生成目录书签
  13. 基于单片机的红绿黄灯设计(单片机实验交通灯设计)
  14. 利用循环打印正方形和长方形
  15. java pdf 模板_java通过PDF模板填写PDF表单
  16. HTML入门与进阶以及HTML5
  17. HDS F900装机小结
  18. ArcGIS Pro功能模块简介
  19. laravel view
  20. esp8266 mesh 组网

热门文章

  1. FPGA开源IP核下载opencores.org
  2. Python脚本访问子目录
  3. 好用的前端组件收集(ing)
  4. Stage3D 入门资源汇总
  5. matlab中求方差的,matlab中求方差为什么除以n-1?
  6. python分数由高至低排序_python之数据库
  7. Doris之分区缓存(全面)
  8. 下面是java语言的关键字是_下面4个选项中,哪个是Java语言的关键字:
  9. 计算机网络-自顶向下方法(7th) 第二章 Review Questions 英文题目+中文答案
  10. python入门指南by许半仙长佩_有哪些好看的耽美文啊?