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 ...
随机推荐
- 洛谷P2744 [USACO5.3]量取牛奶Milk Measuring
题目描述 农夫约翰要量取 Q(1 <= Q <= 20,000)夸脱(夸脱,quarts,容积单位--译者注) 他的最好的牛奶,并把它装入一个大瓶子中卖出.消费者要多少,他就给多少,从不有 ...
- Luogu4198 楼房重建
https://zybuluo.com/ysner/note/1124880 题面 带修改的区间维护最大斜率. 题面 解析 用线段树区间维护斜率. 考虑如何向上合并. 左半段一定有贡献. 如果左半段的 ...
- 数据库异常 :java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
最近在新项目中突然出现了 java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) ...
- php 静态属性和静态变量
- 题解报告:hdu 1846 Brave Game(巴什博弈)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1846 Problem Description 十年前读大学的时候,中国每年都要从国外引进一些电影大片, ...
- Android 签名(5)用命令签名和用android studio,eclipse签名
1,用命令签名 无论用哪个 IDE 开发,最终只是用了 keytool 和 jarsigner 这两个 Java 工具来完成签名任务(在 jdk 的 bin 目录下).其中 keytool 用来生成 ...
- 配置Oracle数据库的开机自启动
每当数据库服务器重启后,都要重新启动数据库的监听和实例,特别是在服务器断电重启.例行维护性的场景下.能否像Windows服务器一样,让实例和监听随着服务的启动而启动呢?答案当然是肯定的,我们可以利用O ...
- scala控制流程语句
直接上代码了哈. package com.test.scala.test object Kongzi { def main(args: Array[String]): Unit = { //if 语句 ...
- 我的github教程
这篇文章记录个人常用的一些命令,和记不住的一些命令. 安装 在 Windows 上安装 Git ,有个叫做 msysGit 的项目提供了安装包: http://msysgit.github.io/ 完 ...
- JSP中如何利用JS实现登录页面的跳转(JSP中如何利用JS实现跳转页面)
<%! <% url = word = } ...