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≤iN−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≤iN−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 VacantMale 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 012 are occupied by a man, occupied by a woman and vacant, respectively.

Input Output
3  
  0
Male  
  1
Female  
  2
Vacant  
题意:给你大于等于3的奇数个座位,编号0到N-1,座位情况为空,男,女,其中同性不相邻,至少存在一个空座位,然后你询问一个座位编号,它告诉你现在那个地方是不是空,时空就结束,如果不是就告诉你这个地方的人的性别。要在20次查询以内得出结果!所以必然需要二分!
分析:这是第一次看到交互式题目,真的是看的我很懵逼!觉得很有必要写个博客!交互式,和我们原来做题目的模式是刚好相反的!像题目中给出的案例:输入N以后,输出0,然后我们输入Male,代表0号位置上面坐的男性,下面同样!但是以往我们做的非交互题目都是输入座位编号,然后电脑输出座位的信息!
(注意:这一所谓的性别相同的不能相邻是说中间假设存在空座位的两个性别相同的人之间是相邻的!或者直接相邻!
举个例子:5和7
N=5时,假设0位置为男性,mid=2,如果2号位置与0号位置同性别(假设为男),则一号位置必为女,所以去另外一边查找,left=mid;在left和mid位置同性别的情况下,只要mid-left为偶数就意味着中间不存在空座位;如果left与mid位置性别不同,即本例中的0号和2号位置的性别不同,那么他们中间必然为空;
N=7时,同上假设,mid=3,如果0号和3号位置同性别,就意味着中间两个必然有一个为空,所以right=mid,如果性别不同就意味着中间必然是两种性别交替出现,必然不存在空座位,所以此时left=mid,要注意此时的性别也要换成mid位置的性别。可以画图认真体会!
AC代码:

#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-交互式题目)的更多相关文章

  1. 【AtCoder】AtCoder Petrozavodsk Contest 001

    A - Two Integers 如果\(X\)是\(Y\)的倍数的话不存在 可以输出\(X \cdot (\frac{Y}{gcd(X,Y)} - 1)\) 代码 #include <bits ...

  2. AtCoder Petrozavodsk Contest 001

    第一场apc,5H的持久战,我当然水几个题就睡了 A - Two Integers Time limit : 2sec / Memory limit : 256MB Score : 100 point ...

  3. AtCoder 杂题训练

    前言: 因为要普及了,今年没一等就可以退役去学文化课了,所以暑假把历年noip普及组都刷了一遍,离noip还有50+天,想弄点强化训练什么的. 想了想,就这些天学文化课之余有空就把AtCoder之前那 ...

  4. 洛谷——P2071 座位安排 seat.cpp/c/pas

    P2071 座位安排 seat.cpp/c/pas 题目背景 公元二零一四年四月十七日,小明参加了省赛,在一路上,他遇到了许多问题,请你帮他解决. 题目描述 已知车上有N排座位,有N*2个人参加省赛, ...

  5. [Atcoder Regular Contest 060] Tutorial

    Link: ARC060 传送门 C: 由于难以维护和更新平均数的值: $Average->Sum/Num$ 这样我们只要用$dp[i][j][sum]$维护前$i$个数中取$j$个,且和为$s ...

  6. 洛谷 P2071 座位安排 seat.cpp/c/pas

    P2071 座位安排 seat.cpp/c/pas 题目背景 公元二零一四年四月十七日,小明参加了省赛,在一路上,他遇到了许多问题,请你帮他解决. 题目描述 已知车上有N排座位,有N*2个人参加省赛, ...

  7. ZJOI2017 Day1

    私のZJOI Day1 2017-3-21 07:52:53 有人在暴力膜 苟-- 富贵 无相忘 ZJOI2017交流群 133135071 如果你足够厉害 如果你足够厉害 如果你足够厉害 其实完全可 ...

  8. English_word_learning

    这次报名参加了学院的21天打卡活动,说实话,也是想给自己一个积累的平台. 毕竟,真的有时候感觉挺弱的 有的人用了一年考完了四六级,而有人却用四年还未考完. 听到有一位学长因为自己的四级成绩没有达到48 ...

  9. 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 ...

随机推荐

  1. MAC上的爬虫软件怎么选?看完这篇就够了

    在上一篇文章:网络爬虫软件哪个好用? 中,我们介绍了目前市面上比较成熟好用的网络爬虫软件, 但是其中有些不能在MAC上使用,因此今天这篇文章我们单独介绍一下在MAC操作系统中有哪些好用的爬虫软件,给大 ...

  2. typescript-学习使用ts-1

    Hello World 新建 greeter.ts 并写入以下内容: function greeter(person) { return "Hello, " + person; } ...

  3. LeetCode——199. 二叉树的右视图

    给定一棵二叉树,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值. 示例: 输入: [1,2,3,null,5,null,4] 输出: [1, 3, 4] 解释: 1 < ...

  4. 898B. Proper Nutrition#买啤酒问题(枚举&取余)

    题目出处:http://codeforces.com/problemset/problem/898/B 题目大意:为一个整数能否由另外两个整数个整数合成 #include<iostream> ...

  5. i2c驱动dht12的原理和步骤

    一.步骤 1.首先匹配i2c的控制器设备和控制器驱动,会生成一个struct i2c_adapter对象, 2.根据i2c_board_info   ,在  arch/arm/mach-sunxi/s ...

  6. win10+CUDA9.0176、CUDNN7.6.0安装

    在github上下载了一个文本分类的代码,包含了CNN.LSTM等分类模型,运行时说我的CUDA版本不行,我原来是9.1,让我安装9.0 然后开始卸载9.1啊,在此感谢博主:https://blog. ...

  7. P2448 无尽的生命(树状数组+离散化)

    题目描述 逝者如斯夫,不舍昼夜! 叶良辰认为,他的寿命是无限长的,而且每天都会进步. 叶良辰的生命的第一天,他有1点能力值.第二天,有2点.第n天,就有n点.也就是S[i]=i 但是调皮的小A使用时光 ...

  8. BucketSort(桶排序)原理及C++代码实现

    桶排序假设输入数据服从均匀分布,平均情况下它的时间复杂度为O(n). 桶排序将输入数据的区间均匀分成若干份,每一份称作“桶”.分别对每一个桶的内容进行排序,再按桶的顺序输出则完成排序. 通常使用链表来 ...

  9. ROC曲线、KS曲线

    一.ROC曲线 ROC曲线由混淆矩阵为基础数据生成. 纵坐标:真阳性比率TPR,预测为正占真正为正的比例. 横坐标:假阳性比率FPR,预测为正占真正为负的比例. 除了roc曲线的纵横坐标外,还有一个准 ...

  10. in+sb's+基数词的复数形式|UFO|the minutes|

    Hawking became world-famous in ________.  A. his thirties in the 1970's  B. the thirties in his 1970 ...