sdut 2884 Painting Cottages 计算几何
2016-05-24 14:25
639 查看
Painting Cottages
Time Limit: 2000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
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 decidewhich 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://www.sdutacm.org/image/2884.png)
来源
2014年山东省第五届ACM大学生程序设计竞赛
示例程序
提交
状态
讨论
给你一个点集求能分割成几种不同的2个空间
可以转化为求点集能有几条直线
利用3点共线的思想 通过gcd来确定 一条直线最小两个点
ACcode:
#include <cstdio> #include <map> #define maxn 1005 using namespace std; inline int gcd(int a,int b){return b==0?a:gcd(b,a%b);} struct Point{ int x,y; Point(){} inline Point(int _x,int _y){ x=_x; y=_y; } inline double lenx(const Point &b)const{ return x-b.x; } inline double leny(const Point &b)const{ return y-b.y; } }P[maxn]; int main(){ int n; while(~scanf("%d",&n)){ for(int i=1;i<=n;++i){ int x,y; scanf("%d%d",&x,&y); P[i]=Point(x,y); } int ans=0; for(int i=1;i<=n;++i){ map<pair<int ,int>,int> dp; for(int j=i+1;j<=n;++j){ int x=P[i].lenx(P[j]); int y=P[i].leny(P[j]); int z=gcd(x,y); if(!dp[make_pair(x/z,y/z)])dp[make_pair(x/z,y/z)]=++ans; } } printf("%d\n",ans<<1); } return 0; }
相关文章推荐
- AEAI ESB路由转换机制说明
- .Net 4.5 的async 和await 的简单理解使用
- AEAI ESB路由转换机制说明
- rails devise使用
- hdu1151Air Raid(最小路径)
- 磁盘分区与格式化挂载,创建逻辑卷与raid组建和快照。
- 算法杂货铺——分类算法之朴素贝叶斯分类(Naive Bayesian classification)
- 【论文笔记】Deep Structured Output Learning for Unconstrained Text Recognition
- AIX slibclean
- Odoo 中group domain的优化应用
- Facebook查找RetainCycle开源库的分析
- Kairosdb集群的搭建
- 转载出去:http://blog.csdn.net/han_xiaoyang/article/details/11969497
- HDU 2686 Matrix||HDU 3376 Matrix Again (拆点费用流)
- HDU 1023 Train Problem II (卡特兰数)
- Light OJ 1296 - Again Stone Game (博弈sg函数递推)
- AIX5.3扩容文件系统时报0516-404
- The Chain Of Responsibility (1)
- The Chain Of Responsibility (1)
- http://zhidao.baidu.com/link?url=3tJ_i5gyYLrd7rFPk0eRYre_oxjCZvTOMOutp89LGhUgi6Ic6Ncama_GMAHnwfF73SVYGqy364vDfv6AY4ERPa