交互题[CF1103B Game with modulo、CF1019B The hat、CF896B Ithea Plays With Chtholly]
交互题就是程序与电脑代码的交互。
比如没有主函数的程序,而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]的更多相关文章
- Codeforces 897D. Ithea Plays With Chtholly (交互)
题目链接:D. Ithea Plays With Chtholly 题意: 给你n张纸,在纸上写字(在 1 - c之间)可以写m次数 (,).(主要是交互,让你判断) 题解: 首先,看到m>=n ...
- D. Game with modulo 交互题(取余(膜)性质)附带a mod b<a/2证明
D. Game with modulo 交互题(取余(膜)性质) 题意 猜一个点\(a\)可以向机器提问 点对\((x,y)\) 如果\(x\mod(a)>=y\mod(a)\)回答\(x\) ...
- CF1114E Arithmetic Progression(交互题,二分,随机算法)
既然是在CF上AC的第一道交互题,而且正是这场比赛让我升紫了,所以十分值得纪念. 题目链接:CF原网 题目大意:交互题. 有一个长度为 $n$ 的序列 $a$,保证它从小到大排序后是个等差数列.你不知 ...
- Codeforces 1137D - Cooperative Game - [交互题+思维题]
题目链接:https://codeforces.com/contest/1137/problem/D 题意: 交互题. 给定如下一个有向图: 现在十个人各有一枚棋子(编号 $0 \sim 9$),在不 ...
- Gym - 101375H MaratonIME gets candies 交互题
交互题介绍:https://loj.ac/problem/6 题意:输出Q X ,读入><= 来猜数,小于50步猜出就算过样例 题解:根本不需要每次输出要打cout.flush()... ...
- Codeforces Round #523 (Div. 2) F. Katya and Segments Sets (交互题+思维)
https://codeforces.com/contest/1061/problem/F 题意 假设存在一颗完全k叉树(n<=1e5),允许你进行最多(n*60)次询问,然后输出这棵树的根,每 ...
- Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分
D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...
- 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 ...
- [CF1103B]Game with modulo
题目大意:交互题,有一个数$a(a\leqslant10^9)$,需要猜出它的值,一次询问为你两个数字$x,y(x,y\in[0,2\times10^9])$: 若$x\bmod a\geqslant ...
随机推荐
- Python XML解析之DOM
DOM说明: DOM:Document Object Model API DOM是一种跨语言的XML解析机制,DOM把整个XML文件或字符串在内存中解析为树型结构方便访问. https://docs. ...
- SQL Server -- 回忆笔记(四):case函数,索引,子查询,分页查询,视图,存储过程
SQL Server知识点回忆篇(四):case函数,索引,子查询,分页查询,视图,存储过程 1. CASE函数(相当于C#中的Switch) then '未成年人' else '成年人' end f ...
- SQLServer之视图简介
视图定义 视图是一个虚拟表,其内容由查询定义. 同表一样,视图包含一系列带有名称的列和行数据. 视图在数据库中并不是以数据值存储集形式存在,除非是索引视图. 行和列数据来自由定义视图的查询所引用的表, ...
- Python基础之面对对象进阶
阅读目录 isinstance和issubclass 反射 setattr delattr getattr hasattr __str__和__repr__ __del__ item系列 __geti ...
- 爬虫系列二(数据清洗--->xpath解析数据)
一 xpath介绍 XPath 是一门在 XML 文档中查找信息的语言.XPath 用于在 XML 文档中通过元素和属性进行导航. XPath 使用路径表达式在 XML 文档中进行导航 XPath 包 ...
- applicationSettings设置和appsttings
applicationSettings 可以和sttings一样在配置文件中,设置参数.支持定义参数的类型“serializaAs=string”,并可以使用 . 语法. 可以使用.语法
- javaScript判断手机型号
window.onload = function () { alert("1"); var u = navigator.userAgent; if (u.indexOf('Andr ...
- python3 Counter模块
from collections import Counter c = Counter("周周周周都方法及")print(c)print(type(c))print('__iter ...
- 想了解SAW,BAW,FBAR滤波器的原理?看这篇就够了!
想了解SAW,BAW,FBAR滤波器的原理?看这篇就够了! 很多通信系统发展到某种程度都会有小型化的趋势.一方面小型化可以让系统更加轻便和有效,另一方面,日益发展的IC**技术可以用更低的成本生产 ...
- Nginx(四)------nginx 负载均衡
在上一篇博客我们介绍了 Nginx 一个很重要的功能——代理,包括正向代理和反向代理.这两个代理的核心区别是:正向代理代理的是客户端,而反向代理代理的是服务器.其中我们又重点介绍了反向代理,以及如何通 ...