超级超导对撞机
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; }
相关文章推荐
- 转-cocos2d-x 之 AppDelegate学习
- 滴滴快车奖励政策,高峰奖励,翻倍奖励,按成交率,指派单数分级(12月20日)
- 【Java EE 学习 78 中】【数据采集系统第十天】【Spring远程调用】
- java——常用类的总结
- sklearn 里的分类
- error: unknown field ‘ioctl’ specified in initializer
- 数据结构面试题(1)--用两个队列实现一栈和用两个栈实现一个队列
- 超级大联盟放出超级大空炮!
- lshell限制用户使用命令及其访问目录
- C语言学习笔记-----伊能C语言学习笔记---指针类型和指针所指向的类型不同时
- XRebel使用教程
- HDU——PKU题目分类
- 遗传算法最简单的举例
- Linux gdb调试器用法全面解析
- 116,字符串与路径
- 栈的最小值
- android 自己定义开关(SwitchButton)
- 在Ubuntu GNOME 14.04上安装GNOME 3.12
- online_judge_1116
- 【杭电】[1096]A+B for Input-Output Practice (VIII)