Facebook Hacker Cup 2016 Qualification Round第一题
2016-09-14 20:40
218 查看
这个,题意就是,给一个图,让你找,两条线段的端点是一个,并且长度相同,这个为一组,然后就是找,有多少组这样的星系
题解这个就事这么回事,依次找距离,然后排序,排序就是找相同的距离的有cnt个,然后(cnt-1)*cnt就是得数,关键在于想到用排序,我一开始想的是map,但是不行。。。。。
会tle
最近好久没有刷题了,因为数学建模,希望我有一天能有足够的能力来拥抱爱我和我爱的人
题解这个就事这么回事,依次找距离,然后排序,排序就是找相同的距离的有cnt个,然后(cnt-1)*cnt就是得数,关键在于想到用排序,我一开始想的是map,但是不行。。。。。
会tle
最近好久没有刷题了,因为数学建模,希望我有一天能有足够的能力来拥抱爱我和我爱的人
#include<cstdio> #include<algorithm> #include<cstring> #include<cmath> using namespace std; const int MaxN = 2000 + 5; struct node{ int x , y; }a[MaxN]; double dis[MaxN * MaxN]; long long ans = 0; double Dis(int i , int j) { double x = (a[i].x - a[j].x) * (a[i].x - a[j].x); double y = (a[i].y - a[j].y) * (a[i].y - a[j].y); return sqrt(x + y); } int main() { int t , cnt = 1; scanf("%d", &t); while(t--){ ans = 0; int n; scanf("%d",&n); for(int i = 1 ; i <= n ; i++){ scanf("%d %d",&a[i].x , &a[i].y); } for(int i = 1 ; i <= n ; i++){ // printf("*"); int tot = 0; for(int j = 1 ; j <= n ; j++){ if(i != j) dis[++tot] = Dis(i , j); } sort(dis + 1 , dis + tot + 1); int cnt = 0;dis[0] = dis[1] ,dis[tot + 1] = -1;//计算后面的,前面那句是为了把cnt = 1;很巧妙 for(int j = 1 ; j <= tot + 1 ; j++){ if(dis[j] != dis[j - 1]) ans += cnt*(cnt - 1) / 2 , cnt = 1; else cnt++; } } printf("Case #%d: ",cnt++); printf("%lld\n",ans); } } /* 5 3 0 0 0 1 0 3 5 0 0 0 1 0 2 0 3 0 4 4 0 0 0 100 100 0 100 100 4 0 0 -3 4 0 5 -5 0 6 5 6 6 5 7 6 6 7 7 8 8 7 */
相关文章推荐
- Facebook Hacker Cup 2016 Qualification Round High Security
- Facebook Hacker Cup 2016 Round 1 Boomerang Tournament
- Facebook Hacker Cup 2016 Qualification Round Text Editor
- Facebook Hacker Cup 2016 Round 2
- Facebook Hacker Cup 2016 Qualification Round The Price is Correct
- FaceBook Hacker Cup 2016 Qualification - Text Editor (dp)
- Facebook Hacker Cup 2016 Qualification Round 解题报告
- FaceBook Hacker Cup 2016 Qualification - High Security (贪心)
- Facebook Hacker Cup 2016 Round 1 Laundro, Matt
- Facebook Hacker Cup 2015 Round 1 解题报告
- Facebook Hacker Cup 2014 Qualification Round 竞赛试题 Square Detector 解题报告
- Facebook Hacker Cup 2013 Qualification Round 解题报告
- Facebook Hacker Cup 2015 Round 1--Winning at Sports(动态规划)
- [ 2-SAT 线段树 ] Codeforces Gym 100159 Facebook Hacker Cup 2012 I.Unfriending
- Facebook Hacker Cup 2015 Round 1 --- Homework
- Facebook hacker cup qualification round 题解
- Facebook Hacker Cup 2015 Round 1 --- Autocomplete
- Facebook Hacker Cup 2015
- Facebook Hacker Cup 2014 Qualification Round 竞赛试题 Square Detector 解题报告
- Facebook Hacker Cup 2015 Round 1 --- Winning at Sports