acm交互题
1、Dragon Balls
根据勾股定理把所有整数点都给求解出来,然后依次询问,注意数据范围
暴力求解,把每次可能的值都求出来,然后逐个比较。
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int x, n;
typedef pair<int, int> pii;
vector<pii> vet;
signed main(){
cin >> n;
while(n -- ){
cout << 0 <<" " << 0 << endl;
cout.flush();
cin >> x;
vet.clear();
if(x == 0) continue;
for(int i = 0; i * i <= x; i++){
int a = i * i;
int b = x - a;
int y = sqrt(b);
if(y * y == b) vet.push_back({i, y});
}
for(vector<pii>::iterator it = vet.begin(); it != vet.end(); it ++){
pii t = *it;
if(t.first < 0 || t.first > 1e6 || t.second < 0 || t.second > 1e6) continue;
cout << t.first <<" " << t.second << endl;
cout.flush();
cin >> x;
if(x == 0) break;
}
}
return 0;
}
2、D. Fixed Point Guessing
题意:给你n个数(n是奇数),交换(n) / 2组不交叉的数,比如刚开始是1,2,3,4,5交换完之后可能是4,2,5,1,3。通过不超过15次询问,找出来那个没有被交换的位置。
在一个区间里面,如果含有没有被交换位置的数,那么这个属于这个区间的数的个数一定是奇数。
因为,如果是区间内的数相互交换,那么贡献值是2,如果是某个数和外边的数交换,贡献值是0.只有当含有不交换的那个数的时候,该区间内的属于这个区间的数的个数才会是奇数。
比较裸的一个二分。
#include<bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
int t, n, a[N], cnt, x;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while( t --){
cin >> n;
int l = 1, r = n;
while(l < r){
int mid = (l + r + 1) >> 1;
cnt = 0;
cout << "? " << mid <<" " << r << endl;
cout.flush();
for(int i = 1; i <= r - mid + 1; i ++){
cin >> x;
if(x >= mid && x <=r) cnt ++;
}
if(cnt % 2 != 0) l = mid;
else r = mid - 1;
}
cout <<"! " << l << endl;
}
return 0;
}
3、I. Interactive Treasure Hunt
题意:在一个最大16*16的网格里,有两个点有宝藏,通过不超过七次询问,找出宝藏的位置。询问有两种,①scan x y:输出俩宝藏到点(x,y)的曼哈顿距离和;②dig x y:询问点(x,y)是不是宝藏点。
思路:先scan(1,1),scan(n,1)。求出来俩距离d1,d2。然后整理算出来sx = x1 + x2, sy = y1 + y2。下一步,scan(sx/2,1),scan(1,sy/2)。根据这四个式子,可以算出来x1,x2,y1,y2。但不确定y1,y2和x1,x2的对应关系,所以询问一次,看哪个是符合条件的。
#include <bits/stdc++.h>
using namespace std;
int t, x, y,d1, d2, d3,d4, n, m, d5;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while(t --){
cin >> n >> m;
int cnt = 4;
cout << "SCAN " << 1 <<" " << 1 << endl;
cout.flush();
cin >> d1;
cout << "SCAN " << n <<" " << 1 << endl;
cout.flush();
cin >> d2;
int sx = (d1 - d2 + 2 * n + 2) / 2 ;
int sy = (d2 + d1 + 6 - 2 * n) / 2;
cout << "SCAN " << sx / 2 <<" " << 1 << endl;
cout.flush();
cin >> d3;
cout << "SCAN " << 1 <<" " << sy / 2 << endl;
cout.flush();
cin >> d4;
int nx = (sx - (d3 - sy + 2))/ 2;
int mx = (sx + d3 - sy + 2) / 2;
int ny = (sy - (d4 - sx + 2))/ 2;
int my = (sy + (d4 - sx + 2)) / 2;
cout <<"DIG " << nx <<" " << ny << endl;
cout.flush();
cin >> x;
if(x == 1){
cout <<"DIG " << mx <<" " << my << endl;
cin >> x;
}
else{
cout <<"DIG " << nx <<" " << my << endl;
cin >> x;
cout <<"DIG " << mx <<" " << ny << endl;
cin >> y;
}
}
return 0;
}
acm交互题的更多相关文章
- ACM 做题过程中的一些小技巧。
ACM做题过程中的一些小技巧. 1.一般用C语言节约空间,要用C++库函数或STL时才用C++; cout.cin和printf.scanf最好不要混用. 2.有时候int型不够用,可以用long l ...
- ACM 刷题小技巧【转】
转载自URl-team ACM做题过程中的一些小技巧. 1.一般用C语言节约空间,要用C++库函数或STL时才用C++; cout.cin和printf.scanf最好不要混用. 大数据输入输出时最好 ...
- 交互题[CF1103B Game with modulo、CF1019B The hat、CF896B Ithea Plays With Chtholly]
交互题就是程序与电脑代码的交互. 比如没有主函数的程序,而spj则给你一段主函,就变成了一个整体函数. 还有一种就是程序和spj之间有互动,这个用到fflush(stdout);这个函数就可以实现交互 ...
- 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 ...
- CF1153E Serval and Snake(交互题)
题目 CF1153E Serval and Snake 很有意思的一道交互题 做法 我们观察到,每次查询一行,当这一行仅包含一端是返回的答案是奇数 根据这个性质查询每一行每一列,我们大体能知道两端的位 ...
随机推荐
- [转帖]36.堆空间的参数设置和-XX:HandlePromotionFailure
目录 1.堆空间参数 2.-XX:HandlePromotionFailure 1.堆空间参数 * -XX:+PrintFlagsInitial : 查看所有的参数的默认初始值 * -XX:+Prin ...
- [转帖]setsockopt(setsockopt的使用方法及注意事项)
http://xingzuo.aitcweb.com/9156453.html 1. setsockopt简介 setsockopt是一个系统调用函数,用于设置套接字选项.套接字是指通信的两个端点之间 ...
- [转帖]IPv6地址解析库,窥探IPv6地址中包含的信息
https://zhuanlan.zhihu.com/p/479028720 大家好,我是明说网络的小明同学. 今天和大家介绍一个IPv6 地址解析库IPv6 address Parser :http ...
- [转帖]013 Linux 搞懂「文件所属者更改及权限的赋予」从未如此简单 (chmod、chgrp、chown)
https://my.oschina.net/u/3113381/blog/5435014 01 一图详解「ls -l」 02 两种符号区分表示文件和目录 -(横线) # 表示非目录文件 d # ...
- JVM启动参数脚本的再学习与研究
JVM启动参数脚本的再学习与研究 摘要 学无止境 前段时间一直再研究JVM参数调优. 但是最近也在想不应该仅研究如何调优. 因为不管怎么设置, 总有猪队友会把环境搞崩. 所以应该想办法在无人值守的情况 ...
- PG数据库异步流复制
PG数据库异步流复制 背景说明 最近想进行一个数据库高可用课题的研究. 因为之前某种原因,这次选择的是PG数据库. 为了简单起见, 暂时采用PG异步流复制的场景. 这次仅是为了测试, 不考虑高可用绿色 ...
- BAdI:INVOICE_UPDATE 导致MM Invoice Doc. Missing
Symptom:发票校验过程中,对应发票号生成,FI凭证也产生,但是对应RBKP,RSEG中无相应的发票. 原先这一问题SAP早给出过解释,参照note:1876234 Cause:在SD MM模块中 ...
- Stable Diffusion WebUI Model 加载个人笔记
参考1:https://www.bilibili.com/read/cv20039815 参考2:https://blog.cmyr.ltd/archives/e740aac.html 服务器:阿里云 ...
- 【解决一个小问题】macbook m2 上交叉编译 gozstd
作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢! cnblogs博客 zhihu Github 公众号:一本正经的瞎扯 已知 zstd 是一个优秀的压缩库,gozstd封装了这个 ...
- [置顶] Gin--Begoo框架快速指南
Gin篇 第一篇: Gin-官方文档 第二篇: Gin-安装,修改启动端口,get/post 请求参数,模型绑定shouldbind,自定义验证器/表单验证 第三篇: Gin-上传文件/返回前端.中间 ...