题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5657

题意:

  有n个人,每一个人都可能携带boom,给出你这些人的位置x, y。 q次询问, 每次给你一个R(爆炸范围),求能炸到多少个人的期望。

题解:

  A到B的距离与B到A的距离相同,我们只需要将每2个人的距离算出来,排序,每给出一个R ,就找小于R 的数量 * 2 , 最后还要加上自己死亡 n 。

  记得case完要空行

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define eps 0.0000000001
#define IOS ios::sync_with_stdio(0);cin.tie(0);
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+;
const int maxn = +;
int x[maxn], y[maxn];
int dis[maxn*maxn];
int n, q, r;
int cul(int i, int j)
{
return (y[j]-y[i])*(y[j]-y[i])+(x[j]-x[i])*(x[j]-x[i]);
}
void solve()
{
int cnt = ;
for(int i = ;i<n;i++) scanf("%d%d", &x[i], &y[i]);
for(int i = ;i+<n;i++){
for(int j = i+;j<n;j++){
dis[cnt++] = cul(i, j);
}
}
sort(dis, dis+cnt);
int ans;
while(q--){
scanf("%d", &r);
int pos = upper_bound(dis, dis+cnt, r*r) - dis;
ans = ;
ans += *pos;
ans += n;
printf("%.2f\n", (double)ans/(double)n);
}
printf("\n");
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
// IOS
while(~scanf("%d%d", &n, &q)&&n+q){
solve();
}
return ;
}

  

uva的评测机很慢,居然不能用二维来算,然后排序, 有点卡常。

uva live 7635 National Bomb Defusing Squad的更多相关文章

  1. SDU暑期集训排位(8)

    A. A Giveaway 签到 B. Game of XOR 做法 dp[G][L][R]表示在倒数第G代,左边的数是L,右边的数是R,下面共有多少个0和1 区间和转换成两次前缀和和一次单点查询 利 ...

  2. [Javascript] Create Objects

    var vehicle1 = {type: "Motorboat", capacity: 6, storedAt: "Ammunition Depot"}; v ...

  3. The 13th Zhejiang Provincial Collegiate Programming Contest - C

    Defuse the Bomb Time Limit: 2 Seconds      Memory Limit: 65536 KB The bomb is about to explode! Plea ...

  4. 2016.4.23浙江省赛(zoj3936 zoj3938 zoj3940 zoj3944 zoj3946 zoj3947 )

    A      Apples and Ideas Time Limit: 2 Seconds      Memory Limit: 65536 KB "If you have an apple ...

  5. Uva 11183 - Teen Girl Squad (最小树形图)

    Problem ITeen Girl Squad Input: Standard Input Output: Standard Output You are part of a group of n  ...

  6. UVA:11183:Teen Girl Squad (有向图的最小生成树)

    Teen Girl Squad Description: You are part of a group of n teenage girls armed with cellphones. You h ...

  7. UVA 11183 Teen Girl Squad 最小树形图

    最小树形图模板题 #include <iostream> #include <algorithm> #include <cstdio> #include <c ...

  8. 【UVA 11183】 Teen Girl Squad (定根MDST)

    [题意] 输入三元组(X,Y,C),有向图,定根0,输出MDST. InputThe first line of input gives the number of cases, N (N < ...

  9. uva 11183 Teen Girl Squad

    题意: 有一个女孩,需要打电话让所有的人知道一个消息,消息可以被每一个知道消息的人传递. 打电话的关系是单向的,每一次电话需要一定的花费. 求出打电话最少的花费或者判断不可能让所有人知道消息. 思路: ...

随机推荐

  1. checkbox的全选、全消的使用

    jquery的选择器的使用 //全选,全消 $("#check_all").click(function () { state = $(this).prop("check ...

  2. 洛谷 - P1522 - 牛的旅行 - Cow Tours - Floyd

    https://www.luogu.org/problem/P1522 好坑啊,居然还有直径不通过新边的数据,还好不是很多. 注意一定要等Floyd跑完之后再去找连通块的直径,不然一定是INF. #i ...

  3. MySQL 的自增 ID 用完了,怎么办?

      一.简述 在 MySQL 中用很多类型的自增 ID,每个自增 ID 都设置了初始值.一般情况下初始值都是从 0 开始,然后按照一定的步长增加.在 MySQL 中只要定义了这个数的字节长度,那么就会 ...

  4. struts2_对Map进行双层迭代

    转自:struts2_对Map进行双层迭代 //后台数据 public String execute() throws Exception { Map<String, List<Produ ...

  5. 锋利的JS解读——认识JQuery(一)

    一.jQuery的发展 随着javascript的不断发展,延伸出了多种JS程序库,当前比较流行的js库有:1)Prototype  成型较早,从整体上对面向对象的编程思想把握的不是很到位. 2)Do ...

  6. 第三次作业—Wordcount

    一.地址 Github项目地址:https://github.com/1320068008/WordCount-1 同伴蒋鑫作业地址:https://www.cnblogs.com/JxsBK/p/1 ...

  7. moc_XXXX.o:(.data.rel.ro._ZTI12CalculatorUI[_ZTI12CalculatorUI]+0x10): undefined reference to `typeinfo for QWidget' collect2: error: ld returned 1 exit status make: *** [Makefile:144: myCalculator]

    main.cpp:(.text.startup+0x22): undefined reference to `QApplication::QApplication(int&, char**, ...

  8. VS2017报错:未提供初始值设定项

    今天在使用VS2017写程序时,报错: 出错的代码如下: #include "pch.h" #include <iostream> #include <threa ...

  9. js赋值后 改变现有数据会修改原来的数据

    看代码: let obj1 = { name: '张三', age: , sex: '男' } let obj2 = obj1 console.log('obj2:', obj2) obj2.age ...

  10. font-awesome样式只显示方框

    这是一个踩过的坑:使用font-awesome中的css样式库时,比如fa-user-circle-o,显示的不是一个用户图标,而是一个方框. 怎么回事呢? 进入css文件,发现: 咦,这些文件呢?我 ...