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

比如没有主函数的程序,而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. Linux 中NFS服务器的搭建

    serve端IP:192.168.2.128 客户端IP:192.168.2.131 server端配置: 1.安装nfs,rpcbind,可以参考Linux 中yum的配置来安装: yum inst ...

  2. Linux 用户关联命令

    在执行useradd命令创建用户时,它首先读取/etc/default/useradd文件的配置参数,然后通过这些参数来配置新创建的用户,如创建名为luser的用户. [root@rhl5 -]# u ...

  3. Redhat安装Oracle 11g (转)

    1.1     安装前准备 1.1.1     修改操作系统核心参数 在Root用户下执行以下步骤: 1.1.1.1 修改/etc/security/limits.conf文件 输入命令:vi /et ...

  4. spark读写hbase性能对比

    一.spark写入hbase hbase client以put方式封装数据,并支持逐条或批量插入.spark中内置saveAsHadoopDataset和saveAsNewAPIHadoopDatas ...

  5. Configuring High Availability and Consistency for Apache Kafka

    To achieve high availability and consistency targets, adjust the following parameters to meet your r ...

  6. springboot中,页面访问不到静态资源

    例一,静态资源放在默认的目录,如:resources/static或resources/templates 访问静态资源的时候,路径不应带上默认目录,因为springboot默认从这些目录下开始加载, ...

  7. android glide图片加载框架

    项目地址: https://github.com/bumptech/glide Glide作为安卓开发常用的图片加载库,有许多实用而且强大的功能,那么,今天就来总结一番,这次把比较常见的都写出来,但并 ...

  8. CentOS 6.5 minimal 安装配置VMware tools

    1.登录到系统,切换到root账户 2.配置网络 minimal版本默认不启动网络,所以要自己配置. 配置过程很简单,编辑配置文件 vi /etc/sysconfig/network-script/i ...

  9. python小白——进阶之路——day3天-———运算符

    (1)算数运算符:  + - * / // % ** (2)比较运算符:  > < >= <= == != (3)赋值运算符:  = += -= *= /= //= %= ** ...

  10. Spring Cloud:统一异常处理

    在启动应用时会发现在控制台打印的日志中出现了两个路径为 {[/error]} 的访问地址,当系统中发送异常错误时,Spring Boot 会根据请求方式分别跳转到以 JSON 格式或以界面显示的 /e ...