题目链接:

B. Searching Rectangles

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Filya just learned new geometry object — rectangle. He is given a field consisting of n × n unit cells. Rows are numbered from bottom to top with integer from 1 to n. Columns are numbered from left to right with integers from 1 to n. Cell, located at the intersection of the rowr and column c is denoted as (r, c). Filya has painted two rectangles, such that their sides are parallel to coordinate axes and each cell lies fully inside or fully outside each of them. Moreover, no cell lies in both rectangles.

Later, hedgehog Filya became interested in the location of his rectangles but was unable to find the sheet of paper they were painted on. They were taken by Sonya and now she wants to play a little game with Filya. He tells her a query rectangle and she replies with the number of initial rectangles that lie fully inside the given query rectangle. The query rectangle should match the same conditions as initial rectangles. Rectangle lies fully inside the query if each o its cells lies inside the query.

Filya knows Sonya really well, so is sure that if he asks more than 200 questions she will stop to reply.

Input

The first line of the input contains an integer n (2 ≤ n ≤ 216) — size of the field.

For each query an integer between 0 and 2 is returned — the number of initial rectangles that lie fully inside the query rectangle.

Output

To make a query you have to print "? xyxy2" (without quotes) (1 ≤ x1 ≤ x2 ≤ n, 1 ≤ y1 ≤ y2 ≤ n), where (x1, y1) stands for the position of the bottom left cell of the query and (x2, y2) stands for the up right cell of the query. You are allowed to ask no more than 200queries. After each query you should perform "flush" operation and read the answer.

In case you suppose you've already determined the location of two rectangles (or run out of queries) you should print "! x11 y11 x12 y12x21 y21 x22 y22" (without quotes), where first four integers describe the bottom left and up right cells of the first rectangle, and following four describe the corresponding cells of the second rectangle. You can print the rectangles in an arbitrary order. After you have printed the answer, print the end of the line and perform "flush". Your program should terminate immediately after it print the answer.

Interaction

To flush you can use (just after printing an integer and end-of-line):

  • fflush(stdout) in C++;
  • System.out.flush() in Java;
  • stdout.flush() in Python;
  • flush(output) in Pascal;
  • See the documentation for other languages.

You will get the Wrong Answer verdict if you ask more than 200 queries, or if you print an incorrect coordinates.

You will get the Idleness Limit Exceeded verdict if you don't print anything (but you should) or if you forget about flushing the output (more info below).

Hacking.

The first line should contain an integer n (2 ≤ n ≤ 216).

The second line should contain four integers x1, y1, x2, y2 (1 ≤ x1 ≤ x2 ≤ n, 1 ≤ y1 ≤ y2 ≤ n) — the description of the first rectangle.

The third line contains the description of the second rectangle in the similar way.

Example
input
5
2
1
0
1
1
1
0
1
output
? 1 1 5 5
? 1 1 3 3
? 1 1 3 1
? 2 2 2 2
? 3 3 5 5
? 3 3 3 5
? 3 3 3 4
? 3 4 3 5
! 2 2 2 2 3 4 3 5 题意: 给两个矩形区域,然后你进行不超过200次的询问,然后找出这两个区域; 思路: 先找出这两个矩形的分界线,然后再在两个区域内找两个矩形; AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const int mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=(1<<20)+10;
const int maxn=1e6+110;
const double eps=1e-12; int n,ans[20],cnt=0;
inline int out(int x,int y,int fx,int fy)
{
if(x>fx||y>fy)return 0;
printf("? %d %d %d %d\n",x,y,fx,fy);
fflush(stdout);
int num;
cin>>num;
return num;
}
inline void solve(int x,int y,int fx,int fy)
{
int l=x,r=fx,Ans=x;
while(l<=r)
{
int mid=(l+r)>>1;
int f=out(mid,y,fx,fy);
if(f==0)r=mid-1;
else l=mid+1,Ans=mid;
}
ans[++cnt]=Ans;
l=y,r=fy,Ans=y;
while(l<=r)
{
int mid=(l+r)>>1;
int f=out(x,mid,fx,fy);
if(f==0)r=mid-1;
else l=mid+1,Ans=mid;
}
ans[++cnt]=Ans;
l=x,r=fx,Ans=fx;
while(l<=r)
{
int mid=(l+r)>>1;
int f=out(x,y,mid,fy);
if(f==0)l=mid+1;
else r=mid-1,Ans=mid;
}
ans[++cnt]=Ans;
l=y,r=fy,Ans=fy;
while(l<=r)
{
int mid=(l+r)>>1;
int f=out(x,y,fx,mid);
if(f==0)l=mid+1;
else r=mid-1,Ans=mid;
}
ans[++cnt]=Ans;
}
int main()
{
read(n);
int l=1,r=n,flag=0;
while(l<=r)
{
int mid=(l+r)>>1;
int f=out(1,1,n,mid),g=out(1,mid+1,n,n);
if(f&&g)flag=1;
if(f==0)l=mid+1;
else r=mid-1;
}
if(flag)
{
solve(1,1,n,l);
solve(1,l+1,n,n);
}
else
{
l=1,r=n;
while(l<=r)
{
int mid=(l+r)>>1;
int f=out(1,1,mid,n);
if(f==0)l=mid+1;
else r=mid-1;
}
solve(1,1,l,n);
solve(l+1,1,n,n);
}
printf("! ");
for(int i=1;i<=8;i++)printf("%d ",ans[i]);
printf("\n");
return 0;
}

  

codeforces 713B B. 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.714D.Searching Rectangles(交互 二分)

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

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

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

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

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

  5. Codeforces 607A - Chain Reaction - [DP+二分]

    题目链接:https://codeforces.com/problemset/problem/607/A 题意: 有 $n$ 个塔排成一行,第 $i$ 个激光塔的位置为 $a_i$,伤害范围是 $b_ ...

  6. Codeforces 825D Suitable Replacement - 贪心 - 二分答案

    You are given two strings s and t consisting of small Latin letters, string s can also contain '?' c ...

  7. Codeforces 749D. Leaving Auction set+二分

    D. Leaving Auction time limit per test: 2 seconds memory limit per test:256 megabytes input:standard ...

  8. Educational Codeforces Round 60 C 思维 + 二分

    https://codeforces.com/contest/1117/problem/C 题意 在一个二维坐标轴上给你一个起点一个终点(x,y<=1e9),然后给你一串字符串代表每一秒的风向, ...

  9. Codeforces 372 B. Counting Rectangles is Fun

    $ >Codeforces \space 372 B.  Counting Rectangles is Fun<$ 题目大意 : 给出一个 \(n \times m\) 的 \(01\) ...

随机推荐

  1. 模块在insmod之后无法rmmod问题

    1,首先保证make menuconfig选项配置: [*] Enable loadable module support  ---> [*]   Module unloading 2,在lib ...

  2. STL---Codeforces675D Tree Construction(二叉树节点的父亲节点)

    Description During the programming classes Vasya was assigned a difficult problem. However, he doesn ...

  3. java jdk environment variables

    1. create system variable 2. edit the system path note: ;%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin; 3. cre ...

  4. Java中的GOF23(23中设计模式)--------- 工厂模式(Factory)

    Java中的GOF23(23中设计模式)--------- 工厂模式(Factory) 在给大家介绍工厂模式之前,我想和大家聊聊面向对象的那点事,在这里,引入三个概念. 开闭原则(Open Close ...

  5. 我为什么要做富文本编辑器【wangEditor5个月总结】

    请访问wangEditor官网:www.wangEditor.com ----------------------------------------------------------------- ...

  6. SQLSERVER数据库表各种同步技术

    1 --SQLSERVER数据库表各种同步技术 减少SQLServer中每次的同步数据量 2 3 --说到数据库,我就不由地想到同步数据,如何尽可能地减少每次的同步数据量,以此来提高同步效率,降低对网 ...

  7. setTimeout实现动画的黄金优化法则

    1.使用递归思想实现setTimeout的轮询动画:在每一次执行方法的时候都重新的设置一个定时器,然后在指定时间内重新的执行当前的方法 问题:每一次设置的定时器,虽然不执行了,但是还存在呢,浪费性能 ...

  8. VS2012/2013/2015关闭单击文件进行预览的功能

    Visual Studio在2010版本后推出了点击项目管理器预览文件的功能,但是对于配置不咋地的旧电脑总是觉得有点卡,下面是解决方案. 英文版方法:Tools->Options->Env ...

  9. 同源策略 JSONP(实践篇)

    JSONP详解 json相信大家都用的多,jsonp我就一直没有机会用到,但也经常看到,只知道是“用来跨域的”,一直不知道具体是个什么东西.今天总算搞明白了.下面一步步来搞清楚jsonp是个什么玩意. ...

  10. SAP中给当前指定的活动用户发系统信息的函数

    函数名:TH_POPUP 输入集团.当前在线用户.Message即可