UVA7267 Mysterious Antiques in Sackler Museum (强行模拟)

来源:互联网 发布:百视通网络电视直播 编辑:程序博客网 时间:2024/06/05 10:21

the link is here

this question need a lot consideration ,witch five us 4 rectangles and let us to check if there exist three of them that can from a rectangle

because there ‘re only 4 ,we can iter any formation of the four rectangle and see if they can line up in a rectangle or one of them can match line up with other two
this take me really time to finish up so I should do more complicated question to speed up my code speed

#include <iostream>#include<cstdio>#include<cstring>#include<vector>#include<map>using namespace std;struct rec{    int x,y;    int s;}z[5];bool check(int a,int b,int c,int t){    int mx = 0;    for(int i = 0;i<=8;i++)    {        int t1 = (i&1) ? z[a].x : z[a].y;        int y1 = (i&1) ? z[a].y : z[a].x;        int t2 = ((i>>1)&1) ? z[b].x : z[b].y;        int y2 = ((i>>1)&1) ? z[b].y : z[b].x;        int t3 = ((i>>2)&1) ? z[c].x : z[c].y;        int y3 = ((i>>2)&1) ? z[c].y : z[c].x;        //printf("%d %d %d\n",t1,t2,t3);        if(t1 == t2 && t1 == t3)        {            if(mx < (z[a].s + z[b].s + z[c].s))            {                mx = z[a].s + z[b].s + z[c].s;            }            //printf("")        }        if(t1 + t2 == t3 && y1 == y2)        {            if(mx < (z[a].s + z[b].s + z[c].s))            {                mx = z[a].s + z[b].s + z[c].s;            }        }        if(t2 + t3 == t1 && y2 == y3)        {            if(mx < (z[a].s + z[b].s + z[c].s))            {                mx = z[a].s + z[b].s + z[c].s;            }        }        if(t1 + t3 == t2 && y1 == y3)        {            if(mx < (z[a].s + z[b].s + z[c].s))            {                mx = z[a].s + z[b].s + z[c].s;            }        }    }    //printf("%d %d %d %d = %d\n",a,b,c,t,mx);    return mx != 0;}int main(){    int ca;    scanf("%d",&ca);    while(ca--)    {        for(int i = 1;i<=4;i++)        {            scanf("%d%d",&z[i].x,&z[i].y);            z[i].s = z[i].x*z[i].y;        }        if(check(1,2,3,4) || check(1,2,4,3) || check(2,3,4,1) ||check(1,3,4,2))        {            printf("Yes\n");        }        else        {            printf("No\n");        }    }    return 0;}
阅读全文
0 0
原创粉丝点击