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交互题的更多相关文章

  1. ACM 做题过程中的一些小技巧。

    ACM做题过程中的一些小技巧. 1.一般用C语言节约空间,要用C++库函数或STL时才用C++; cout.cin和printf.scanf最好不要混用. 2.有时候int型不够用,可以用long l ...

  2. ACM 刷题小技巧【转】

    转载自URl-team ACM做题过程中的一些小技巧. 1.一般用C语言节约空间,要用C++库函数或STL时才用C++; cout.cin和printf.scanf最好不要混用. 大数据输入输出时最好 ...

  3. 交互题[CF1103B Game with modulo、CF1019B The hat、CF896B Ithea Plays With Chtholly]

    交互题就是程序与电脑代码的交互. 比如没有主函数的程序,而spj则给你一段主函,就变成了一个整体函数. 还有一种就是程序和spj之间有互动,这个用到fflush(stdout);这个函数就可以实现交互 ...

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

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

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

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

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

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

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

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

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

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

  9. 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 ...

  10. CF1153E Serval and Snake(交互题)

    题目 CF1153E Serval and Snake 很有意思的一道交互题 做法 我们观察到,每次查询一行,当这一行仅包含一端是返回的答案是奇数 根据这个性质查询每一行每一列,我们大体能知道两端的位 ...

随机推荐

  1. [转帖]资料整理——Oracle版本历史(很全面)(Releases and versions of Oracle Database)

    资料来源: https://en.wikipedia.org/wiki/Oracle_Database Oracle Database Version Initial Release Version ...

  2. [转帖]你应该知道的Shell 脚本的经典十三问

    https://blog.csdn.net/wangzhicheng987/article/details/131031344 1. 为何叫做shell? 我们知道计算机的运作不能离开硬件,但使用者却 ...

  3. [转帖]性能测试工具netperf安装使用

    https://blog.51cto.com/dingtongxue1990/1853714 netperf工具使用 一.安装 1,下载 liunx下载地址:ftp://ftp.netperf.org ...

  4. [转帖]tidb 修改root密码

    http://blog.51yip.com/tidb/2452.html   通过 {pd-ip}:{pd-port}/dashboard 登录 TiDB Dashboard,登录用户和口令为 TiD ...

  5. [转帖]查看请求在nginx中消耗的时间

    需求:查看请求在nginx中消耗的时间,不包括程序响应时间. 1.声明日志的格式,在nginx配置文件nginx.conf里的http下添加如下内容: log_format test '$remote ...

  6. 【转帖】16.JVM栈帧内部结构-局部变量表

    目录 1.局部变量表(Local variables) 1.局部变量表(Local variables) 1.局部变量表也称为局部变量数组或本地变量表. 2.局部变量表定义为一个数字数组,主要用于存储 ...

  7. CentOS确认网口是否插入网线的办法

    最近公司的机器存在网络问题, 部分网络总是不通, 比较奇怪. 最近一直想处理好. 第一步: 先查看网口的设备信息 可以使用 ip link show 可以讲网口信息都展示出来. 一般情况下  NO-C ...

  8. FS OFS RS ORS

  9. 记一次 .NET某工控自动化系统 崩溃分析

    一:背景 1. 讲故事 前些天微信上有位朋友找到我,说他的程序偶发崩溃,分析了个把星期也没找到问题,耗费了不少人力物力,让我能不能帮他看一下,给我申请了经费,哈哈,遇到这样的朋友就是爽快,刚好周二晚上 ...

  10. echarts去除坐标轴上的x和y轴

    通过 show:false控制手否显示 <!DOCTYPE html> <html lang="en"> <head> <meta cha ...