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
题意: 有一个女孩,需要打电话让所有的人知道一个消息,消息可以被每一个知道消息的人传递. 打电话的关系是单向的,每一次电话需要一定的花费. 求出打电话最少的花费或者判断不可能让所有人知道消息. 思路: ...
随机推荐
- openstack镜像服务(glance)
1.Use the database access client to connect to the database server as the root user: $ mysql -u root ...
- nginx下载安装和虚拟机的配置
一. Nginx下载安装 1.Nginx下载:nginx-1.13.0.tar.gz,下载到:/usr/local/software/ wget http://nginx.org/download/n ...
- 3.css3中多个背景图片的用法
(background-clip裁剪,background-position位置,background-origin定位,background-repeat是否重复) <!DOCTYPE htm ...
- vue+element ui 时间格式化
<el-table-column prop="startTime" label="日期" width="200" align=&quo ...
- 算法学习之选择排序算法的python实现
——参考自<算法图解> def findSmallest(arr): # 假设第一个元素最小 smallest = arr[0] smallest_index = 0 for i in r ...
- modesim 仿真问题
> unisim (ERROR: Library path "d:/Xilinx/14.3/ISE_DS/ISE//vhdl/mti_se/10.1a/nt64/unisim/unis ...
- 爱奇艺免费vip观看地址
本人qq群也有许多的技术文档,希望可以为你提供一些帮助(非技术的勿加). QQ群: 281442983 (点击链接加入群:http://jq.qq.com/?_wv=1027&k=29Lo ...
- wepy相关
1.根据官方文档: $ npm install @wepy/cli -g # 全局安装 WePY CLI 工具 $ wepy init standard myproj # 使用 standard 模板 ...
- python基本数据类型常用方法
python基本数据类型 1.整型 1.1 int 1.2 bit_lenght # 当前数字的二进制位数,至少用n位表示 r = age.bit_length() >>> a = ...
- MYSQL数据导出与导入,secure_file_priv参数设置
https://www.imooc.com/article/41883 MySQL 报错 [Code: 1290, SQL State: HY000] The MySQL server is run ...