解题: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 ...
随机推荐
- 《how tomcat works》阅读笔记 - 2 - 门面设计模式,避免强制转换
在第二章 2.3节中 try { servlet = (Servlet) myClass.newInstance(); servlet.service((ServletRequest) request ...
- Linux 磁盘与文件系统(EXT2)简介
Linux 中,一切(或几乎一切)都是文件. 一.Linux 磁盘分区与文件系统 1.1 磁盘分区 磁盘的分区主要分为主分区和扩展分区 1)主分区:总共最多只能有四个主分区: 2)扩展分区:只能有一个 ...
- Django FBV/CBV、中间件、GIT使用
s5day82 内容回顾: 1. Http请求本质 Django程序:socket服务端 a. 服务端监听IP和端口 c. 接受请求 \r\n\r\n:请求头和请求体 \r\n & reque ...
- Django之Models与ORM操作
一.models例子 from django.db import models class User(models.Model): """ 用户表 "" ...
- Vue 事件处理
原生的js事件处理 原生的js事件处理,可以分为:直接内联执行代码,或者绑定事件函数. 在内联的事件处理函数内部或者事件绑定的方法内部的作用域中的this都是指向当前的dom对象.如何在vue绑定的元 ...
- 更换 CentOS 7 的下载源为阿里云
http://blog.csdn.net/realghost/article/details/45949759
- hive创建临时函数
add jar /home/hjl/sunwg/Lower.jar; create temporary function my_lower as ‘com.example.hive.udf.Lower ...
- 团队作业 & alpha最终测试报告
本次ALPHA版本测试是依据Daily Scrum11.16(http://www.cnblogs.com/newbe/p/4101339.html)分配的任务有序进行的,从11.16~11.23.为 ...
- 使用python快速搭建web服务器
命令:python -m SimpleHTTPServer 8088 参考:https://www.cnblogs.com/harry-xiaojun/p/6739003.html https://w ...
- DataTime日期格式化
C# DateTime日期格式化 在C#中DateTime是一个包含日期.时间的类型,此类型通过ToString()转换为字符串时,可根据传入给Tostring()的参数转换为多种字符串格式. 目录 ...