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\) ...
随机推荐
- python flask应用部署
失败版本:flask+uwsgi ini配置文件 [uwsgi] callable = app ;//程序内启用的application变量名 home = /home/jcuan/code/pyth ...
- springMVC图片文件上传功能的实现
在工程依赖库下添加文件上传jar包 commons-fileupload-1.2.2.jar commons-io-2.4.jar 2.jsp页面设置form表单属性enctype 在表单中上传图片时 ...
- ahjesus用forever管理nodejs服务
全局安装forever npm install -g forever 查看帮助 forever -h 查看安装位置 whereis forever 编写自己的sh文件 forever -p web文件 ...
- 【iOS】Quartz2D简单介绍
一.什么是Quartz2D Quartz 2D是⼀个二维绘图引擎,同时支持iOS和Mac系统 Quartz 2D能完成的工作: 绘制图形 : 线条\三角形\矩形\圆\弧等 绘制文字 绘制\生成图片(图 ...
- JavaScript中的null与nudefined
null和undefined 概述 null与undefined都可以表示"没有",含义非常相似.将一个变量赋值为undefined或null,老实说,语法效果几乎没区别. var ...
- ESRI.ArcGIS.esriSystem名称空间问题
在AO或AE开发中,并没有ESRI.ArcGIS.esriSystem这个dll,只有ESRI.ArcGIS.System,凡是需要ESRI.ArcGIS.esriSystem命名空间时,添加ESRI ...
- Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.
改下build.gradle文件,将里面的compileSdkVersion改为23即可 apply plugin: 'com.android.application' android { compi ...
- 高性能JS笔记1——加载执行
一.脚本位置 1.Script标签尽可能放到Body底部,以减少脚本文件下载对整个页面UI渲染的影响. 2.Script标签永远不要紧跟Link标签后面. 二.组织脚本 1.合并多个文件在一个Scri ...
- JSP内置对象--request对象
本文主要介绍JSP中的request对象 request对象的主要方法: setAttribute(String name,Object):设置名字为name的request的参数值 getAttri ...
- UITableView删除添加和移动
#import "RootTableViewController.h" @interface RootTableViewController () @property (nonat ...