题目链接

\(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. 【洛谷】【洛谷月赛】4月月赛Round 1/2

    洛谷月赛“月”来“月”丧了,一月更比一月丧,做得我十分不“月”…… 4月的两轮月赛,都只会T1,就写一下吧,等待后续更新…… 先看看Round1的T1: [R1T1] 网址:点我 [题意简述] 给定一 ...

  2. 新手向-同步关键字synchronized对this、class、object、方法的区别

    synchronized的语义 实验 分析 在看源代码时遇到多线程需要同步的时候,总是会看见几种写法,修饰方法.修饰静态方法.synchronized(Xxx.class).synchronized( ...

  3. Flip Bits

    Determine the number of bits required to flip if you want to convert integer n to integer m. Notice ...

  4. ip_local_deliver && ip_local_deliver_finish

    当ip包收上来,查路由,发现是发往本地的数据包时,会调用ip_local_deliver函数: ip_local_deliver中对ip分片进行重组,经过LOCAL_IN钩子点,然后调用ip_loca ...

  5. ASP.NET MVC5 支持PUT 和DELETE

    Web.config <configuration> <system.webServer> <handlers> <remove name="Ext ...

  6. FTRL算法

    稀疏解的作用:内存和时间啊 实际的互联网广告应用需要的是快速地进行model的更新.为了保证快速的更新,训练样本是一条一条地过来的,每来一个样本,model的参数对这个样本进行一次迭代,从而保证了mo ...

  7. Ibatis.Net 各类的作用说明学习(三)

    Ibatis中,加载.分析配置及映射文件是在创建SqlMapper实例的时候进行的,另外对数据库的操作,也是在SqlMapper实例上调用方法来完成.创建SqlMapper的实例的方式是: ISqlM ...

  8. 使用Jsoup解析出html中的img元素

    jsoup 是一款Java 的HTML解析器,可直接解析某个URL地址.HTML文本内容.它提供了一套非常省力的API,可通过DOM,CSS以及类似于jQuery的操作方法来取出和操作数据. 博客项目 ...

  9. Linux学习笔记:mkdir创建文件夹

    文件夹,即目录,在linux中使用mkdir创建. 语法:mkdir dir_name 通过 mkdir 命令可以实现在指定位置创建以 dir_name(指定的文件名)命名的文件夹或目录.要创建文件夹 ...

  10. 利用Requests库写爬虫

    基本Get请求: #-*- coding:utf-8 -*- import requests url = 'http://www.baidu.com' r = requests.get(url) pr ...