山东省第五届ACM省赛题——Painting Cottages(求点集的划分)
2016-04-27 12:57
417 查看
题目描述
The new cottage settlement is organized near the capital of Flatland. The construction company that is building the settlement has decided to paint some cottages pink and others — light blue. However, they cannot decide which cottages must be painted which color. The director of the company claims that the painting is nice if there is at least one pink cottage, at least one light blue cottage, and it is possible to draw a straight line in such a way that pink cottages are at one side of the line, and light blue cottages are at the other side of the line (and no cottage is on the line itself). The main architect objects that there are several possible nice paintings. Help them to find out how many different nice paintings are there.
输入
The first line of the input file contains n — the number of the cottages (1 ≤ n ≤ 300). The following n lines contain the coordinates of the cottages — each line contains two integer numbers xi and yi (−10^4 ≤ xi, yi ≤ 10^4).
输出
Output one integer number — the number of different nice paintings of the cottages.
示例输入
4
0 0
1 0
1 1
0 1
示例输出
12
提示
Sample.
![](http://acm.sdut.edu.cn/image/2884.png)
可以把问题转化为求N个点可以组成多少不同的线段
The new cottage settlement is organized near the capital of Flatland. The construction company that is building the settlement has decided to paint some cottages pink and others — light blue. However, they cannot decide which cottages must be painted which color. The director of the company claims that the painting is nice if there is at least one pink cottage, at least one light blue cottage, and it is possible to draw a straight line in such a way that pink cottages are at one side of the line, and light blue cottages are at the other side of the line (and no cottage is on the line itself). The main architect objects that there are several possible nice paintings. Help them to find out how many different nice paintings are there.
输入
The first line of the input file contains n — the number of the cottages (1 ≤ n ≤ 300). The following n lines contain the coordinates of the cottages — each line contains two integer numbers xi and yi (−10^4 ≤ xi, yi ≤ 10^4).
输出
Output one integer number — the number of different nice paintings of the cottages.
示例输入
4
0 0
1 0
1 1
0 1
示例输出
12
提示
Sample.
![](http://acm.sdut.edu.cn/image/2884.png)
可以把问题转化为求N个点可以组成多少不同的线段
#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algorithm> #include <set> #include <queue> #include <stack> #include <map> #include <bitset> #define MAXN 10000010 using namespace std; struct Node { double x,y; }; Node a[305]; map<pair<int,int>,int> H; int gcd(int a,int b) { if(b==0) return a; else return gcd(b,a%b); } int main() { int n,cnt=0; while(~scanf("%d",&n)) { cnt=0; for(int i=0; i<n; ++i) scanf("%lf%lf",&a[i].x,&a[i].y); for(int i=0; i<n; ++i) { H.clear(); for(int j=i+1; j<n; ++j) { int aa=a[i].x-a[j].x; int bb=a[i].y-a[j].y; int cc=gcd(aa,bb); //如果有三个点可以组成一条线段,可以用gcd+关联筛选 if(H[make_pair(aa/cc,bb/cc)]==0) { cnt++; H[make_pair(aa/cc,bb/cc)]=1; } } } printf("%d\n",cnt*2); } return 0; }
相关文章推荐
- CGRectContainsPoint的具体用法解释
- 理解 %IOWAIT (%WIO)
- TIME_WAIT和CLOSE_WAIT状态区别
- You have new mail in /var/spool/mail/root
- leetcode 11. Container With Most Water
- fn contains 包含字符串 三种方法判断
- Troubleshooting 'library cache: mutex X' waits. (文档 ID 1357946.1)
- 习近平主席关心人工智能事业的发展
- WAITEVENT: "library cache: mutex X" (文档 ID 727400.1)
- RAID的介绍和RAID的安装
- HDU 1302 The Snail(模拟题)
- 最新型的TurboMail智慧邮件服务器平台
- 先搜集下关于行动列表和行为树的AI制作
- 10252_Common_permutaion
- 关于服务器raid的一个记录
- 关于服务器raid的一个记录
- LeetCode *** 220. Contains Duplicate III (set::lower_bound)
- 11. Container With Most Water
- int main(int argc,char* argv[])参数简介
- Shell 括号辨识(转http://blog.csdn.net/taiyang1987912/article/details/39551385)