hdu 5020(斜率的表示+STL)
Revenge of Collinearity
Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 612 Accepted Submission(s): 207
geometry, collinearity is a property of a set of points, specifically,
the property of lying on a single line. A set of points with this
property is said to be collinear (often misspelled as colinear).
---Wikipedia
Today,
Collinearity takes revenge on you. Given a set of N points in
two-dimensional coordinate system, you have to find how many set of
<Pi, Pj, Pk> from these N points are collinear. Note that <Pi, Pj, Pk> cannot contains same point, and <Pi, Pj, Pk> and <Pi, Pk, Pj> are considered as the same set, i.e. the order in the set doesn’t matter.
Each test case begins with an integer N, following N lines, each line contains two integers Xi and Yi, describing a point.
[Technical Specification]
1. 1 <= T <= 33
2. 3 <= N <= 1 000
3. -1 000 000 000 <= Xi, Yi <= 1 000 000 000, and no two points are identical.
4. The ratio of test cases with N > 100 is less than 25%.
3
1 1
2 2
3 3
4
0 0
1 0
0 1
1 1
0
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
int main()
{
pii a(,);
pii b(,);
printf("%d\n",a==b);
piii c(,make_pair(,));
piii d(,make_pair(,));
printf("%d\n",c==d);
return ;
}
/*1 1*/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
const int N = ;
struct Point{
int x,y;
}p[N];
int cmp(Point a,Point b){
if(a.x==b.x) return a.y<b.y;
return a.x<b.y;
}
int gcd(int a,int b){
return b==?a:gcd(b,a%b);
}
map<pair<int,int>,int> mp;
map<pair<int,int>,int>::iterator it;
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--){
int n;
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d%d",&p[i].x,&p[i].y);
}
int ans = ;
for(int i=;i<=n;i++){
mp.clear();
for(int j=i+;j<=n;j++){
int x = p[j].x - p[i].x;
int y = p[j].y - p[i].y;
int d = gcd(x,y);
x/=d,y/=d;
mp[make_pair(x,y)]++;
}
for(it = mp.begin();it!=mp.end();it++){
if(it->second>=){
int t = it->second;
ans+=t*(t-)/;
}
}
}
printf("%d\n",ans);
}
return ;
}
最新文章
- jQuery 学习之路(4):事件
- Graph | Eulerian path
- .NET Core Runtime IDentifier (RID) catalog
- jquery定义表格宽度
- jxse2.6连接外网rdv一直连接不上,而相同的代码用jxse2.7却能连上
- java strtus2 DynamicMethodInvocation配置入门 "; ! ";访问action里面的方法
- Top 100 English Verbs
- 使用myeclipse新建和删除web项目时一定要小心
- Thrift总结(一)介绍
- sublime text 3 package Install 安装失败解决方法
- 支付-stripe
- Python正则的贪婪和非贪婪示例
- sentinel 控制台接入
- mysql 乱码解决方案
- mysql hive sql 进阶
- PHP双向队列,双端队列代码
- NamedParameterJdbcTemplate常用方法总结
- css圆角和阴影兼容问题(ie7,ie8)
- 38 一次 redis 连接泄露的原因 以及 ShardedJedisPool
- compare `lvs/haproxy/nginx`
热门文章
- kali下将Python2.x切换至Python3.x
- 04vim的使用
- mongodb安装,库操作,集合操作(表),文档操作(记录)
- astyle 使用说明 —— 集成到开发平台中
- day 16 JS DOM 继续
- Django admin模块使用search时报错:django.core.exceptions.FieldError: Related Field got invalid lookup: contains
- ASP.NET下调用ffmpeg与mencoder实现视频转换截屏
- Windows Server 2012 R2:细节信息汇总
- 剖析微软Hyper-V的最佳部署方式
- Python框架之Django学习笔记(十六)