题目链接

\(Description\)

在一个\(n*n\)的二维平面中有两个不相交的整点矩形,每次可以询问两个矩形有几个完全在你给出的一个矩形中。200次询问内确定两个矩形坐标。

\(Solution\)

容易想到二分。整个矩形好像不好判断?那就每次二分判断矩形两个点的横纵坐标。次数为 8*26<200。

前四次二分可以确定出一个矩形的位置。然后第二个矩形就可以根据第一个求了。

#include <cstdio>
#include <cctype>
#define gc() getchar() inline int read()
{
int now=0;register char c=gc();
for(;!isdigit(c);c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now;
}
inline int Query(int a,int b,int c,int d)
{
printf("? %d %d %d %d\n",a,b,c,d);
fflush(stdout);
return read();
} int main()
{
int n=read();
int x1,x2,y1,y2,x3,x4,y3,y4;
int l=1, r=n, mid;
while(l<=r){//x2
if(Query(1,1,mid=l+r>>1,n)) x2=mid,r=mid-1;
else l=mid+1;
}
l=1, r=n;
while(l<=r){//y2
if(Query(1,1,x2,mid=l+r>>1)) y2=mid,r=mid-1;
else l=mid+1;
}
l=1, r=x2;
while(l<=r){//x1
if(Query(mid=l+r>>1,1,x2,y2)) x1=mid,l=mid+1;
else r=mid-1;
}
l=1, r=y2;
while(l<=r){//y1
if(Query(x1,mid=l+r>>1,x2,y2)) y1=mid,l=mid+1;
else r=mid-1;
}
l=1, r=n;
while(l<=r){
if(Query(1,1,mid=l+r>>1,n)-(x1>=1&&y1>=1&&x2<=mid&&y2<=n)) x4=mid,r=mid-1;
else l=mid+1;
}
l=1, r=n;
while(l<=r){
if(Query(1,1,x4,mid=l+r>>1)-(x1>=1&&y1>=1&&x2<=x4&&y2<=mid)) y4=mid,r=mid-1;
else l=mid+1;
}
l=1, r=x4;
while(l<=r){
if(Query(mid=l+r>>1,1,x4,y4)-(x1>=mid&&y1>=1&&x2<=x4&&y2<=y4)) x3=mid,l=mid+1;
else r=mid-1;
}
l=1, r=y4;
while(l<=r){
if(Query(x3,mid=l+r>>1,x4,y4)-(x1>=x3&&y1>=mid&&x2<=x4&&y2<=y4)) y3=mid,l=mid+1;
else r=mid-1;
}
printf("! %d %d %d %d %d %d %d %d\n",x1,y1,x2,y2,x3,y3,x4,y4);
fflush(stdout); return 0;
}

Codeforces.714D.Searching Rectangles(交互 二分)的更多相关文章

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

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

  2. Codeforces.1129E.Legendary Tree(交互 二分)

    题目链接 \(Description\) 有一棵\(n\)个点的树.你需要在\(11111\)次询问内确定出这棵树的形态.每次询问你给定两个非空且不相交的点集\(S,T\)和一个点\(u\),交互库会 ...

  3. codeforces 713B B. Searching Rectangles(二分)

    题目链接: B. Searching Rectangles time limit per test 1 second memory limit per test 256 megabytes input ...

  4. Codeforces.862D.Mahmoud and Ehab and the binary string(交互 二分)

    题目链接 \(Description\) 有一个长为\(n\)的二进制串,保证\(01\)都存在.你可以询问不超过\(15\)次,每次询问你给出一个长为\(n\)的二进制串,交互库会返回你的串和目标串 ...

  5. Codeforces.810D.Glad to see you!(交互 二分)

    题目链接 \(Description\) 有一个大小为\(k\)的集合\(S\),元素两两不同且在\([1,n]\)内.你可以询问不超过\(60\)次,每次询问你给出\(x,y\),交互库会返回\(\ ...

  6. Codeforces Round #534 (Div. 2)D. Game with modulo-1104-D(交互+二分+构造)

    D. Game with modulo time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. Glad to see you! CodeForces - 810D (交互+二分)

    This is an interactive problem. In the output section below you will see the information about flush ...

  8. CodeForces 377B---Preparing for the Contest(二分+贪心)

    C - Preparing for the Contest Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d ...

  9. Codeforces 484B Maximum Value(高效+二分)

    题目链接:Codeforces 484B Maximum Value 题目大意:给定一个序列,找到连个数ai和aj,ai%aj尽量大,而且ai≥aj 解题思路:类似于素数筛选法的方式,每次枚举aj,然 ...

随机推荐

  1. Vue学习看这篇就够

    Vue -渐进式JavaScript框架 介绍 vue 中文网 vue github Vue.js 是一套构建用户界面(UI)的渐进式JavaScript框架 库和框架的区别 我们所说的前端框架与库的 ...

  2. [转]计算机视觉之跟踪算法——相关滤波器Correlation Filter

    https://blog.csdn.net/victoriaw/article/details/62416759 ASEF相关滤波器: Average of Synthetic Exact Filte ...

  3. bzoj 4816: 洛谷 P3704: [SDOI2017]数字表格

    洛谷很早以前就写过了,今天交到bzoj发现TLE了. 检查了一下发现自己复杂度是错的. 题目传送门:洛谷P3704. 题意简述: 求 \(\prod_{i=1}^{N}\prod_{j=1}^{M}F ...

  4. mysql -> 备份与恢复_11

    备份恢复原理 逻辑备份 物理备份 备份工具

  5. 33 Introducing the Go Race Detector

    Introducing the Go Race Detector 26 June 2013 Introduction Race conditions are among the most insidi ...

  6. Javascript 跨域访问解决方案 总结

    在客户端编程语言中,如javascript和ActionScript,同源策略是一个很重要的安全理念,它在保证数据的安全性方面有着重要的意义.同 源策略规定跨域之间的脚本是隔离的,一个域的脚本不能访问 ...

  7. 面试经典问题---数据库索引B+、B-树

    具体讲解之前,有一点,再次强调下:B-树,即为B树.因为B树的原英文名称为B-tree,而国内很多人喜欢把B-tree译作B-树,其实,这是个非常不好的直译,很容易让人产生误解.如人们可能会以为B-树 ...

  8. 让你的 JMeter 像 LoadRunner 那样实时查看每秒事务数(TPS)、事务响应时间(TRT)

    熟悉 LoadRunner 的朋友一定不会对其 TPS(每秒事务数).TRT(事务响应时间) 等视图感到陌生,因为这是压力测试最为关键的两个指标.JMeter 以其开源.轻巧.灵活.扩展性高等特性赢得 ...

  9. 在 SQL Server 2005 中配置数据库邮件

    一.            SQL Server发邮件原理和组件介绍: 数据库邮件有4个组件:配置文件.邮件处理组件.可执行文件以及“日志记录和审核组件”. l  配置组件包括: 1)数据库邮件帐户包 ...

  10. python 多线程删除MySQL表

    一.需求分析 在<python 统计MySQL表信息>这篇博客中,链接如下: https://www.cnblogs.com/xiao987334176/p/9901692.html 已经 ...