codeforces 713B B. Searching Rectangles(二分)
题目链接:
1 second
256 megabytes
standard input
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.
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.
To make a query you have to print "? x1 y1 x2 y2" (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.
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.
5
2
1
0
1
1
1
0
1
? 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(二分)的更多相关文章
- Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分
D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...
- Codeforces.714D.Searching Rectangles(交互 二分)
题目链接 \(Description\) 在一个\(n*n\)的二维平面中有两个不相交的整点矩形,每次可以询问两个矩形有几个完全在你给出的一个矩形中.200次询问内确定两个矩形坐标. \(Soluti ...
- CodeForces 377B---Preparing for the Contest(二分+贪心)
C - Preparing for the Contest Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d ...
- Codeforces 484B Maximum Value(高效+二分)
题目链接:Codeforces 484B Maximum Value 题目大意:给定一个序列,找到连个数ai和aj,ai%aj尽量大,而且ai≥aj 解题思路:类似于素数筛选法的方式,每次枚举aj,然 ...
- Codeforces 607A - Chain Reaction - [DP+二分]
题目链接:https://codeforces.com/problemset/problem/607/A 题意: 有 $n$ 个塔排成一行,第 $i$ 个激光塔的位置为 $a_i$,伤害范围是 $b_ ...
- Codeforces 825D Suitable Replacement - 贪心 - 二分答案
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' c ...
- Codeforces 749D. Leaving Auction set+二分
D. Leaving Auction time limit per test: 2 seconds memory limit per test:256 megabytes input:standard ...
- Educational Codeforces Round 60 C 思维 + 二分
https://codeforces.com/contest/1117/problem/C 题意 在一个二维坐标轴上给你一个起点一个终点(x,y<=1e9),然后给你一串字符串代表每一秒的风向, ...
- Codeforces 372 B. Counting Rectangles is Fun
$ >Codeforces \space 372 B. Counting Rectangles is Fun<$ 题目大意 : 给出一个 \(n \times m\) 的 \(01\) ...
随机推荐
- 使scp不用输入密码
使scp不用输入密码 有些时候,我们在复制/移动文件 到另一台机器时会用到scp,因为它比较安全.但如果每次都要输入密码,就比较烦了,尤其是在script里.不过,ssh有另一种用密钥对来验证的方式. ...
- Fresco
1.简介 Fresco是Facebook最新推出的一款用于Android应用中展示图片的强大图片库,可以从网络.本地存储和本地资源中加载图片.相对于ImageLoader,拥有更快的图片下载速度以及可 ...
- asp.net 发送邮件
asp.net 发送邮件 System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); msg.To. ...
- MUI - 图片预览(perviewimage)的优化
主要对mui图片全屏预览插件做了以下三点补充 1.添加了预览图片文字说明,使用的时候需要添加以下css及DOM属性 .mui-slider-img-content { position: absolu ...
- JS写返回上一级
应产品需求,自己的网站上要有返回上一级的需求,几经周折,做个小总结. (1): $("XX").on("click",function(){ wind ...
- C#实现图标批量下载
本文略微有些长,花了好几晚时间编辑修改,若在措辞排版上有问题,请谅解.本文共分为四篇,下面是主要内容,也是软件开发基本流程. 阶段 描述 需求分析 主要描述实现本程序的目的及对需求进行分析,即为什么要 ...
- Android 五大布局
Android 五大布局: FrameLayout(框架布局),LinearLayout (线性布局),AbsoluteLayout(绝对布局),RelativeLayout(相对布局),Table ...
- 读书笔记-Autonomous Intelligent Vehicles(一)
Autonomous intelligent vehicles have to finish the basic procedures: perceiving and modeling environ ...
- 比较好用的web打印控件——Lodop
前一段时间公司一项目比较特殊,客户要求打印单必须是淘宝上卖的那种三联打印单.如果还是使用原来系统自带的打印的话,就会造成无法打印出来理想的效果,于是找了下相关的打印控件,比较网络上比较流行的几款插件, ...
- Android分辨率适配心得
关于Android分辨率适配,这个是Android开发很头疼的一个问题,也需要花费相当一部分开发时间处理的一个问题,往往一个界面怎么适配就得想半天,特别是新手,也经常有人问我是怎么适配分辨率的,我也不 ...