noip模拟赛 radius
分析:这道题实在是不好想,一个可以骗分的想法是假定要求的那个点在中心点上,可以骗得不少分.但是在边上的点要怎么确定呢?理论复杂度O(﹢无穷).答案一定是和端点有关的,涉及到最大值最小,考虑二分最大值,关键就是怎么check.如果有一条边x,还有一个点y,把y到x上的点的距离>mid的点给标记上,这样就会形成许多个区间,判断一下x是否被这些区间给完全覆盖住了,如果没有被完全覆盖住,证明这个最大值可以更小.思路非常奇妙,具体实现细节可以参看代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int maxn = , maxm = ; int n, m, a[maxn][maxn], head[maxn], to[maxm],ans,len,top,nextt[maxm],w[maxm], tot = ;
struct node
{
int x, y, z;
}e[]; struct node2
{
int first, second;
}e2[]; void add(int x, int y, int z)
{
w[tot] = z;
to[tot] = y;
nextt[tot] = head[x];
head[x] = tot++;
} void floyd()
{
for (int k = ; k <= n; k++)
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++)
if (a[i][j] > a[i][k] + a[k][j])
a[i][j] = a[i][k] + a[k][j];
} void add2(int x, int y)
{
e2[++top].first = x;
e2[top].second = y;
} bool cmp(node2 a, node2 b)
{
if (a.first == b.first)
return a.second < b.second;
return a.first < b.first;
} bool can()
{
int x = ;
sort(e2 + , e2 + + top,cmp);
for (int i = ; i <= top; i++)
{
if (x < e2[i].first)
return false;
if (x > e2[i].second)
continue;
x = e2[i].second + ;
}
if (x > len)
return true;
return false;
} bool check(int p)
{
bool flag = false;
for (int i = ; i <= m; i++)
{
top = ;
len = e[i].z;
for (int j = ; j <= n; j++)
{
int x = p - a[e[i].x][j];
int y = p - a[e[i].y][j];
if (x < && y < )
{
add2(, e[i].z);
break;
}
if (x >= e[i].z || y >= e[i].z)
continue;
if (x + y >= e[i].z)
continue;
add2(max(, x + ), min(e[i].z, e[i].z - y - ));
}
if (!can())
flag = ;
if (flag)
break;
}
if (flag)
return true;
return false;
} int main()
{
memset(a, / , sizeof(a));
scanf("%d%d", &n, &m);
for (int i = ; i <= m; i++)
{
int u, v, z;
scanf("%d%d%d", &u, &v, &z);
z *= ;
add(u, v, z);
add(v, u, z);
e[i].x = u;
e[i].y = v;
e[i].z = z;
a[u][v] = a[v][u] = min(a[u][v], z);
}
for (int i = ; i <= n; i++)
a[i][i] = ;
floyd();
int l = , r = ;
while (l <= r)
{
int mid = (l + r) >> ;
if (check(mid))
{
ans = mid;
r = mid - ;
}
else
l = mid + ;
}
double temp = ans / 2.0;
printf("%.2lf\n", temp);
return ;
}
noip模拟赛 radius的更多相关文章
- NOIP模拟赛20161022
NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...
- contesthunter暑假NOIP模拟赛第一场题解
contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
- 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程
数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...
- 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
- 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...
- 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...
- CH Round #58 - OrzCC杯noip模拟赛day2
A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...
- CH Round #52 - Thinking Bear #1 (NOIP模拟赛)
A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...
随机推荐
- 洛谷P2516 [HAOI2010]最长公共子序列
题目描述 字符序列的子序列是指从给定字符序列中随意地(不一定连续)去掉若干个字符(可能一个也不去掉)后所形成的字符序列.令给定的字符序列X="x0,x1,-,xm-1",序列Y=& ...
- yistack
- opensStack
- git-更改本地和远程分支的名称
git branch -m old_branch new_branch # Rename branch locally git push origin :old_branch # Delete the ...
- WP处理事件
(1).Launching事件 Launching(进入)事件是每一个第三方应用在第一次运行时都必须执行的事件,它主要负责应用程序的初始化.这个事件与Closing事件是对应的,一个运行正常的应用程序 ...
- [Apple开发者帐户帮助]六、配置应用服务(5.3)推送通知(APN):从您的Web服务器发送推送通知
要使用APN从Web服务器向macOS用户发送推送通知,请注册网站推送标识符并创建网站推送证书. 对于每个网站,请注册一个网站推送标识符,用于验证通知是否来自您的服务器.然后创建一个网站推送证书以签署 ...
- akka设计模式系列-慎用ask
慎用ask应该是Akka设计的一个准则,很多时候我们应该禁用ask.之所以单独把ask拎出来作为一篇博文,主要是akka的初学者往往对ask的使用比较疑惑. "Using ask will ...
- Elasticsearch如何做到亿级数据查询毫秒级返回?
阅读本文大概需要 6 分钟. 如果面试的时候碰到这样一个面试题:ES 在数据量很大的情况下(数十亿级别)如何提高查询效率? 这个问题说白了,就是看你有没有实际用过 ES,因为啥?其实 ES 性能并没有 ...
- hdu2026(water~~)
http://acm.hdu.edu.cn/showproblem.php?pid=2026 #include<iostream> #include<stdio.h> #inc ...
- 在vSphere Client上安装虚拟机工具VMware Tools
一.什么是虚拟机工具 VMware Tools是一套安装在虚拟机操作系统中的实用程序.VMware Tools可提高虚拟机的性能,并在 VMware产品中实现多个易于使用的功能. 尽管客户机操作系统在 ...