题目:

Go Northwest! is a game usually played in the park main hall when occasional rainy weather discourages the visitors from enjoying outdoor attractions.

The game is played by a pair of players and it is based entirely on luck, the players can hardly influence its outcome.

The game plan consists of one large map on the wall with N distinct towns displayed on it. Before the start of the game, the leader of the game hands a bowl filled with N identical balls to each player. Inside each ball, there is a reference to some town on the map. Each bowl contains references to all towns on the map.

When the game starts, one of the players randomly draws one ball from his/her bowl, opens it and reveals the town inside. Next, the other player randomly draws one ball form his/her bowl, opens it and also reveals the town inside.

If both towns are the same, the game ends in a draw. If the towns are not the same, the leader of the game highlights the towns on the map. If one of the towns lies exactly Northwest to the other, the first player wins the game. If one of the towns lies exactly Northeast to the other, the second player wins the game. In all other cases, the game ends in a draw. Two towns are considered to lie exactly Northwest or Northeast from each other, if the angle between the line connecting the towns and the horizontal axis is exactly 45 degrees.

It is clear that the chance of winning the game depends substantially on the layout of the towns on the map. All town coordinates are known in advance. You are asked to find the probability that there is a winner in the game.

Input Specification:

There are more test cases. Each case starts with a line containing one integer N (1 ≤ N ≤ 105 ) specifying the number of towns on the map. Next, there are N lines each of which contains two integers x and y separated by space and specifying the coordinates of one town on the map. The coordinates are standard Cartesian coordinates in the plane. The absolute value of any coordinate does not exceed 109 .

Output Specification:

For each test case, print a single line with one floating point number P denoting the probability that there is a winner in the game. P should be printed with the maximum allowed error of 10-6.

题意:

给出一些点的坐标,两个玩家随机选取两个点(这两个点可以是同一个),如果这两个点的斜率是1或者是-1,则这两个玩家就能分出胜负,否则游戏结束。问给出的点中,所有的选择中有玩家胜出的概率是多少。

思路:

将给出的每一个点,分别以1和-1的斜率做直线与y轴交于两个点,将这两个点的y坐标的大小记录下来。那么遍历这个map容器,答案就是对映射值(k)的k*(k-1)求和,最终结果除以n*n。

PS:

一定要注意数据范围!!!!

代码:

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 2e5+; int main() {
ll n;
while(scanf("%lld",&n)!=EOF) {
map<ll, ll> add;
//map<int, int> sub;
for(ll i = ; i<n; i++){
ll x,y;
scanf("%lld%lld",&x,&y);
add[y+x]++;
add[y-x]++;
}
map<ll, ll>::iterator it;
ll sum = ,temp = n*n;
for(it = add.begin(); it!=add.end(); it++){
sum += it->second*(it->second-);
}
printf("%.6f\n",1.0*sum/temp);
}
return ;
}
/*
PutIn:
4
1 2
2 1
1 1
2 2
3
3 1
2 2
1 3
PutOut:
0.25
0.666667
*/

Gym - 101670H Go Northwest!(CTU Open Contest 2017 思维题+map)的更多相关文章

  1. Gym - 101670A Amusement Anticipation(CTU Open Contest 2017 签到题)

    题目&题意: 倒着找处于最后位置的等差数列的开头的位置. 例: 1 5 3 4 5 6 3 4 5 6是等差数列,它的开头的位置是3 PS: 读题真的很重要!!!!多组输入,上来就读错了!! ...

  2. (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest(爽题)

    layout: post title: (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest(爽题) author: " ...

  3. Gym - 101670H Dark Ride with Monsters(CTU Open Contest 2017 贪心)

    题目: A narrow gauge train drives the visitors through the sequence of chambers in the Dark Ride attra ...

  4. Gym - 101670F Shooting Gallery(CTU Open Contest 2017 区间dp)

    题目&题意:(有点难读...) 给出一个数字序列,找出一个区间,当删除这个区间中的两个相同的数字后,只保留这两个数字之间的序列,然后继续删除相同的数字,问最多可以实行多少次删除操作. 例如: ...

  5. Gym - 101670G Ice cream samples(CTU Open Contest 2017 尺取法)

    题目: To encourage visitors active movement among the attractions, a circular path with ice cream stan ...

  6. Gym - 101670E Forest Picture (CTU Open Contest 2017 模拟)

    题目: https://cn.vjudge.net/problem/1451310/origin 题意&思路: 纯粹模拟. 大体题意是这样的: 1.有人要在一个10-9<=x<=1 ...

  7. Gym - 101670C Chessboard Dancing(CTU Open Contest 2017 找规律)

    题目:链接 思路: 多画出几个情况就可以找出规律来了 Knight (当大于2的时候只要两种颜色相间出现就可以了) King(当大于等于3的时候,总可以用四种形式来补色,具体如下)  Bishop(斜 ...

  8. Gym - 101670B Pond Cascade(CTU Open Contest 2017 贪心,二分)

    题目: The cascade of water slides has been installed in the park recently and it has to be tested. The ...

  9. Gym - 101670J Punching Power(CTU Open Contest 2017 最大独立集)

    题目: The park management finally decided to install some popular boxing machines at various strategic ...

随机推荐

  1. HDU 5979 Convex【计算几何】 (2016ACM/ICPC亚洲区大连站)

    Convex Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  2. Windows10 Win键失灵的解决方法

    之前在Windows10出来的时候在使用过程中发现:按“Win键”调出开始菜单没有用.一点反应都没有.Win+R等这样的组合键也没用. 后来周年更新后,还是无法使用... 各种方法用尽啊.都不行啊! ...

  3. 论如何O(1)快速乘

    然而并没有什么好论的... 直接贴代码算了... ll Mul(ll x,ll y,ll Mod){ x=(x%Mod+Mod)%Mod;y=(y%Mod+Mod)%Mod; return (x*y- ...

  4. css实现左边div固定宽度,右边div自适应撑满剩下的宽度

    (1)使用float <div class="use-float"> <div></div> <div></div> & ...

  5. query或者JavaScript实现在textarea光标处插入文本

    1.Jquery函数实现: $(function() { /* 在textarea处插入文本--Start */ (function($) { $.fn.extend({ insertContent ...

  6. /usr/lib64/python2.6/lib-dynload/pyexpat.so: symbol XML_SetHashSalt, version EXPAT_2_0_1_RH not defined in file libexpat.so.1 with link time reference

    解决方法:[root]$cd /usr/lib64/python2.6/lib-dynload[root]$ln -s /lib64/libexpat.so.1.5.2 libexpat.so.0[r ...

  7. Kafka详解与总结(七)-Kafka producer拦截器(interceptor)

    1. 拦截器原理 Producer拦截器(interceptor)是在Kafka 0.10版本被引入的,主要用于实现clients端的定制化控制逻辑. 对于producer而言,interceptor ...

  8. git 详细部署及其应用

    第1章 版本控制系统 自动生成备份.随时回滚.知道改动的地方. 1.1 svn和git的区别 1.1.1 svn 集中式的版本控制系统,只有一个中央数据仓库,如果中央数据库仓库挂了或者不可访问,所有的 ...

  9. POJ 2773 欧几里得

    思路: 若a和b互素的话,则b*t+a和b一定互素 用周期性做就好了 //By SiriusRen #include <cstdio> using namespace std; ],m,k ...

  10. Android 性能优化(23)*性能工具之「Heap Viewer, Memory Monitor, Allocation Tracker」Memory Profilers

    Memory Profilers In this document Memory Monitor Heap Viewer Allocation Tracker You should also read ...