[Poi2011]Dynamite

本文介绍了一个关于在特定结构的洞穴中,通过点燃指定数量的点来引爆所有炸药的问题。文章提供了一种解决方法,采用二分查找结合贪心策略来确定最短引爆时间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[Poi2011]Dynamite

时间限制: 3 Sec  内存限制: 128 MB

题目描述

The Byteotian Cave is composed of  n chambers and n-1 corridors that connect them. For every pair of chambers there is unique way to move from one of them to another without leaving the cave. Dynamite charges are set up in certain chambers. A fuse is laid along every corridor. In every chamber the fuses from the adjacent corridors meet at one point, and are further connected to the dynamite charge if there is one in the chamber. It takes exactly one unit of time for the fuse between two neighbouring chambers to burn, and the dynamite charge explodes in the instant that fire reaches the chamber it is inside.
We would like to light the fuses in some m chambers (at the joints of fuses) in such a way that all the dynamite charges explode in the shortest time possible since the fuses are lit. Write a program that will determine the minimum such time possible.
 
Byteotian Cave的结构是一棵N个节点的树,其中某些点上面已经安置了Bomb,现在需要点燃M个点上的引线引爆所有的Bomb。
某个点上的引线被点燃后的1单位时间内,在树上和它相邻的点的引线会被点燃。如果一个有Bomb的点的引信被点燃,那么这个点上的Bomb会爆炸。
求引爆所有Bomb的最短时间。

输入:
第一行是两个整数N,M。(1<=m<=n<=300000)
接下来一行有N个整数Di,第I个数为1表示该点有Bomb。
接下来N-1行每行有两个数A,B,表示A和B之间有一条边。
输出:
最短时间。
样例解释: 
点燃3,5上的引线。 

输入

The first line of the standard input holds two integers n and m (1<=M<=N<=300000)
, separated by a single space, that denote, respectively, the number of chambers in the cave and the number of chambers in which fire can be set to the fuses. The chambers are numbered from 1 to n . The next line contains  n integers d1,d2…dn (Di属于{0,1}, separated by single spaces. If Di=1 , then there is dynamite in the -th chamber, and if di=0 , there is none. The following n -1 lines specify the corridors of the cave. Each of them holds two integers a,b (a<=a<b<=n), separated by a single space, denoting that there is a corridor connecting the chambers a and b . Every corridor appears exactly once in the description.
You may assume that in tests worth 10% of the points it holds additionally that n<= 10, while in tests worth 40% of the points it holds that N<=1000.

输出

The first and only line of the standard output should hold a single integer, equal to the minimum time it takes from lighting the fuses to the explosion of all the charges.

样例输入

7 2
1 0 1 1 0 1 1
1 3
2 3
3 4
4 5
5 6
5 7

样例输出

1

Solution:
     一开始觉得落谷模拟赛一个题很像,直接打了个暴力发现只有40,一看发现数据范围不对QAQ,二分一下答案然后贪心就好,需要
放就放,如果数量超过m说明不可行。
  
 1 #pragma GCC optimize("O3")
 2 #include <iostream>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <cstdio>
 6 using namespace std;
 7 #define N 300005
 8 int read() {
 9     int s=0,f=1;
10     char ch=getchar();
11     for( ; ch<'0'||ch>'9'; f=(ch=='-')?-1:f,ch=getchar()) ;
12     for( ; ch>='0'&&ch<='9'; s=s*10+(ch^48),ch=getchar()) ;
13     return s*f;
14 }
15 int n,m,tot,r[N],deep[N],Bomb[N],L,R,Ans,son[N],num;
16 struct EDGE{int to,next;} c[N<<1];
17 void add(int x,int y) {
18     c[++tot]=(EDGE){y,r[x]};
19     r[x]=tot;
20 }
21 int Judge[N],f[N];
22 //可以再往上传的长度 需要被炸得最长长度 
23 void DFS(int u,int fa,int now) {
24     int mx1=-0x5f5f5f5f,mx2=-0x5f5f5f5f;
25     if(Bomb[u]) mx1=0;
26     for(int i=r[u]; ~i; i=c[i].next) {
27         if(c[i].to!=fa) {
28             DFS(c[i].to,u,now);
29             if(Judge[c[i].to]==1) mx1=max(mx1,f[c[i].to]+1);
30             if(Judge[c[i].to]==2) mx2=max(mx2,f[c[i].to]-1);
31             if(Judge[c[i].to]==-1||num>m) {Judge[u]=-1; return ;}    
32         }
33     } 
34     if(mx1>mx2) {
35         if(mx1>=now) {
36             ++num,Judge[u]=2,f[u]=now;
37             if(num>m) Judge[u]=-1;
38         } else Judge[u]=1,f[u]=mx1;
39     } else Judge[u]=2,f[u]=mx2;
40 }
41 bool check(int now) {
42     num=0;
43     DFS(1,1,now);
44     if(Judge[1]==-1) return false;
45     if(Judge[1]==1&&f[1]>=0) ++num;
46     return num<=m; 
47 } 
48 int main() {
49     R=n=read(),m=read();
50     memset(r,0xff,sizeof(r));
51     for(int x,i=1; i<=n; ++i) Bomb[i]=read();
52     for(int x,y,i=1; i<n; ++i) x=read(),y=read(),add(x,y),add(y,x);
53     while(L<=R) {
54         int mid=(L+R)>>1;
55         if(check(mid))Ans=mid,R=mid-1;
56         else L=mid+1;
57     } printf("%d",Ans);
58     return 0;
59 }

 

 

转载于:https://www.cnblogs.com/forevergoodboy/p/7791661.html

内容概要:本文档详细介绍了Analog Devices公司生产的AD8436真均方根-直流(RMS-to-DC)转换器的技术细节及其应用场景。AD8436由三个独立模块构成:轨到轨FET输入放大器、高动态范围均方根计算内核和精密轨到轨输出放大器。该器件不仅体积小巧、功耗低,而且具有广泛的输入电压范围和快速响应特性。文档涵盖了AD8436的工作原理、配置选项、外部组件选择(如电容)、增益调节、单电源供电、电流互感器配置、接地故障检测、三相电源监测等方面的内容。此外,还特别强调了PCB设计注意事项和误差源分析,旨在帮助工程师更好地理解和应用这款高性能的RMS-DC转换器。 适合人群:从事模拟电路设计的专业工程师和技术人员,尤其是那些需要精确测量交流电信号均方根值的应用开发者。 使用场景及目标:①用于工业自动化、医疗设备、电力监控等领域,实现对交流电压或电流的精准测量;②适用于手持式数字万用表及其他便携式仪器仪表,提供高效的单电源解决方案;③在电流互感器配置中,用于检测微小的电流变化,保障电气安全;④应用于三相电力系统监控,优化建立时间和转换精度。 其他说明:为了确保最佳性能,文档推荐使用高质量的电容器件,并给出了详细的PCB布局指导。同时提醒用户关注电介质吸收和泄漏电流等因素对测量准确性的影响。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值