poj 1693 模拟
来源:互联网 发布:spycall在淘宝怎么买 编辑:程序博客网 时间:2024/05/01 23:38
Counting Rectangles
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 1072 Accepted: 557
Description
We are given a figure consisting of only horizontal and vertical line segments. Our goal is to count the number of all different rectangles formed by these segments. As an example, the number of rectangles in the Figures 1 and 2 are 5 and 0 respectively.
There are many intersection points in the figure. An intersection point is a point shared by at least two segments. The input line segments are such that each intersection point comes from the intersection of exactly one horizontal segment and one vertical segment.
There are many intersection points in the figure. An intersection point is a point shared by at least two segments. The input line segments are such that each intersection point comes from the intersection of exactly one horizontal segment and one vertical segment.
Input
The first line of the input contains a single number M, which is the number of test cases in the file (1 <= M <= 10), and the rest of the file consists of the data of the test cases. Each test case begins with a line containing s (1 <= s <= 100), the number of line segments in the figure. It follows by s lines, each containing x and y coordinates of two end points of a segment respectively. The coordinates are integers in the range of 0 to 1000.
Output
The output for each test case is the number of all different rectangles in the figure described by the test case. The output for each test case must be written on a separate line.
Sample Input
260 0 0 200 10 25 1020 10 20 200 0 10 010 0 10 200 20 20 2035 0 5 2015 5 15 250 10 25 10
Sample Output
50
题意:就是给出一些平行于坐标的线,求围成的矩形
题解:就是随机抽取纵线,然后用横线去截取,可以自己用草稿纸推出公式temp*(temp-1)/ 2
注意上叙随机二字就好了
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct X{ int x; int y1,y2;}vert[105];int num1;struct Y{ int y; int x1,x2;}horiz[105];int num2;int main(){ int m,n; int t1_x,t2_x,t1_y,t2_y; scanf("%d",&m); while(m--) { scanf("%d",&n); num1=num2=0; while(n--){ scanf("%d%d%d%d",&t1_x,&t1_y,&t2_x,&t2_y); if(t1_x==t2_x){ vert[num1].x=t1_x; vert[num1].y1=min(t1_y,t2_y); vert[num1++].y2=max(t1_y,t2_y); } else{ horiz[num2].y=t1_y; horiz[num2].x1=min(t1_x,t2_x); horiz[num2++].x2=max(t1_x,t2_x); } } int ans=0,temp; for(int i=0;i<num1-1;i++){ for(int j=i+1;j<num1;j++){ temp=0; if((vert[i].y1>vert[j].y2)||(vert[i].y2<vert[j].y1)) continue; int max_y=min(vert[i].y2,vert[j].y2); int min_y=max(vert[i].y1,vert[j].y1); int min_x=min(vert[i].x,vert[j].x); int max_x=max(vert[i].x,vert[j].x); for(int k=0;k<num2;k++){ if(horiz[k].y<=max_y&&horiz[k].y>=min_y) if(horiz[k].x1<=min_x&&horiz[k].x2>=max_x) temp++; } ans+=temp*(temp-1)/2; } } printf("%d\n",ans); } return 0;}
0 0
- poj 1693 模拟
- POJ 1017 模拟啊模拟
- POJ 1565 水 模拟
- Poj 模拟题
- POJ 1068 括号模拟
- POJ 2453 简单模拟
- POJ 2833 简单模拟
- POJ 1016 模拟题
- 模拟退火 poj 1379
- poj 1379 模拟退火
- poj 3285 模拟退火,
- POJ 1068 Parencodings 模拟
- POJ 3295 Tautology 模拟
- POJ 1099 模拟
- poj 3427 模拟
- poj 2612 扫雷 模拟
- POJ 1250 模拟题
- poj 2632 模拟
- ACM HDU 1061 Rightmost Digit
- java基础总结_03
- cesiumjs开发实践 (一)
- 搭建Dubbo+Zookeeper
- drawable文件夹详解
- poj 1693 模拟
- 面试题41:和为s的两个数字VS和为s的连续正数序列
- JSON
- 【杭电-oj】-1002-A + B Problem II(大数相加)
- 本地通知 UILocalNotification
- 移植apache-1.3.39到arm平台
- git不区分大小写
- 二维码的生成 lizbqrencode遇到的问题
- 【链表】C++链表反转、链表逆序打印