hdu 5258 数长方形-2015年百度之星程序设计大赛 - 复赛
2016-04-30 10:35
274 查看
数长方形
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 172 Accepted Submission(s): 99
Problem Description
小度熊喜欢玩木棒。一天他在玩木棒的时候,发现一些木棒会形成长方形。小度熊可能是处女座吧,他只会将木棒横竖摆放,这样会形成很多长方形。现在给你一些横竖摆放的木棒,请你帮小度熊数一数形成了多少个长方形。
为了简化题目,一个木棒的端点不会在另一个木棒上,也就是说,木棒的端点不会在长方形上。
Input
第一行一个整数T,表示T组数据,不超过100组。
每组数据中,第一行是n,代表有多少个木棒,n不会超过25。接下来n行,每行4个整数x1,y1,x2,y2,代表木棒的坐标,绝对值不超过1000。
所有的木棒都是横竖摆放的,也就是说x1=x2或者y1=y2,没有长为0的木棒。
Output
对于每组测试数据,先输出一行
Case #i:
然后输出一个整数,代表有多少个长方形。
Sample Input
2 4 3 0 3 3 4 0 4 3 2 1 5 1 2 2 5 2 4 3 0 3 3 4 0 4 3 2 1 5 1 2 2 -5 2
Sample Output
Case #1: 1 Case #2: 0
Source
2015年百度之星程序设计大赛
- 复赛
思路:
这题没啥好说的,数据量这么小,暴力判断就行了。PS,最好分一下组,然后排个序,逻辑上会更清晰一些!
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <set> #include <queue> #include <vector> using namespace std; #define max(x, y) ((x) > (y) ? (x) : (y)) #define min(x, y) ((x) < (y) ? (x) : (y)) struct Stick { int x1, y1; int x2, y2; Stick(int a, int b, int c, int d) { x1 = a, y1 = b, x2 = c, y2 = d; if (x1 > x2) { swap(x1, x2); swap(y1, y2); } else if (y1 > y2) { swap(x1, x2); swap(y1, y2); } } bool operator < (Stick &obj) { if (x1 == x2) { // 竖着的 return x1 < obj.x1; } else if (y1 == y2) { // 横着的 return y1 < obj.y1; } return false; } }; int n; vector<Stick> vecHor; vector<Stick> vecVer; void Solve() { int ans = 0; sort(vecHor.begin(), vecHor.end()); sort(vecVer.begin(), vecVer.end()); for (int i = 0; i < vecHor.size(); ++i) { for (int j = i + 1; j < vecHor.size(); ++j) { if (vecHor[i].y1 == vecHor[j].y1) { continue; } for (int x = 0; x < vecVer.size(); ++x) { for (int y = x + 1; y < vecVer.size(); ++y) { if (vecVer[x].x1 == vecVer[y].x1) { continue; } if (max(vecHor[i].x1, vecHor[j].x1) <= vecVer[x].x1 && vecVer[y].x1 <= min(vecHor[i].x2, vecHor[j].x2) && max(vecVer[x].y1, vecVer[y].y1) <= vecHor[i].y1 && vecHor[j].y1 <= min(vecVer[x].y2, vecVer[y].y2)) { ++ans; } } } } } printf("%d\n", ans); } int main() { //freopen("input.txt", "r", stdin); int times; scanf("%d", ×); for (int i = 1; i <= times; ++i) { vecHor.clear(); vecVer.clear(); scanf("%d", &n); int x1, y1, x2, y2; for (int j = 0; j < n; ++j) { scanf("%d %d %d %d", &x1, &y1, &x2, &y2); Stick stick(x1, y1, x2, y2); if (y1 == y2) { vecHor.push_back(stick); } else if (x1 == x2) { vecVer.push_back(stick); } } printf("Case #%d:\n", i); Solve(); } return 0; }
相关文章推荐
- redis windows下的环境搭建
- DotNet 资源大全
- 《鸟哥的Linux私房菜》第一章练习题
- sphinx 总结命令
- 二叉树节点间的最大距离
- IO学习(四)文件读取与写出
- C3P0连接池连接MySQL出现的问题
- [drp 3]读取Xml配置文件,连接数据库
- [drp 3]读取Xml配置文件,连接数据库
- XMG系列第一天代理解耦
- iOS程序猿之AFNetworking 3.0 版本使用
- 关于WindowManager
- 欧拉角总结
- 十、森林与并查集---(3)并查集的查询
- wordpress不用插件添加代码块
- pattern与matcherr
- iphone数据存储之-- Core Data的使用(二)
- SQLiteOpenHelper 中什么时候调用 onCreate() , 什么时候调用 onUpgrade() ?
- iphone数据存储之-- Core Data的使用(一)
- tcp 状态以及三次握手