Vacant Seat(Atcoder-C-交互式题目)
C - Vacant Seat
Time limit : 2sec / Memory limit : 256MB
Score : 500 points
Problem Statement
This is an interactive task.
Let N be an odd number at least 3.
There are N seats arranged in a circle. The seats are numbered 0 through N−1. For each i (0≤i≤N−2), Seat i and Seat i+1 are adjacent. Also, Seat N−1 and Seat 0 are adjacent.
Each seat is either vacant, or oppupied by a man or a woman. However, no two adjacent seats are occupied by two people of the same sex. It can be shown that there is at least one empty seat where N is an odd number at least 3.
You are given N, but the states of the seats are not given. Your objective is to correctly guess the ID number of any one of the empty seats. To do so, you can repeatedly send the following query:
- Choose an integer i (0≤i≤N−1). If Seat i is empty, the problem is solved. Otherwise, you are notified of the sex of the person in Seat i.
Guess the ID number of an empty seat by sending at most 20 queries.
Constraints
- N is an odd number.
- 3≤N≤99 999
Input and Output
First, N is given from Standard Input in the following format:
N
Then, you should send queries. A query should be printed to Standart Output in the following format. Print a newline at the end.
i
The response to the query is given from Standard Input in the following format:
s
Here, s is Vacant, Male or Female. Each of these means that Seat i is empty, occupied by a man and occupied by a woman, respectively.
Notice
- Flush Standard Output each time you print something. Failure to do so may result in
TLE. - Immediately terminate the program when s is
Vacant. Otherwise, the verdict is indeterminate. - The verdict is indeterminate if more than 20 queries or ill-formatted queries are sent.
Sample Input / Output 1
In this sample, N=3, and Seat 0, 1, 2 are occupied by a man, occupied by a woman and vacant, respectively.
| Input | Output |
|---|---|
| 3 | |
| 0 | |
| Male | |
| 1 | |
| Female | |
| 2 | |
| Vacant |
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<stack>
#include<map>
#include<vector>
#include<queue>
#define N 15
using namespace std;
typedef long long ll;
char s[N];
int main()
{
ios::sync_with_stdio(false);
int n,left,right,mid;
int M1,M2;//用于标记性别
cin>>n;
cout << "" << endl;
cin>>s;
if (s[]=='V')
return ;
if (s[]=='M') M1=;
else M1=;
left=,right=n;
while (left<right)
{
mid=(right+left)/;
cout << mid << endl;
cin>>s;
if (s[]=='V')
return ;
if (s[]=='M') M2=;
else M2=;
int t=(mid-left);
if (t%==)
{
if (M1==M2) left=mid;
else right=mid;
}
else
{
if (M1==M2) right=mid;
else left=mid,M1=M2;
}
}
cout << flush;
return ;
}
Vacant Seat(Atcoder-C-交互式题目)的更多相关文章
- 【AtCoder】AtCoder Petrozavodsk Contest 001
A - Two Integers 如果\(X\)是\(Y\)的倍数的话不存在 可以输出\(X \cdot (\frac{Y}{gcd(X,Y)} - 1)\) 代码 #include <bits ...
- AtCoder Petrozavodsk Contest 001
第一场apc,5H的持久战,我当然水几个题就睡了 A - Two Integers Time limit : 2sec / Memory limit : 256MB Score : 100 point ...
- AtCoder 杂题训练
前言: 因为要普及了,今年没一等就可以退役去学文化课了,所以暑假把历年noip普及组都刷了一遍,离noip还有50+天,想弄点强化训练什么的. 想了想,就这些天学文化课之余有空就把AtCoder之前那 ...
- 洛谷——P2071 座位安排 seat.cpp/c/pas
P2071 座位安排 seat.cpp/c/pas 题目背景 公元二零一四年四月十七日,小明参加了省赛,在一路上,他遇到了许多问题,请你帮他解决. 题目描述 已知车上有N排座位,有N*2个人参加省赛, ...
- [Atcoder Regular Contest 060] Tutorial
Link: ARC060 传送门 C: 由于难以维护和更新平均数的值: $Average->Sum/Num$ 这样我们只要用$dp[i][j][sum]$维护前$i$个数中取$j$个,且和为$s ...
- 洛谷 P2071 座位安排 seat.cpp/c/pas
P2071 座位安排 seat.cpp/c/pas 题目背景 公元二零一四年四月十七日,小明参加了省赛,在一路上,他遇到了许多问题,请你帮他解决. 题目描述 已知车上有N排座位,有N*2个人参加省赛, ...
- ZJOI2017 Day1
私のZJOI Day1 2017-3-21 07:52:53 有人在暴力膜 苟-- 富贵 无相忘 ZJOI2017交流群 133135071 如果你足够厉害 如果你足够厉害 如果你足够厉害 其实完全可 ...
- English_word_learning
这次报名参加了学院的21天打卡活动,说实话,也是想给自己一个积累的平台. 毕竟,真的有时候感觉挺弱的 有的人用了一年考完了四六级,而有人却用四年还未考完. 听到有一位学长因为自己的四级成绩没有达到48 ...
- Codeforces Round #525 (Div. 2)D. Ehab and another another xor problem
D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Descripti ...
随机推荐
- C到C++转变简述
从 C 到 C++ 语言的转变 1.平时使用还以 printf, scanf 为主 printf 和 scanf 与 cin cout 相比效率更快 2.头文件改成如下,C++对C语言兼容 #incl ...
- c/c++基础 输入函数/流
....光看算法了没怎么注意输入函数输入流 无论get(char *) gets(char *)/gets_s(char * ,sizeof char*) cin.getline(char* ,siz ...
- bzoj2127happiness(最小割)
一眼最小割. 一种比较好想的建图方式如下: 连源点表示学文,连汇点表示学理,然后adde(S,id(i,j),a[i][j]),adde(id(i,j),T,b[i][j]):对于相邻座位选择同一科的 ...
- JavaScript学习笔记 - 进阶篇(3)- 流程控制语句
if语句 if语句是基于条件成立才执行相应代码时使用的语句. 语法: if(条件) { 条件成立时执行代码} 注意:if小写,大写字母(IF)会出错! 假设你应聘web前端技术开发岗位,如果你会HTM ...
- SQL Link Oracle
转自:http://www.2cto.com/database/201107/96105.html 做项目过程中常用到数据库同步,现把前一段时间做的一个项目部分,同步过程贴出来,供分享与自己参考! 本 ...
- Eova 怎么放在 Docker中,使用阿里云流水线构建Eova!!
Eova 快速开发框架不做过多解释,使用起来超级爽提高了我们的开发效率. 有要了解的可以去官网看下http://www.eova.cn/ 最近我们想在docker中运行并且使用阿里云的云效工具去构建部 ...
- 吴裕雄--天生自然 pythonTensorFlow图形数据处理:输入文件队列
import tensorflow as tf # 1. 生成文件存储样例数据. def _int64_feature(value): return tf.train.Feature(int64_li ...
- Halcon系列(1) 菜鸟入门
官方网站怎么使用HDevelop :https://www.mvtec.com/products/halcon/halcon-tour
- 使用VMware vSphere Client管理ESXI(新建虚拟机)
1.下载vSphere Client客户端 2.将镜像文件(ISO)上传到ESXI主机,具体操作见如下链接地址 https://blog.csdn.net/amandazhouzhou/article ...
- Java复习(三)类中的方法
3.1方法的控制流程 与C/C++类似 3.2异常处理 Java处理错误的方法 抛出(throw)异常 在方法的运行过程中,如果发生了异常,则该方法生成一个代表该异常的代码并把它交给运行时系统,运行时 ...