[关闭]
@Chilling 2017-02-16T10:48:20.000000Z 字数 2935 阅读 897

UVALive-7267: Mysterious Antiques in Sackler Museum


Description

Sackler Museum of Art and Archaeology at Peking University is located on a beautiful site near the West Gate of Peking University campus, and its architecture takes the inspiration from buildings that already exist on campus.

The collection of Chinese art and artifacts currently housed in this new museum contains more than 10, 000 objects and spans a period of 280, 000 years, from Paleolithic hominids and stone tool remains to costumes, ceramics and paintings of the present era. The collection, which is used for teaching and research purposes, has been acquired during the past seventy years from diverse sources.

The use of some objects in the museum remains unknown. For example, there are four pieces of rectangular bones which can be dated back to 200, 000 years ago, and no one knows what they were made for. A former NOIer and present ACMer, Mr. Liang in the School of Archaeology and Museology is very interested in those bones, and his tutor told him to use his wildest imagination to guess the usage of them. So, one day, a crazy idea came up to him: were those bones some kind of IQ test tools used by ancient people? Maybe the one who could pick exactly three pieces of those bones to form a
larger rectangle was considered smart at that time. So Mr. Liang wanted to write a program to find out how to pass this IQ test imagined by him. Can you also do this?

Input

There are several test cases. The first line of input is an integer T (1 ≤ T ≤ 20), indicating the number of test cases. Each test case is in one line and contains 8 integers describing 4 rectangular bones. Each bone is described by 2 integers indicating its width and height.

All integers in the input are between [1, 1000].

Output

For each test case, if Mr. Liang can form a rectangle using those bones in the way he imagined, please print ‘Yes’. If he can’t, print ‘No’ instead. Please note that the area of the new rectangle he forms must be equal to the total area of the bones he picks.

Sample Input

2
1 1 1 1 1 2 2 2
1 1 2 2 10 10 20 20

Sample Output

Yes
No

题意: t组数据,每组8个数,两两一组,是四个矩形的宽和长。问从这四个矩形当中选出3个,是否能拼成一个面积更大的矩形。

分析:三个矩形拼成一个矩形,只有两种拼法,一个是三个排一排,另一个是上面一个下面两个矩形。挨个判断一下。


接下来分享一个很丑的代码

  1. #include<stdio.h>
  2. struct node
  3. {
  4. int w,l;
  5. }a[5];
  6. int zhixian(node x,node y,node z)
  7. {
  8. if((x.w==y.w&&y.w==z.w)||(x.l==y.l&&y.l==z.l)||(x.l==y.w&&y.w==z.l)||(x.l==y.w&&y.w==z.w)||(x.l==y.l&&y.l==z.w)||(x.w==y.l&&y.l==z.l)||(x.w==y.w&&y.w==z.l)||(x.w==y.l&&y.l==z.w))
  9. return 1;
  10. return 0;
  11. }
  12. int syxe(node x,node y,node z)
  13. {
  14. if((y.w+z.l==x.l&&y.l==z.w)||(y.l+z.w==x.l&&y.w==z.l)||(y.w+z.w==x.l&&y.l==z.l)||(y.l+z.l==x.l&&y.w==z.w)||(y.l+z.w==x.w&&y.w==z.l)||(y.w+z.w==x.w&&y.l==z.l)||(y.w+z.l==x.w&&y.l==z.w)||(y.l+z.l==x.w&&y.w==z.w))
  15. return 1;
  16. return 0;
  17. }
  18. int main()
  19. {
  20. int t,flag;
  21. scanf("%d",&t);
  22. while(t--)
  23. {
  24. flag=0;
  25. for(int i=1;i<=4;i++)
  26. scanf("%d%d",&a[i].w,&a[i].l);
  27. if(zhixian(a[1],a[2],a[3])||zhixian(a[1],a[2],a[4])||zhixian(a[1],a[3],a[4])||zhixian(a[2],a[3],a[4]))
  28. flag=1;
  29. if(syxe(a[1],a[2],a[3])||syxe(a[2],a[1],a[3])||syxe(a[3],a[1],a[2]))
  30. flag=1;
  31. if(syxe(a[2],a[3],a[4])||syxe(a[3],a[2],a[4])||syxe(a[4],a[2],a[3]))
  32. flag=1;
  33. if(syxe(a[1],a[2],a[4])||syxe(a[2],a[1],a[4])||syxe(a[4],a[1],a[2]))
  34. flag=1;
  35. if(syxe(a[1],a[3],a[4])||syxe(a[3],a[1],a[4])||syxe(a[4],a[1],a[3]))
  36. flag=1;
  37. if(flag==0)
  38. printf("No\n");
  39. else
  40. printf("Yes\n");
  41. }
  42. return 0;
  43. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注