7.11_SUPER STUPID CROSS

来源:互联网 发布:想的太多读书太少 知乎 编辑:程序博客网 时间:2024/06/15 18:10

这道题目可以对前1000个进行排序,然后找出最大的横边和竖边,从头开始搜索,一旦找到匹配的就停止搜索输出,而一旦搜到尾,还没有找到匹配的,就输出那句话“ Human intelligence is really terrible ”。

#include<iostream>#include<cstdio>#include<algorithm>using namespace std;​int n,an,bn,ans;struct hen{    int x;    int y1,y2;}h[100010];struct shu{    int y;    int x1,x2;}s[100010];​bool cmph(hen a,hen b){    return a.y2-a.y1>b.y2-b.y1;}bool cmps(shu a,shu b){    return a.x2-a.x1>b.x2-b.x1;}​int main(){    cin>>n;    int i,j,k,xx1,yy1,xx2,yy2;    for(i=0;i<n;i++){        scanf("%d%d%d%d",&xx1,&yy1,&xx2,&yy2);        if(xx1==xx2){h[an].x=xx1;h[an].y1=min(yy1,yy2);h[an].y2=max(yy1,yy2);an++;}        else{s[bn].y=yy1;s[bn].x1=min(xx1,xx2);s[bn].x2=max(xx1,xx2);bn++;}}    sort(h,h+an,cmph);sort(s,s+bn,cmps);    for(i=0;i<min(an,1000);i++)        for(j=0;j<min(bn,1000);j++){            if(s[j].x2-s[j].x1<=ans*2||h[i].y2-h[i].y1<=ans*2)continue;            int r=min(min(s[j].x2-h[i].x,h[i].x-s[j].x1),min(h[i].y2-s[j].y,s[j].y-h[i].y1));            if(ans<r)                ans=r;        }    if(ans)        cout<<ans<<endl;    else        cout<<"Human intelligence is really terrible"<<endl;    return 0;}


0 0
原创粉丝点击