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 ...
随机推荐
- (最全最灵活地)利用Jxl工具包实现Excel表的内容读取 、写入(可向已有表中追加数据)
1.引子 (1)读取 Jxl工具比较强大,可以方便地实现Excel表的读取和写入.另一款工具Poi也具有相似的功能,并且功能更多,运用也相对复杂.Poi读取Excel表内容时,需要先判断其内容格式,如 ...
- mysql 不停机 短时间锁表 备份 主备同步 新增备份机器
刷新数据 [root@localhost ~]# mysql -e 'flush tables with read lock;' 锁表刷新表数据 [root@localhost ~]# mys ...
- rpm包管理工具
介绍: RPM [1] 是Red-Hat Package Manager(RPM软件包管理器)的缩写,这一文件格式名称虽然打上了RedHat的标志,但是其原始设计理念是开放式的,现在包括OpenLi ...
- java centos7 gcc编码 解决socket通信 汉字乱码
1.把 Java eclipes 设置编码成utf-8 windows->preference->workspace 2.centos7 gcc 默认为utf-8
- Nmap_使用介绍
Nmap 注意,本文仅是作为课余时间的学习了解,请不要做有关违反法律法规的事情,违者自行承担后果!!! 环境centos7.7yum -y install nmap 命令操作 1.扫描单个目标 1. ...
- BaseAdapter教程(2) BaseAdapter的notifyDataSetChanged动态刷新
遇到了这麽一个需求,ListView滑到最底,然后会自动在底部加入新的Cell,实现动态刷新. 1. 首先,为ListView加上setOnScrollListener. lvHomePostItem ...
- E - Apple Tree(树状数组+DFS序)
There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. ...
- crm项目-业务实现
############### crm业务 ############### """ 校区管理,部门管理,课程管理, 这三个都比较简单 1,只需要展示校区名称,这是 ...
- Navicat 12 无限期试用
最近发现navicat12又过期了,以前的是用的破解软件,然后是到1899年过期哈哈哈哈哈哈.重装了系统后,软件也重装了,发现破解软件不好使了,就先试用了,现在到期了.很是难受,这可咋整,不过在网上看 ...
- SpringBoot 系列 - 自己写starter
原文地址: https://www.xncoding.com/2017/07/22/spring/sb-starter.html 前言: Spring Boot由众多Starter组成,随着版本的推移 ...