uva live 7635 National Bomb Defusing Squad
题意:
有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的更多相关文章
- SDU暑期集训排位(8)
A. A Giveaway 签到 B. Game of XOR 做法 dp[G][L][R]表示在倒数第G代,左边的数是L,右边的数是R,下面共有多少个0和1 区间和转换成两次前缀和和一次单点查询 利 ...
- [Javascript] Create Objects
var vehicle1 = {type: "Motorboat", capacity: 6, storedAt: "Ammunition Depot"}; v ...
- 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 ...
- 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 ...
- Uva 11183 - Teen Girl Squad (最小树形图)
Problem ITeen Girl Squad Input: Standard Input Output: Standard Output You are part of a group of n ...
- UVA:11183:Teen Girl Squad (有向图的最小生成树)
Teen Girl Squad Description: You are part of a group of n teenage girls armed with cellphones. You h ...
- UVA 11183 Teen Girl Squad 最小树形图
最小树形图模板题 #include <iostream> #include <algorithm> #include <cstdio> #include <c ...
- 【UVA 11183】 Teen Girl Squad (定根MDST)
[题意] 输入三元组(X,Y,C),有向图,定根0,输出MDST. InputThe first line of input gives the number of cases, N (N < ...
- uva 11183 Teen Girl Squad
题意: 有一个女孩,需要打电话让所有的人知道一个消息,消息可以被每一个知道消息的人传递. 打电话的关系是单向的,每一次电话需要一定的花费. 求出打电话最少的花费或者判断不可能让所有人知道消息. 思路: ...
随机推荐
- Julia出现错误ERROR: LoadError: syntax: try without catch or finally
因项目要求进行机器学习数据可视化,要求尝试使用Julia,在此,记录下遇到的坑,仅为记录效果.后续陆续更新. 问题一:关于LightML库中的坑:ERROR: LoadError: syntax: t ...
- Android使用adb抓完整Log
前言 最新项目里一直在做 Android RIL 方面的研究,非常最终项目还是未能解决通信底层模块的问题,但是在使用adb抓log上还是有一些收获的,这里记录一下. Log分类 A ...
- 运用swagger编写api文档
一.什么是swagger 随着互联网技术的发展,前后端技术在各自的道路上越走越远,他们之间的唯一联系变成了api接口,api接口文档编程了前后端人员的纽带,而swagger就是书写api文档的一款框架 ...
- OC(构造函数,分类等知识总结)
文章来源:http://my.oschina.net/luoguankun/blog/219532 一.成员变量的作用域 · @public · 在任何地方都能直接访问对象 ...
- django基础篇06-ModelForm操作及验证
本文内容主要来自银角大王的博客 学习大纲: 一.ModelForm 二.Ajax - 原生(jQuery) - 伪Ajax操作 三.文件上传(预览) - Form提交 - Ajax文件上传 四. 图片 ...
- Java并发(具体实例)——几个例子
一步步优化页面渲染功能 本节将模拟一个简单的页面渲染功能,它的作用是将HTML页面绘 ...
- 仿scikit-learn模式写的kNN算法
一.什么是kNN算法 k邻近是指每个样本都可以用它最接近的k个邻居来代表. 核心思想:如果一个样本在特征空间中的k个最相邻的样本中大多数属于一个某类别,则该样本也属于这个类别. 二.将kNN封装成kN ...
- [易学易懂系列|golang语言|零基础|快速入门|(二)]
现在我们来写代码,首先我们要新建一个项目. 新建项目: 点击:File>>New>>Project...如下图: 在New Project窗口,Location:输入:“goP ...
- windows 10 安装openssh 0x800f0954 的一种解决方法
安装与卸载参考:https://docs.microsoft.com/zh-cn/windows-server/administration/openssh/openssh_install_first ...
- Ansible笔记(2)--配置清单
一.Ansible Inventory配置及详解 Inventory是ansible管理主机信息的配置文件,默认存放在/etc/ansible/hosts.在使用时通过 -i 或 --inventor ...