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 很有意思的一道交互题 做法 我们观察到,每次查询一行,当这一行仅包含一端是返回的答案是奇数 根据这个性质查询每一行每一列,我们大体能知道两端的位 ...
随机推荐
- 【转帖】【奇技淫巧】Linux | 统计网络-netstat
theme: condensed-night-purple 小知识,大挑战!本文正在参与"程序员必备小知识"创作活动. 在构建生产服务器时,我们有的时候需要统计网络接口状况,比如T ...
- [转帖]gdb调试常见命令详细总结(附示例操作)
一.简介 通过gdb调试我们可以监控程序执行的每一个细节,包括变量的值.函数的调用过程.内存中数据.线程的调度等,从而发现隐藏的错误或者低效的代码,程序的调试过程主要有:单步执行,跳入函数,跳出函数, ...
- 【转贴】linux命令总结之seq命令
linux命令总结之seq命令 https://www.cnblogs.com/ginvip/p/6351720.html 功能: seq命令用于产生从某个数到另外一个数之间的所有整数. 语法: 1 ...
- 截止2021年linux发行版
- firewall-cmd 命令简单总结
最近进行相关网络设置, 发现需要总结一下不然总是会忘记. # 1. 开放IP地址访问 firewall-cmd --zone=trusted --add-source=yourip --permane ...
- 【k哥爬虫普法】简历大数据公司被查封,个人隐私是红线!
我国目前并未出台专门针对网络爬虫技术的法律规范,但在司法实践中,相关判决已屡见不鲜,K 哥特设了"K哥爬虫普法"专栏,本栏目通过对真实案例的分析,旨在提高广大爬虫工程师的法律意识, ...
- C#使用命令行打开diskpart修改盘符
参考链接: https://www.cnblogs.com/k98091518/p/6019296.html https://learn.microsoft.com/zh-cn/windows-ser ...
- Python 探索性数据分析工具(PandasGUI,Pandas Profiling,Sweetviz,dtale)以及学术论文快速作图science.mplstyle
如果探索的数据集侧重数据展示,可以选PandasGUI:如果只是简单了解基本统计指标,可以选择Pandas Profiling和Sweetviz:如果需要做深度的数据探索,那就选择dtale. 1. ...
- 【6】VScode 无法在终端输入问题,提示:无法在只读编辑器中编辑
相关文章: [1]VScode中文界面方法-------超简单教程 [2]VScode搭建python和tensorflow环境 [3]VSCode 主题设置推荐,自定义配色方案,修改注释高亮颜色 [ ...
- 辣鸡 mac 下 pycharm 中代码拖拽的问题
Editor –> General Enable Drag'n'Drop functionality in Editor