UVALive 7267 Mysterious Antiques in Sackler Museum (判断长方形)
2017-11-05 20:39
295 查看
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组数据,每组给定4个长方形的宽和高,问是否能从中任取三个构成一个严格的长方形,严格的长方形指的是长方形内部没有空缺。
看了别人的博客才知道函数用的好可以大幅减少代码量QWQ,自己写的时候写了5,6个if就不想写了。
思路:两个长方形相接有四种情况,分别判断就可以了。
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组数据,每组给定4个长方形的宽和高,问是否能从中任取三个构成一个严格的长方形,严格的长方形指的是长方形内部没有空缺。
看了别人的博客才知道函数用的好可以大幅减少代码量QWQ,自己写的时候写了5,6个if就不想写了。
思路:两个长方形相接有四种情况,分别判断就可以了。
#include<stdio.h> #include<string.h> #include<map> #include<iostream> #include<algorithm> using namespace std; int gcd(int a, int b) { return a%b == 0 ? b : gcd(b, a%b); } struct node { int width, lenth; node(int x=0, int y=0) { width = min(x,y); lenth = max(x,y); } }rect[4]; node emerge(node a, node b) { node temp; if (a.lenth == b.lenth)return node(a.lenth, a.width + b.width); if (a.lenth == b.width)return node(a.lenth, a.lenth + b.width); if (a.width==b.lenth)return node(a.lenth, a.lenth + b.width); if (a.width == b.width)return node(a.width, a.lenth + b.lenth); return node(0, 0); } bool juge(node a, node b, node c) { node tmp; tmp = emerge(a, b); tmp = emerge(tmp, c); if (tmp.width > 0)return true; tmp = emerge(a, c); tmp = emerge(tmp, b); if (tmp.width > 0)return true; tmp = emerge(c, b); tmp = emerge(tmp, a); if (tmp.width > 0)return true; } bool sumjuge() { if (juge(rect[0], rect[1], rect[2]))return true; if (juge(rect[0], rect[1], rect[3]))return true; if (juge(rect[3], rect[1], rect[2]))return true; if (juge(rect[0], rect[2], rect[3]))return true; return false; } int main() { int t; cin >> t; while (t--) { for (int i = 0; i < 4; i++) { cin >> rect[i].lenth >> rect[i].width; } if (sumjuge()) { cout << "Yes" << endl; } else { cout << "No" << endl; } } //system("pause"); return 0; }
相关文章推荐
- UVALive 7267 Mysterious Antiques in Sackler Museum (判断长方形)
- UVALive 7267 Mysterious Antiques in Sackler Museum 思维题 拼接矩形
- UVALive - 7267 Mysterious Antiques in Sackler Museum
- 2015北京邀请赛 UVALive7267 Mysterious Antiques in Sackler Museum
- UVALive 7267 Mysterious Antiques in Sackler Museum(dfs)
- UVaLive 7267 Mysterious Antiques in Sackler Museum (if-else,枚举)
- UVA7267 Mysterious Antiques in Sackler Museum (强行模拟)
- 【hihocoder1255 Mysterious Antiques in Sackler Museum】构造 枚举
- 【hihocoder1255 2015北京赛区G】【简单模拟 简化写法超棒哦】 Mysterious Antiques in Sackler Museum 四个矩形选三个 恰好拼成大矩形
- hihoCoder 1255 Mysterious Antiques in Sackler Museum(水)
- Robot Race UVALive - 7020(几何数学 判断钝角)
- uvalive 6600 - Spanning trees in a secure lock pattern
- UVA 11090 Going in Cycle!! SPFA判断负环+二分
- UvaLive 6600 Spanning trees in a secure lock pattern 矩阵行列式
- UVALive 6934 Good morning! 打表判断
- UVALive 6257 Chemist's vows 判断一个字符串是否由n中的某些字符串组成 dp
- UVALive 7267(数学暴力)
- Islands in the Data Stream UVALive - 7092
- UVALive 6092 Catching Shade in Flatland 线段被多个不相交圆截取的长度和
- UVALive - 2728 A Spy in the Metro DP