Non-Interactive Guessing Number

题目描述:
Romanos: “Can I submit an interactive problem to ACM-ICPC 2017 Jakarta?”
Theodora: “No.”
Romanos: “Aww, man… That’s not fun.”
Then Romanos decided to submit a non-interactive version of his problem to the contest; and here it is, based on his playing with Theodora.
Romanos and Theodora are playing a game. Initially, Theodora picks a number between 1 to N inclusive. Romanos’ goal is to determine that number. He can make up to ! guesses. For each guess, he will say a number out loud as his guess. Theodora will then say one of the following answers based on the exact condition:
• "My number is smaller than your guess (<)”,
• “My number is greater than your guess (>)”, or
• “Your guess is correct (=)”.
The game will end right after one of the following:
• Romanos guesses the correct number (he wins), or
• All ! guesses are wrong (he loses).
Sadly, Romanos is not playing the game seriously. He knows the best strategy to win this game, but he does not always use it. Nevertheless, he pretends that he plays seriously, hence his guess will never be a dumb one. In other words, his guess will always be a number between 1 to N inclusive and will always be consistent with all of Theodora’s previous answers.
For example, suppose N is 10 and Romanos’ first guess is 4. If Theodora answers “My number is smaller than your guess (<)” then the next Romanos’s guess will always be between 1 to 3, inclusive.
Contrast to Romanos, Theodora is playing the game too seriously. She wants to win (by making Romanos lose) and “cheats” as follows.
Adaptively, Theodora might change her number as far as it is consistent with all of her previous answers. To do that, whenever possible, Theodora will always answer either “My number is smaller than your guess (<)” or “My number is greater than your guess (>)” that maximizes the possible answer range. In the case of tie, she will always answer the first one (<).
For example, suppose N is 10 and Romanos’ first guess is 4. Theodora will always answer “My number is greater than your guess (>)” because the possible answer range will be between 5 to 10 inclusive; it is larger than 1 to 3 inclusive.
Now, this is the actual problem proposed by Romanos. You are given N,K , and Theodora’s answer for each guess. Can you show one of the possible scenario for Romanos’ guesses or state that it is impossible?
输入:
The first line contains two integers: N K(1 ≤N≤ 1018; 1 ≤K≤ 50,000) in a line denoting the number range and the number of guesses. The second line contains a string in a line denoting Theodora’s answers. Each character of the string is either ‘<’, ‘>’, or ‘=’, and either:
• The last character of the string is ‘=’ and each character of the string other than the last character is either ‘<’ or ‘>’, and the length of the string is not more than K , or
• The length of the string is exactly K and each character of the string is either ‘<’ or ‘>’.
输出:
If there is a possible scenario for Romanos’ guesses,output YES,else output NO.
样例输入:

样例输出:
YES
题目大意:
(太长了不好总结,直接贴的有道,如下)
Romanos:“我可以向ACM-ICPC 2017 Jakarta提交一个交互式问题吗?”
狄奥多拉:“没有。”
romano:“哇哇哇,男人. .这不是有趣。”
然后罗马诺斯决定提交他的问题的非交互式版本的比赛;这是根据他和狄奥多拉的玩耍。罗马诺斯和狄奥多拉在玩游戏。最初,狄奥多拉选择了一个1到N之间的数。罗马诺斯的目标是确定这个数字。他可以弥补!的猜测。每猜一次,他就会说出一个数字作为他的猜测。狄奥多拉会根据具体情况给出以下答案之一
•“我的号码比你猜的要小(<)”,
•“我的号码比你猜的要大(>)”,或
•“你的猜测是正确的(=)”。
游戏将在以下内容之一结束:
•罗马诺斯猜对了号码(他赢了),或者
•所有!猜错了(他输了)。
遗憾的是,罗马诺斯并没有认真对待这场比赛。他知道赢得这场比赛的最佳策略,但他并不总是使用它。然而,他假装自己玩得很认真,因此他的猜测永远不会是愚蠢的。换句话说,他的猜测将始终是1到N之间的一个数字包括1到N也将始终与狄奥多拉之前所有的答案一致。
例如,假设N是10,Romanos的第一个猜测是4。如果狄奥多拉的回答是“我的数字比你的猜测小(<)”,那么下一个罗马诺斯的猜测将永远在1到3之间,包括在内。
与罗马诺斯不同,狄奥多拉玩这个游戏太认真了。她想要赢(通过让罗曼诺斯输掉比赛),“作弊”如下。
适应性地,狄奥多拉可能会改变她的号码只要和她之前的答案一致。为了做到这一点,狄奥多拉总是尽可能地回答“我的数字比你的猜测要小(<)”或者“我的数字比你的猜测要大(>)”,这样可以最大限度地扩大可能的答案范围。在打领带的情况下,她总是第一个回答(<)。
例如,假设N是10,Romanos的第一个猜测是4。狄奥多拉总是回答"我的数字比你的猜测大"因为可能的答案范围在5到10之间;它大于1到3。
这就是罗马诺斯提出的实际问题。每个猜测都有N K狄奥多拉的答案。你能给出罗马诺斯猜测的一个可能的场景吗?
输入:
第一行包含两个整数:N K(1≤N≤1018;(1≤K≤50,000)),表示数字范围和猜测次数。第二行包含一行字符串,表示狄奥多拉的答案。字符串的每个字符要么是’<’,’>’,要么是’=’,要么是:
•字符串的最后一个字符是’=’,除最后一个字符外,字符串的每个字符都是’<‘或’>’,字符串的长度不超过K,或
•字符串的长度正好是K,字符串的每个字符都是’<‘或’>’。
输出:
如果有可能的场景romano的猜测,输出是的,其他没有输出。
题解:
(1)如果最后一个是“=”,就跑最优路,但要注意’>‘和’<‘的个数不能超过n(在这里WA了好几发,引以为戒),如果最优路可以且’>‘和’<'的个数不超过n,则输出“YES”,否则输出“NO”;
(2)如果最后一个不是“=”,就跑最差情况(一个一个往前或一个一个往后),最后左端点不等于右端点就输出“YES”,否则输出“NO”。

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{ll n,k;cin>>n>>k;string str;cin>>str;ll len=str.size();if(len<k||(len==k&&str[len-1]=='=')){if(len>n){printf("NO\n");return 0;}ll l=1;ll r=n;ll r0=r;ll l0=l;int i;for(i=0; i<len-1; i++){if(r<=l)break;if((r-l+1)%2==0){if(str[i]=='<') r=(l+r)/2;if(str[i]=='>') l=(l+r)/2+1;}else{if(str[i]=='<') r=(l+r)/2-1;if(str[i]=='>') l=(l+r)/2;}}if(i<=len-1){if(r==l)printf("YES\n");elseprintf("NO\n");}elseprintf("NO\n");}else{ll l=1;ll r=n;for(int i=0;i<len;i++){if(str[i]=='>')r--;elsel++;}if(r>=l){printf("YES\n");}elseprintf("NO\n");}return 0;
}

Non-Interactive Guessing Number相关推荐

  1. Dump Windows password hashes efficiently

    link:http://brk.dis9.com/dump-windows-password-hashes-efficiently.html Slightly modified definition ...

  2. 10个节省时间和改善工作流的Git技巧

    根据手册,Git 被定义为傻瓜式内容追踪器,它功能丰富,但有些功能却让人望而生畏.因此,我们只是重复使用那几个被记住的命令,而没有充分使用. https://manpages.debian.org/s ...

  3. python random.randint未定义_学习python - 无法弄清楚random.randint

    那么这是我根据您发布的问题文本做的快速重写: import random input("Think of a number from 1 to 10, then press enter. D ...

  4. Rust:剑指C++

    Rust:极富活力和前途的编程语言,剑指C++ 今天开始学习Rust,马上要回去休息了,只贴上一段实例代码,在后续的学习中,会对这种语言进行一个详尽的介绍(学习中....). extern crate ...

  5. Head First Java学习笔记(2):类与对象

    类 1.类是定义同一类所有对象的变量和方法的蓝图或原型. 2.实例变量的值由类的每个实例提供.当创建类的实例时,就创建了这种类型的一个对象,然后系统为类定义的实例变量分配内存.然后可以调用对象的实例方 ...

  6. SecureCRT 5.2.2版本下载和注册码

    Name: Apollo Interactive Company: Apollo Interactive Serial Number: 03-50-023223 License Key: ABMVSR ...

  7. W ndows用户权限设置,防御Mimikatz攻击的方法介绍

    简单介绍 Mimikatz 攻击 Mimikatz 在内网渗透测试中发挥着至关重要的作用,主要是因为它能够以明文形式从内存中提取明文密码.众所周知,攻击者在他们的渗透中大量使用 Mimikatz,尽管 ...

  8. 《Head First Java》| 2-3 拜访对象村+认识变量

    目录 拜访对象村 椅子大战 类与对象的关系 创建并测试你的第一个对象 快离开main! 练习 认识变量 Java八大数据类型 数组变量 练习 拜访对象村 椅子大战 需求:在图形接口画出四方形.圆形.三 ...

  9. SecureCRT 5.2.2的注册码

    Name: Apollo Interactive Company: Apollo Interactive Serial Number: 03-50-023223 License Key: ABMVSR ...

最新文章

  1. vue 过滤器的使用(解决forEach遇到的问题)
  2. PowerDesigner反向生成物理数据模型
  3. 《深度学习的数学》二刷总结
  4. 正则表达式手机固话php,手机和固话正则的记忆方法
  5. ios 获取沙河文件夹_关于 iOS 沙盒的目录结构和获取
  6. 2019年第十届蓝桥杯 - 省赛 - C/C++研究生组 - G. 扫地机器人
  7. 剑指offer-求二叉树深度
  8. Shell脚本基本用法
  9. mysql-------视图
  10. 能够兼容ViewPager的ScrollView
  11. poi html转换成word文档,poi将html转换为word文档
  12. POI2000 病毒
  13. Split过程源码分析
  14. jpress转换html5,docker-compose安装jpress(这种是war包和生成文件在宿主机,运行在docker上)...
  15. MySQL里Wating for Slave workers to free pending events到底在等什么
  16. Android iText向pdf模板插入数据和图片
  17. 哔哩哔哩2020校园招聘前端笔试卷(一)答案解析
  18. python生成桌面路径(winreg)
  19. Android城市列表
  20. Java join()方法的使用

热门文章

  1. html文件右键没有打开方式,一个文件打不开,点右键,怎么在打开方式中加入Word,Excel的打开方式,打开方式中有Word的打开方式?...
  2. 关于十六进制、asc码
  3. Android 8.0版本更新下载
  4. 平板电脑做linux服务器,平板电脑安装Ubuntu教程-以V975w为例,Z3735系列CPU通用
  5. QT drawPixmap和drawImage处理图片模糊问题
  6. Spring boot + netty开发即时通讯 IM
  7. 拉里 埃里森_拉里·埃里森(Larry Ellison)的宝座
  8. Python 批量将.xlsx文件转为.xls文件
  9. IO Workload Characterization Revisited: A Data-Mining Approach
  10. 计算机网络介质图片,存储介质是什么