山东省第五届ACM省赛题——Painting Cottages(求点集的划分)
来源:互联网 发布:陈自强 知乎 编辑:程序博客网 时间:2024/06/08 00:27
题目描述
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.
可以把问题转化为求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 10000010using 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;}
- 山东省第五届ACM省赛题——Painting Cottages(求点集的划分)
- 山东省第五届ACM省赛题——Full Binary Tree(二叉树应用)
- 山东省第五届ACM省赛题——angry_birds_again_and_again(计算几何)
- 山东省第五届ACM省赛题——Hearthstone II(第二类Stiring数)
- 山东省第五届ACM省赛题——Weighted Median(模拟)
- 山东省第五届ACM省赛题——Colorful Cupcakes(四维dp)
- 山东省第五届ACM省赛题——Circle(递推求概率)
- 山东省第五届ACM省赛题——Devour Magic(线段树区间覆盖+更新)
- 第五届山东省ACM Circle(高斯消元)
- 第五届山东省ACM Factorial
- 山东省第一届ACM省赛题——Balloons(搜索)
- 山东省第七届ACM省赛题——Fibonacci(二分)
- sdut2880---Devour Magic(山东省第五届ACM题)
- 2014年山东省第五届ACM--Factorial (求阶乘)
- 第五届山东省ACM Colorful Cupcakes(Dp)
- 第五届山东省ACM Hearthstone II(Dp)
- Circle(山东省第五届ACM大学生程序设计竞赛 )
- Weighted Median(山东省第五届ACM大学生程序设计竞赛 )
- 医疗APP功能解析一微医
- 最近的两个小项目,2:Python webapp的docker镜像
- 在Linux直接运行安卓程序
- 练习三1001
- 圆形TextView的实现
- 山东省第五届ACM省赛题——Painting Cottages(求点集的划分)
- 啊哈!算法—冒泡排序
- 正则表达式知识详解之贪婪模式和非贪婪模式 (java版示例)
- Spring 实践:AOP
- 解读开源中国oschina App(thanatosx版)引导贴
- 长方柱体类
- 尺寸转换
- Android ListView中 每一项都有不同的布局
- 如何修改数据库的快照隔离级别