noip模拟赛 将军令
分析:对于前18个点可以考虑非常恶心的树形dp,不推荐这种方法.其实贪心还是很显然的.每个小队可以控制距离不超过k里的驿站,肯定要让这个k里不能白白浪费.对于所有叶子节点,如果它还没有被控制,那么肯定要在它的第k级祖先派一个小队.这样能保证控制到它,还能控制到尽可能多的点.这样,将所有点按照深度排序,从深度最深的点里面找没有被控制到的,找到它的第k级祖先,然后dfs暴力覆盖.
Qusetion:为什么不从深度最浅的点找?
每个子节点只有一个祖先,而每个祖先可能会有多个子节点,不知道在哪里派小队最优.
莫名被卡掉了一个点:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std;
const int maxn = ; int n, k, t, head[maxn], to[maxn], nextt[maxn], tot = , dep[maxn], sum, vis[maxn], ans; struct node
{
int id, x;
}e[maxn]; void add(int x, int y)
{
to[tot] = y;
nextt[tot] = head[x];
head[x] = tot++;
} void dfs(int u, int fa, int dist)
{
dep[u] = dist;
for (int i = head[u]; i; i = nextt[i])
{
int v = to[i];
if (v == fa)
continue;
dfs(v, u, dist + );
}
} void color(int x, int depth, int p)
{
if (!vis[x])
sum++;
vis[x] = ;
if (depth == p)
return;
for (int i = head[x]; i; i = nextt[i])
color(to[i], depth + , p);
} bool cmp(node a, node b)
{
return a.x > b.x;
} int main()
{
scanf("%d%d%d", &n, &k, &t);
for (int i = ; i < n; i++)
{
int u, v;
scanf("%d%d", &u, &v);
add(u, v);
add(v, u);
}
dfs(, , );
for (int i = ; i <= n; i++)
e[i].id = i, e[i].x = dep[i];
sort(e + , e + + n, cmp);
for (int i = ; i <= n; i++)
if (!vis[e[i].id])
{
ans++;
int u = e[i].id;
for (int j = ; j <= k; j++)
{
for (int kk = head[u];kk;kk = nextt[kk])
{
int v = to[kk];
if (dep[v] < dep[u])
{
u = v;
break;
}
}
}
color(u, , k + );
}
printf("%d\n", ans); return ;
}
noip模拟赛 将军令的更多相关文章
- 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 ...
随机推荐
- java实现九九乘法表
public class Demo { public static void main(String[] args) { for (int i = 1; i < 10; i++) { ...
- framework7 点取消后还提交表单解决方案
$$('form.ajax-submit').on('submitted', function (e) { var xhr = e.detail.xhr; // actual XHR object v ...
- android开发学习——android studio 引入第三方库的总结
http://www.jianshu.com/p/0c592fff5d89 总结的很溜
- div 弹出 居中
function show_tc_conv(){var x=jq13(window).width()/2;var y=jq13(window).height()/2; var div_w=jq13(& ...
- AJPFX关于面向对象中的对象初始化整理,综合子父类、代码块等等
今天总结了一下子父类当中含有静态代码块.代码块.构造函数.成员变量.子类复写父类方法时子类的初始化过程,把思路理清一下 class Fu { //父类成员变量 private int num = 3; ...
- Android下多彩的StatusView的实现
概述 在上一个博文 Anroid沉浸式状态栏中提到了,画了一个图,这个图简单将我们的状态栏分为不同的2个维度来看状态栏.其中涉及的概念我不在赘诉,请返到Anroid沉浸式状态栏再去认识下这几个概念.本 ...
- VS2010 好用的javascript扩展工具
工具1) JScript Editor Extensions 折叠代码 下载地址: JScript Editor Extensions 工具2) Javascript parser 以树形方式查的代码 ...
- SQLite busy handler
SQLite doesn't support high concurrency. In case of a lot of concurrent access from multi-process or ...
- A Convolution Tree with Deconvolution Branches: Exploiting Geometric Relationships for Single Shot Keypoint Detection
作者:嫩芽33出处:http://www.cnblogs.com/nenya33/p/6817781.html 版权:本文版权归作者和博客园共有 转载:欢迎转载,但未经作者同意,必须保留此段声明:必须 ...
- 浮动qq客服备份代码
<div class="main-im"> <div id="open_im" class="open-im"> & ...