解题:POI 2014 Ant colony
既然我们只知道最后数量为$k$的蚂蚁会在特殊边上被吃掉,不妨逆着推回去,然后到达每个叶节点的时候就会有一个被吃掉的蚂蚁的区间,然后二分一下就好啦
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=,maxx=1e9;
int ant[N],deg[N],leaf[N];
int p[N],noww[*N],goal[*N];
int n,g,k,t,root,t1,t2,n1,n2,cnt;
long long ans;
void link(int f,int t)
{
noww[++cnt]=p[f];
goal[cnt]=t,p[f]=cnt;
}
void DFS(int nde,int fth,long long l,long long r)
{
if(l>maxx) return ; if(r>maxx) r=maxx;
for(int i=p[nde];i;i=noww[i])
if(goal[i]!=fth)
t=deg[goal[i]]-,DFS(goal[i],nde,l*t,r*t+t-);
if(leaf[nde])
ans+=(upper_bound(ant+,ant++g,r)-lower_bound(ant+,ant++g,l))*k;
}
int main ()
{
scanf("%d%d%d",&n,&g,&k);
for(int i=;i<=g;i++)
scanf("%d",&ant[i]);
sort(ant+,ant++g);
scanf("%d%d",&n1,&n2);
link(n1,n2),link(n2,n1);
deg[n1]++,deg[n2]++;
for(int i=;i<n;i++)
{
scanf("%d%d",&t1,&t2);
link(t1,t2),link(t2,t1);
deg[t1]++,deg[t2]++;
}
for(int i=;i<=n;i++) if(deg[i]==) deg[i]=,leaf[i]=true;
root=n1,DFS(n1,n2,k*(deg[n1]-),k*(deg[n1]-)+deg[n1]-);
root=n2,DFS(n2,n1,k*(deg[n2]-),k*(deg[n2]-)+deg[n2]-);
printf("%lld",ans);
return ;
}
解题:POI 2014 Ant colony的更多相关文章
- bzoj 3872 [ Poi 2014 ] Ant colony —— 二分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3872 从食蚁兽所在的边向叶节点推,会得到一个渐渐放大的取值区间,在叶子节点上二分有几群蚂蚁符 ...
- [BZOJ3872][Poi2014]Ant colony
[BZOJ3872][Poi2014]Ant colony 试题描述 There is an entrance to the ant hill in every chamber with only o ...
- Codeforces 474 F. Ant colony
线段树求某一段的GCD..... F. Ant colony time limit per test 1 second memory limit per test 256 megabytes inpu ...
- Codeforces Round #271 (Div. 2) F. Ant colony 线段树
F. Ant colony time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 【BZOJ3872】Ant colony(二分,动态规划)
[BZOJ3872]Ant colony(二分,动态规划) 题面 又是权限题... Description There is an entrance to the ant hill in every ...
- bzoj 3872: [Poi2014]Ant colony -- 树形dp+二分
3872: [Poi2014]Ant colony Time Limit: 30 Sec Memory Limit: 128 MB Description There is an entranc ...
- 【BZOJ3872】[Poi2014]Ant colony 树形DP+二分
[BZOJ3872][Poi2014]Ant colony Description 给定一棵有n个节点的树.在每个叶子节点,有g群蚂蚁要从外面进来,其中第i群有m[i]只蚂蚁.这些蚂蚁会相继进入树中, ...
- CodeForces 474F Ant colony ST+二分
Ant colony 题解: 因为一个数是合法数,那么询问区间内的其他数都要是这个数的倍数,也就是这个区间内的gcd刚好是这个数. 对于这个区间的gcd来说,不能通过前后缀来算. 所以通过ST表来询问 ...
- Codeforces G. Ant colony
题目描述: F. Ant colonytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputo ...
随机推荐
- Gitlab CI-1.Gitlab部署
参考文档: GitLab Documentation:https://docs.gitlab.com/ce/ Installation and Configuration using omnibus ...
- Linux-C语言标准输入输出
标准 I/O 库(stdio)及其头文件 stdio.h 为底层 I/O 系统调用提供了一个通用的接口.这个库现在已经成为 ANSI 标准 C 的一部分.标准 I/O 库提供了许多复杂的函数用于格式化 ...
- CS224n学习笔记1——深度自然语言处理
一.什么是自然语言处理呢? 自然语言处理是计算机科学家提出的名字,本质上与计算机语言学是同义的,它跨越了计算机学.语言学以及人工智能学科. 自然语言处理是人工智能的一个分支,在计算机研究领域中,也有其 ...
- python之multiprocessing创建进程
python的multiprocessing模块是用来创建多进程的,下面对multiprocessing总结一下使用记录. multiprocessing创建多进程在windows和linux系统下的 ...
- python处理数据pandas视频资料
python强大数据处理工具pandas视频资料:https://pan.baidu.com/s/17VRd1cgFaKi20drfCgZ8Gg
- 移动设备检测类Mobile_Detect.php
移动设备检测类Mobile_Detect.php http://mobiledetect.net/ 分类:PHP 时间:2015年11月28日 Mobile_Detect.php是一个轻量级的开源移动 ...
- YQCB冲刺第二周第二天
今天的任务依然为实现查看消费明细的功能. 遇到的问题为从数据库中分类读取,实现图标的显示. 站立会议为: 任务面板为:
- Java未赋值变量的默认初始值
在 Java 程序中,任何变量都必须经初始化后才能被使用.当一个对象被创建时,实例变量在分配内存空间时按程序员指定的初始化值赋值,否则系统将按下列默认值进行初始化: 数据类型 初始值 byte 0 s ...
- linshi18
#include<iostream> using namespace std; int n,m,k; #define max 100 char mmap[max][max]; int mm ...
- BNUOJ 52305 Around the World 树形dp
题目链接: https://www.bnuoj.com/v3/problem_show.php?pid=52305 Around the World Time Limit: 20000msMemory ...