[ZOJ1426 ][POJ1693] Counting Rectangles
来源:互联网 发布:淘宝直通车关键词 编辑:程序博客网 时间:2024/04/27 20:21
ZOJ: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=426
POJ: http://poj.org/problem?id=1693
题目大意:
给出一些水平和竖直线段,问围城多少矩形。
注意简化条件:
The input line segments are such that each intersection point comes from the intersection of exactly one horizontal segment and one vertical segment.
解题思路:
据说可以暴力,就暴力了……很久没有1AC了……ZOJ交完交POJ交错题了……
源代码:
#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;#define maxn 110 typedef struct line_ver{ int x, y1, y2;}line_var;typedef struct line_hor{ int y, x1, x2;}line_hor;int v,h,n;line_ver linev[maxn];line_hor lineh[maxn];int min(int x, int y){if (x>y) return y; return x;}int max(int x, int y){if (x>y) return x; return y;}void init(){ int x1,y1,x2,y2; scanf("%d", &n); v=h=0; for (int i=0; i<n; i++) { scanf("%d%d%d%d", &x1, &y1, &x2, &y2); if (x1==x2) //vertical { linev[v].x=x1; linev[v].y1=min(y1,y2); linev[v++].y2=max(y1,y2); } else //horizontal { lineh[h].y=y1; lineh[h].x1=min(x1,x2); lineh[h++].x2=max(x1,x2); } }}bool intersect(int vv, int hh){ if (linev[vv].x>=lineh[hh].x1 && linev[vv].x<=lineh[hh].x2) if (lineh[hh].y>=linev[vv].y1 && lineh[hh].y<=linev[vv].y2) return true; return false;}int solve(){ int ret=0; for (int v1=0; v1<v-1; v1++) for (int h1=0; h1<h-1; h1++) if (intersect(v1, h1)) for (int v2=v1+1; v2<v; v2++) if (intersect(v2, h1)) for (int h2=h1+1; h2<h; h2++) if (intersect(v1, h2) && intersect(v2, h2)) ret++; return ret; }int main(){ int cs, ans; scanf("%d", &cs); while (cs--) { init(); ans=solve(); printf("%d\n", ans); }}
- [ZOJ1426 ][POJ1693] Counting Rectangles
- Counting Rectangles
- poj1693
- poj1693
- UVa10502 - Counting Rectangles
- poj 1693 Counting Rectangles
- UVA - 10574 Counting Rectangles
- 10574 - Counting Rectangles
- UVa 10574 - Counting Rectangles
- EularProject 85:Counting rectangles
- uva 10574 - Counting Rectangles(计数)
- CodeForces 372B. Counting Rectangles is Fun
- UVA 10574 - Counting Rectangles(枚举+计数)
- uva 10574 - Counting Rectangles (离散化)
- Project Euler:Problem 85 Counting rectangles
- B. Counting Rectangles is Fun----dp
- Codeforces Round #219 (Div. 2) D. Counting Rectangles is Fun
- CF 372B Counting Rectangles is Fun(记忆化搜索)
- JavaScript开发者必备的10个超级实用工具
- 如何用Java操作注册表
- [转]epoll 经验谈
- 善良,是最不能丢失的品质
- 主流浏览器的判断
- [ZOJ1426 ][POJ1693] Counting Rectangles
- (学习笔记_2011_07_03)__反汇编__一重for循环
- 一个很实用的WEB打印控件“四方在线WEB打印控件——PAZU”
- Java Process类的浅学习
- 纯真年代
- 长成大树,长成灌木
- CPU/Arm920T/cpu.c解读
- SQL Server 2008 R2 各个版本支持的功能
- 胡适:赠与今年毕业的大学生