hiho1255 Mysterious Antiques in Sackler Museum
题目链接:http://media.hihocoder.com/contests/icpcbeijing2015/problems.pdf
题目大意:给你四个矩形,判断是否能取其中任意三个组成一个大矩形
思路:模拟暴力
1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <iostream> 5 #include <algorithm> 6 using namespace std; 7 struct bones{ 8 int width; 9 int height; 10 bones(int width0=0,int height0=0){ 11 width=width0; 12 height=height0; 13 } 14 }; 15 int maxx; 16 int area; 17 bones a[5]; 18 bones tmp[5]; 19 bones Add(bones a1,bones a2){ 20 if(a1.width==a2.height) return bones(a1.width,a1.height+a2.width); 21 if(a1.width==a2.width) return bones(a1.width,a1.height+a2.height); 22 if(a2.width==a1.height) return bones(a2.width,a2.height+a1.width); 23 if(a2.height==a1.height) return bones(a1.height,a1.width+a2.width); 24 return bones(0,0); 25 26 } 27 bool solve(bones a1,bones a2,bones a3){ 28 bones tmp; 29 tmp=Add(a1,a2); 30 tmp=Add(tmp,a3); 31 if(tmp.width>0) { 32 return true;} 33 tmp=Add(a1,a3); 34 tmp=Add(tmp,a2); 35 if(tmp.width>0) { 36 return true;} 37 tmp=Add(a2,a3); 38 tmp=Add(tmp,a1); 39 if(tmp.width>0) {return true;} 40 return false; 41 } 42 void print(){ 43 if(solve(a[1],a[2],a[3])||solve(a[1],a[2],a[4])||solve(a[1],a[3],a[4])||solve(a[2],a[3],a[4])){ 44 printf("Yes\n"); 45 return ; 46 } 47 printf("No\n"); 48 return ; 49 } 50 int main(){ 51 int T; 52 scanf("%d",&T); 53 while(T--){ 54 for(int i=1;i<=4;i++){ 55 scanf("%d %d",&a[i].width,&a[i].height); 56 } 57 print(); 58 } 59 return 0; 60 }