人生第一次交互题ac!

其实比较水

容易发现如果查询的矩阵里面包含一个端点,得到的值是奇数;否则是偶数。

所以只要花2*n次查询每一行和每一列,找出其中查询答案为奇数的行和列,就表示这一行有一个端点。

令cntr表示答案为奇数的行数,cntc表示答案为奇数的列数。

那么cntr只能为0或者2,0就表示两个头在同一行,2就表示两个头在不同的行(我们已经找出这两行了)

cntc亦然。

然后cntr与cntc不可能同时为0,因为两个端点不可能既在同一行又在同一列。

  • 所以对于cntr=cntc=2的,我们知道如下图这四个交点的位置上有两个头,再查询4次就行了。总次数为2*n+4<=2004<2019

  • 对于cntr与cntc某一个为0的,即两个端点在同一行(列)的情况,已经确定了某两列(行),就随便选一列(行)二分答案就行了(集体看代码)。总次数为2*n+ ⌈log n⌉<=2010<2019

CODE

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 100005;
int n, r[2], cntr, c[2], cntc;
inline bool query(int A, int B, int C, int D) {
printf("? %d %d %d %d\n", A, B, C, D);
fflush(stdout); int x; scanf("%d", &x); return x&1;
}
bool flg[2][2];
int main () {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
if(query(i, 1, i, n)) r[cntr++] = i;
if(query(1, i, n, i)) c[cntc++] = i;
}
if(cntr == cntc) {
for(int i = 0; i < 2; ++i)
for(int j = 0; j < 2; ++j)
if(query(r[i], c[j], r[i], c[j]))
flg[i][j] = 1;
putchar('!');
for(int i = 0; i < 2; ++i)
for(int j = 0; j < 2; ++j)
if(flg[i][j] == 1)
printf(" %d %d", r[i], c[j]);
putchar('\n');
fflush(stdout);
return 0;
}
else {
if(!cntr) {
int L = 1, R = n, mid;
while(L < R) {
mid = (L + R) >> 1;
if(query(1, c[0], mid, c[0])) R = mid;
else L = mid + 1;
}
printf("! %d %d %d %d\n", L, c[0], L, c[1]);
fflush(stdout);
}
else {
int L = 1, R = n, mid;
while(L < R) {
mid = (L + R) >> 1;
if(query(r[0], 1, r[0], mid)) R = mid;
else L = mid + 1;
}
printf("! %d %d %d %d\n", r[0], L, r[1], L);
fflush(stdout);
}
return 0;
}
}

Codeforces Round #551 (Div. 2) E. Serval and Snake (交互题)的更多相关文章

  1. Codeforces Round #551 (Div. 2) D. Serval and Rooted Tree (树形dp)

    题目:http://codeforces.com/contest/1153/problem/D 题意:给你一棵树,每个节点有一个操作,0代表取子节点中最小的那个值,1代表取子节点中最大的值,叶子节点的 ...

  2. Codeforces Round #551 (Div. 2)A. Serval and Bus

    A. Serval and Bus time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  3. Codeforces Round #551 (Div. 2)B. Serval and Toy Bricks

    B. Serval and Toy Bricks time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. Codeforces Round #551 (Div. 2) D. Serval and Rooted Tree (树形dp)

    题目链接 题意:给你一个有根树,假设有k个叶子节点,你可以给每个叶子节点编个号,要求编号不重复且在1-k以内.然后根据节点的max,minmax,minmax,min信息更新节点的值,要求根节点的值最 ...

  5. Codeforces Round #551 (Div. 2) F. Serval and Bonus Problem (DP/FFT)

    yyb大佬的博客 这线段期望好神啊... 还有O(nlogn)FFTO(nlogn)FFTO(nlogn)FFT的做法 Freopen大佬的博客 本蒟蒻只会O(n2)O(n^2)O(n2) CODE ...

  6. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

  7. Codeforces Round #534 (Div. 2) D. Game with modulo 交互题

    先二分一个区间,再在区间里面二分即可: 可以仔细想想,想明白很有意思的: #include<iostream> #include<cstdio> #include<alg ...

  8. Codeforces Round #812 (Div. 2) D. Tournament Countdown(交互题)

    记录一下第一次写交互题 题目大意:一共有1<<n个人参加一场竞标赛,需要你通过比较两人的胜场来判断谁晋级,最终获得第一名 最多1/3*2^(n+1)次询问,每次询问query(a,b),如 ...

  9. 【Codeforces】Codeforces Round #551 (Div. 2)

    Codeforces Round #551 (Div. 2) 算是放弃颓废决定好好打比赛好好刷题的开始吧 A. Serval and Bus 处理每个巴士最早到站且大于t的时间 #include &l ...

随机推荐

  1. HTML 5 全局 contenteditable 属性

    contenteditable 可以将标签设置为可输入的input,textarea, 但是在ios上,点击或者点击很久input输入框才出来,兼容ios的方法是加一个   -webkit-user- ...

  2. 一个简单的一个sql表遍历

    简单的一个sql表遍历 一般我们写储存过程或者其他sql语句的时候都会用到循环遍历数据,最常用的两种就是 1.游标 2.临时表+while 下面贴出示例代码 DECLARE @MinReLogID I ...

  3. 谈谈Python中pop与remove的用法

    remove() 函数用于移除列表中某个值的第一个匹配项. remove()方法语法:  list.remove(obj) 如果obj不在列表中会引发 ValueError 错误,通常先使用count ...

  4. zookeeper-waches

    1. 设置watches data watches: getData() exist() child watches: getChildren() 2. 触发watches setData(): da ...

  5. 设置阿里云镜像仓库并安装Docker

    echo "设置阿里云镜像仓库" mkdir /etc/yum.repos.d/bak && mv /etc/yum.repos.d/*.repo /etc/yum ...

  6. 阿里云Centos7 搭建laravel

    最近在考虑学习laravel框架,唔 现在服务器搭建一下. laravel是依赖composer的,首先在linux服务器下先安装composer.运行composer需要 php 5.3以上版本, ...

  7. [转载]Java中继承、装饰者模式和代理模式的区别

    [转载]Java中继承.装饰者模式和代理模式的区别 这是我在学Java Web时穿插学习Java设计模式的笔记 我就不转载原文了,直接指路好了: 装饰者模式和继承的区别: https://blog.c ...

  8. Apache Flink 任意jar包上传漏洞

    目前受影响版本:version 1.9.1(最新),官方未发布补丁. Apache Flink仪表板- >上传恶意的JAR- >提交新工作- >getshell 生成jar包,用nc ...

  9. js之拖拽事件

    js之拖拽事件 api:https://www.runoob.com/jsref/event-ondrag.html 拖拽事件是js原生的事件,使用时在div上添加 draggable="t ...

  10. stm32 按键操作

    抖动时间的长短由按键的机械特性决定,一般为5ms-10ms void key() { static u8 flag = 1; if(flag == 1 && KEY_UP == 1) ...