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
题意: 有一个女孩,需要打电话让所有的人知道一个消息,消息可以被每一个知道消息的人传递. 打电话的关系是单向的,每一次电话需要一定的花费. 求出打电话最少的花费或者判断不可能让所有人知道消息. 思路: ...
随机推荐
- Docker网络大揭秘(单机)
docker网络官网 https://docs.docker.com/network/ Docker容器和服务如此强大的原因之一是您可以将它们连接在一起,或将它们连接到非Docker工作负载.Dock ...
- Redis哨兵功能与集群搭建
6.redis哨兵功能 Redis-Sentinel Redis-Sentinel是redis官方推荐的高可用性解决方案,当用redis作master-slave的高可用时,如果master本身宕机, ...
- kotlin学习(8)泛型
泛型的声明 与Java不同的是,Kotlin要求类型实参要么被显示的说明,要么能被编译器推导出来.因为Java在1.5版本才引入泛型,所以为了兼容过去的版本,可以不直接声明List类型的变量,而不说明 ...
- 输入某年某月某日,判断这一天是这一年的第几天?(可以用 Python 标准 库)
import datetime def dayofyear(): year = input("请输入年份:") month = input("请输入月份:") ...
- Java——自定义外部字体文件
package chapter1; import javax.swing.*;import java.awt.*;import java.io.IOException;import java.io.I ...
- 39. Combination Sum (Java)
Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), fin ...
- ARM Cortex-M底层技术(1)—程序在Flash和SRAM的空间分配
1. keil编译介绍 当使用keil进行单片机的开发时,运行一段程序后,在output输出框会看到如下图的结果. 图1 keil 的output框 其中,Compiler编译器,使用的版本是 V5. ...
- python3-安装第三方模块
在Python中,安装第三方模块,是通过包管理工具pip完成的. 如果你正在使用Mac或Linux,安装pip本身这个步骤就可以跳过了. 如果你正在使用Windows,请参考安装Python一节的内容 ...
- computed 与methods , watched 的区别
computed 与watched 的区别: 异步请求 数据变化 使用watched ,计算属性不支持异步 计算一个值的结果 用 computed computed 与methods的区别: comp ...
- Spring Boot日志处理
2.4 日志处理 2.4.1 记录日志内容 请求url 访问者ip 调用方法classMethod 参数args 返回内容 2.4.2 新建包aspect,新建日志切面处理类 package com. ...