您的位置:首页 > 其它

超级超导对撞机

2015-12-20 11:13 232 查看

超级超导对撞机

时间限制: 1 Sec 内存限制: 64 MB

题目描述

有一个平面直角坐标系,上面有一些线段,保证这些线段至少与一条坐标轴平行。问题:这些线段构成的最大的十字型有多大。

称一个图形为大小为R(R为正整数)的十字型,当且仅当,这个图形具有一个中心点,它存在于某一条线段上,并且由该点向上下左右延伸出的长度为R的线段都被已有的线段覆盖。

你可以假定:没有两条共线的线段具有公共点,没有重合的线段。

输入

第一行,一个正整数N,代表线段的数目。

以下N行,每行四个整数x1,y1,x2,y2(x1=x2或y1=y2),描述了一条线段。

输出

当不存在十字型时:输出一行“Human intelligence is really terrible”(不包括引号)。

否则:输出一行,一个整数,为最大的R。

【样例输入1】

1

0 0 0 1

【样例输入2】

3

-1 0 5 0

0 -1 0 1

2 -2 2 2

【样例输出1】

Human intelligence is really terrible

【样例输出2】

2

【数据规模与约定】

对于50%的数据:N≤1000。

对于100%的数据:1≤N≤100000,所有坐标的范围在-10^9~10^9中。

来源

cf391d2

题解

很容易想到这题可以二分答案,转换为判断型问题。

对于一个二分的答案ans,我们可以把每条线段在左右(上下)两边各减去ans的长度。

枚举其中一种线段,另一种用set维护。

判断是否存在ans1这个答案:只需判断一段区间内是否存在另一种方向的线段。

代码

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
#include<algorithm>
#define N 100010
using namespace std;
int n,l1,l2;
struct node{int x,y,len;}t1
,t2
;
struct wbs{
int type,tp,x,y;
bool operator<(const wbs &cyc)const{
if(tp!=cyc.tp)return tp<cyc.tp;
return type*y>cyc.type*cyc.y;
}
}t[N*2];
multiset<int>q;

bool pd(int x)
{
int tot=0;
for(int i=1;i<=l1;i++)
if(t1[i].len>=2*x)
t[++tot]=(wbs){0,t1[i].x,t1[i].y+x,t1[i].y+t1[i].len-x};
for(int i=1;i<=l2;i++)
if(t2[i].len>=2*x)
{
t[++tot]=(wbs){1,t2[i].x+x,t2[i].y,1};
t[++tot]=(wbs){1,t2[i].x+t2[i].len-x,t2[i].y,-1};
}
sort(t+1,t+tot+1);q.clear();
for(int i=1;i<=tot;i++)
{
if(t[i].type)
{
if(t[i].y==1)q.insert(t[i].x);
else q.erase(q.find(t[i].x));
}
else
if(q.lower_bound(t[i].x)!=q.upper_bound(t[i].y))return true;
}
return false;
}

int main()
{
int x1,y1,x2,y2;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x1==x2)
{
if(y1>y2)swap(y1,y2);
t1[++l1]=(node){x1,y1,y2-y1};
}
else
{
if(x1>x2)swap(x1,x2);
t2[++l2]=(node){x1,y1,x2-x1};
}
}
if(!pd(1)){printf("Human intelligence is really terrible\n");return 0;}
int l=1,r=1000000000;
while(r-l>1)
{
int mid=l+r>>1;
if(pd(mid))l=mid;
else r=mid-1;
}
if(pd(r))printf("%d\n",r);
else printf("%d\n",l);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: