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 ...
随机推荐
- java基础一(2020.1.3)
今日学习内容: 带命令行参数的Java实例 Java的程序结构 Java的变量与常量 带命令行参数的Java实例: class ArgsDemo{ public static void main(St ...
- 参考JDK1.8源码,自己写一个类似于ArrayList的动态数组
1. ArrayList的基本实现原理 ArrayLiST其内部用一个普通数组来存储数据,当此数组不够容纳新添加的元素的时候,则创建一个更大长度的新数组,并将原来数组中的元素复制到新数组中. 2.Ar ...
- TT(Tokyo Tyrant )介绍及使用
Tokyo Cabinet 是日本人 平林幹雄 开发的一款 DBM 数据库,该数据库读写非常快,哈希模式写入100万条数据只需0.643秒,读取100万条数据只需0.773秒,是 Berkeley D ...
- 使用meshgrid生成热图和单位向量场
需求: 生成 中heatmap unit vector field 目前的数据: 图像的shape, 关键点的x,y , heatmap的半径R 思路: 如果使用for循环来判断距离,会很慢,如果预先 ...
- Python笔记_第二篇_面向过程_第二部分_4.常用模块的简单使用_import语句的解释
1. import语句.from...import语句.from...import*语句 解释:注意一定要在体同一级目录下 1.1 引入模块 格式:import module[,module2,... ...
- InsertionSort(插入排序)原理及C++代码实现
插入排序是最常用的排序之一. 在输入规模较小的时候,插入排序的性能较好. 最好情况下插入排序的时间复杂度是O(n),平均情况则为O(n2). 插入排序是稳定的排序算法之一. 基本思路为从第二个元素开始 ...
- Fabric不支持对同一个数据的并发事务处理
Fabric不支持对同一个数据的并发事务处理,也就是说, 如果我们同时运行了invoke(一),invoke(二),那么只会第一条Transaction成功, 而第二条失败.因为在Committer节 ...
- [转载]Python方法绑定——Unbound/Bound method object的一些梳理
本篇主要总结Python中绑定方法对象(Bound method object)和未绑定方法对象(Unboud method object)的区别和联系.主要目的是分清楚这两个极容易混淆的概念,顺便将 ...
- sockaddr_in 转成string
string strAcceptIp = inet_ntoa(remoteAddr.sin_addr);
- tp3中子查询 逻辑条件是or
直接用写sql最快 $map['_string'] = 'status=1 AND score>10'; //子查询条件字段不同 $condition['platform'] = 'swap'; ...