交互题就是程序与电脑代码的交互。

比如没有主函数的程序,而spj则给你一段主函,就变成了一个整体函数。

还有一种就是程序和spj之间有互动,这个用到fflush(stdout);这个函数就可以实现交互了

fflush(stdin)

  作用:清理标准输入流,把多余的未被保存的数据丢掉

fflush(stdout)

  作用:清空输出缓冲区,并把缓冲区内容输出

CF1103B Game with modulo

题意:有一个需要你猜的数a,你每次可以猜两个数,如果x%a>=y%a,则返回x,否则返回y。你最多可以猜60次。

这很明显是个二分,所以这大概是道交互题练手题

#include<bits/stdc++.h>
using namespace std;
char s[20], s1[20];
int main() {
while ((~scanf("%s", s)) && s[0] == 's') {
int x = 0, y = 1;
while (true) {
printf("? %d %d\n", x, y);
fflush(stdout);
scanf("%s", s1);
if (s1[0] == 'x')
break;
x = y, y = y * 2 + 1;
}
int mid, l = x, r = y;
while (l + 1 < r) {
mid = l + r >> 1;
printf("? %d %d\n", l, mid);
fflush(stdout);
scanf("%s", s1);
if (s1[0] == 'x')
r = mid;
else
l = mid;
}
if (l == 0) {
printf ("! 1\n");
fflush(stdout);
continue;
}
printf("? %d %d\n", r, r + 1);
fflush(stdout);
scanf("%s", s1);
if (s1[0] == 'x')
r --;
printf("! %d\n",r);
fflush(stdout);
}
return 0;
}

CF1019B The hat

又是b题(我就只能做做b题,我太菜了QWQ)

#include <bits/stdc++.h>
using namespace std;
int n, t, r, mid, l;
inline int find (int x) {
printf("? %d\n", x + 1);
fflush(stdout);
scanf("%d", &x);
return x;
}
int main() {
scanf("%d", &n);
t = n / 2;
if (t & 1) {
printf("! -1\n");
return 0;
}
r = n - 1;
while (l < r) {
mid = l + r >> 1;
if (find(mid) - find((mid + t) % n) >= 0)
r = mid;
else
l = mid + 1;
}
printf("! %d", l + 1);
fflush(stdout);
return 0;
}

  

CF896B Ithea Plays With Chtholly

还是B题2333

#include <bits/stdc++.h>
using namespace std;
int a[1005], n, m, c, x;
int main() {
scanf("%d%d%d", &n, &m, &c);
int i;
while(m --) {
scanf("%d", &x);
if(x > c / 2)
for (i = n; a[i] >= x; -- i);
else
for (i = 1; a[i] && a[i] <= x; ++ i);
printf("%d\n", i);
fflush(stdout);
a[i] = x;
for (i = 1; i <= n && a[i]; ++ i);
if (i > n)
break;
}
return 0;
}

  

交互题[CF1103B Game with modulo、CF1019B The hat、CF896B Ithea Plays With Chtholly]的更多相关文章

  1. Codeforces 897D. Ithea Plays With Chtholly (交互)

    题目链接:D. Ithea Plays With Chtholly 题意: 给你n张纸,在纸上写字(在 1 - c之间)可以写m次数 (,).(主要是交互,让你判断) 题解: 首先,看到m>=n ...

  2. D. Game with modulo 交互题(取余(膜)性质)附带a mod b<a/2证明

    D. Game with modulo 交互题(取余(膜)性质) 题意 猜一个点\(a\)可以向机器提问 点对\((x,y)\) 如果\(x\mod(a)>=y\mod(a)\)回答\(x\) ...

  3. CF1114E Arithmetic Progression(交互题,二分,随机算法)

    既然是在CF上AC的第一道交互题,而且正是这场比赛让我升紫了,所以十分值得纪念. 题目链接:CF原网 题目大意:交互题. 有一个长度为 $n$ 的序列 $a$,保证它从小到大排序后是个等差数列.你不知 ...

  4. Codeforces 1137D - Cooperative Game - [交互题+思维题]

    题目链接:https://codeforces.com/contest/1137/problem/D 题意: 交互题. 给定如下一个有向图: 现在十个人各有一枚棋子(编号 $0 \sim 9$),在不 ...

  5. Gym - 101375H MaratonIME gets candies 交互题

    交互题介绍:https://loj.ac/problem/6 题意:输出Q X ,读入><= 来猜数,小于50步猜出就算过样例 题解:根本不需要每次输出要打cout.flush()... ...

  6. Codeforces Round #523 (Div. 2) F. Katya and Segments Sets (交互题+思维)

    https://codeforces.com/contest/1061/problem/F 题意 假设存在一颗完全k叉树(n<=1e5),允许你进行最多(n*60)次询问,然后输出这棵树的根,每 ...

  7. Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分

    D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...

  8. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem K. KMC Attacks 交互题 暴力

    Problem K. KMC Attacks 题目连接: http://codeforces.com/gym/100714 Description Warrant VI is a remote pla ...

  9. [CF1103B]Game with modulo

    题目大意:交互题,有一个数$a(a\leqslant10^9)$,需要猜出它的值,一次询问为你两个数字$x,y(x,y\in[0,2\times10^9])$: 若$x\bmod a\geqslant ...

随机推荐

  1. (办公)SpringBoot和swagger2的整合.

    因为开发项目的接口需要给app,小程序测试,所以用swagger. 1.pom.xml: <dependency><!--添加Swagger依赖 --> <groupId ...

  2. 数据库H2学习

    本文转载自:https://www.cnblogs.com/xdp-gacl/p/4171024.html 一.H2数据库介绍 常用的开源数据库有:H2,Derby,HSQLDB,MySQL,Post ...

  3. 连接到github

    1,创建秘钥 $ ssh-keygen -t rsa -C "youremail@example.com"执行成功后,会在~/.ssh/目录下生成id_rsa和id_rsa.pub ...

  4. Swift NSAttributedString的使用

    NSMutableAttributedString let testAttributes = [NSAttributedStringKey.foregroundColor: UIColor.blue, ...

  5. Linux 自动化部署DNS服务器

    Linux 自动化部署DNS服务器 1.首先配置主DNS服务器的IP地址,DNS地址一个写主dns的IP地址,一个写从dns的地址,这里也可以不写,在测试的时候在/etc/resolv.conf中添加 ...

  6. 为Arch Linux更换Archlinuxcn源(清华源)

    上一篇随笔 archlinux切换官方中国源 里面写了如何切换到官方的中国源,但是因为那个源有一些软件并没有,特别是一些国人常用的中文软件,比如搜狗输入法等这些都是没有的.所以我们现在需要手动切换源一 ...

  7. 《精通Spring+4.x++企业应用开发实战》读后感

    引言 还记得大三时上培训班的是时候,当时的培训老师说自己是本地讲解spring最好的讲师,但是后来等我实习了看了<Spring 3.x 企业应用开发实战>以及后续版本<精通Sprin ...

  8. easyui中datagrid+layout布局

    1.掌握layout布局 首先,layout布局的具体使用可参考官网http://www.jeasyui.net/plugins/162.html layout布局分为东南西北中五个区域,如图我们将其 ...

  9. 在windows下远程访问linux桌面

    一.安装xrdp工具: #  yum install xrdp #   yum install tigervnc-server #   service xrdp start 以上三个命令执行完毕安装完 ...

  10. Kafka 详解(一)------简介

    在前面几篇博客我们介绍过一种消息中间件——RabbitMQ,本篇博客我们介绍另外一个消息中间件——Kafka,Kafka是由LinkedIn开发的,使用Scala编写,是一种分布式,基于发布/订阅的消 ...