Bank Hacking CodeForces - 796C
题意:
一条笨狗要去黑银行,银行有n个,它们之间用n-1条边连接。可以选择任意一个银行开始黑,但是后面每一次黑的银行都要求与已经黑过的银行直接相连。每个银行初始有一个防御值,每一个银行被黑后,与其直接相连的未被黑的银行的防御值会+1,与“与其直接相连的未被黑的银行”相连的未被黑的银行的防御值也会+1,。笨狗要黑完所有银行,且其电脑的强度要求大于等于所有银行被黑那一刻的防御值。现在要求电脑的最小强度。
分析:
记点x在被hack时比原来高的强度为s[x], 稍微尝试一下就会发现,s[第一次选的]=0,s[第一次选的的neighbor]=1,s[其他所有]=2.
| 选的 | s有更新的 |
| 选4 | s[4]=0 s[3]=s[5]=s[2]=s[6]=1 |
| 选5 | s[6]=2 s[7]=1 |
| 选6 | s[7]=2 |
| 选3 | s[2]=2 s[1]=1 |
| 选7 | 无 |
| 选2 | s[1]=2 |
| 选1 | 无 |
所以,暴力吧
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
struct Edge
{
LL to,next;
}edge[];
LL num_edge,first[],d[],ans=0x3f3f3f3f,n;
struct Node
{
Node *lc,*rc;
LL l,r;
LL maxn;
}ssss[];//线段树,然而根本用不着
LL num_node;
Node* getnode()
{
return &ssss[num_node++];
}
Node* build(LL l,LL r)
{
Node *_tmp=getnode();
_tmp->l=l;
_tmp->r=r;
if(l==r)
{
_tmp->maxn=d[l];
//_tmp->lc=NULL;
//_tmp->rc=NULL;
return _tmp;
}
LL m=(l+r)>>;
_tmp->lc=build(l,m);
_tmp->rc=build(m+,r);
_tmp->maxn=max(_tmp->lc->maxn,_tmp->rc->maxn);
return _tmp;
}
LL query(LL L,LL R,Node *p)
{
LL l=p->l;
LL r=p->r;
if(L<=l&&r<=R)
return p->maxn;
LL ans=-0x3f,m=(l+r)>>;
if(L<=m) ans=max(ans,query(L,R,p->lc));
if(R>m) ans=max(ans,query(L,R,p->rc));
return ans;
}
void update(LL L,Node *p,LL x)
{
LL l=p->l;
LL r=p->r;
if(l==r)
{
//p->maxn=max(p->maxn,x);
p->maxn+=x;
return;
}
LL m=(l+r)>>;
if(L<=m) update(L,p->lc,x);
else update(L,p->rc,x);
p->maxn=max(p->lc->maxn,p->rc->maxn);
}
int main()
{
LL i,a,b,k;
scanf("%lld",&n);
for(i=;i<=n;i++)
scanf("%lld",&d[i]);
for(i=;i<n;i++)
{
scanf("%lld%lld",&a,&b);
edge[++num_edge].to=b;
edge[num_edge].next=first[a];
first[a]=num_edge;
edge[++num_edge].to=a;
edge[num_edge].next=first[b];
first[b]=num_edge;
}
Node *x=build(,n);
for(i=;i<=n;i++)
{
update(i,x,-);
k=first[i];
while(k!=)
{
update(edge[k].to,x,-);
k=edge[k].next;
}
ans=min(ans,query(,n,x)+);
update(i,x,);
k=first[i];
while(k!=)
{
update(edge[k].to,x,);
k=edge[k].next;
}
}
printf("%lld",ans);
//del(x);
return ;
}
再贴一张

Bank Hacking CodeForces - 796C的更多相关文章
- Code Forces 796C Bank Hacking(贪心)
Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再 ...
- C. Bank Hacking 解析(思維)
Codeforce 796 C. Bank Hacking 解析(思維) 今天我們來看看CF796C 題目連結 題目 略,請直接看原題. 前言 @copyright petjelinux 版權所有 觀 ...
- CodeForces - 796C Bank Hacking
思路:共有n-1条边连接n个点,即形成一棵树.一开始需要选择一个点hack--将这个点视为根结点,与它相邻的点防御值加1,与它相隔一个在线点的点的防御也加1.当根节点被hack,即这个点被删除,又变成 ...
- 【codeforces 796C】Bank Hacking(用一些技巧来代替multiset)
[题目链接]:http://codeforces.com/contest/796/problem/C [题意] 给你n个节点,你一开始选择一个节点,然后打掉它,然后与被打掉过的节点相连的节点才能被 打 ...
- 【codeforces 796C】Bank Hacking
[题目链接]:http://codeforces.com/contest/796/problem/C [题意] 给你n个节点,你一开始选择一个节点,然后打掉它,然后与被打掉过的节点相连的节点才能被 打 ...
- Codeforces Round #408 (Div. 2) C. Bank Hacking
http://codeforces.com/contest/796/problem/C Although Inzane successfully found his beloved bone, Zan ...
- codeforce 796C - Bank Hacking(无根树+思维)
题目 Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To searc ...
- Codeforces Round #408 (Div. 2)C. Bank Hacking(STL)
题目链接:http://codeforces.com/problemset/problem/796/C 题目大意:有n家银行,第一次可以攻击任意一家银行(能量低于自身),跟被攻击银行相邻或者间接相邻( ...
- Codeforces Round #408 (Div. 2) C.Bank Hacking(二分)
传送门 题意 给出n个银行,银行之间总共有n-1条边,定义i与j有边相连为neighboring,i到j,j到k有边,则定义i到k的关系为semi- neighboring, 每家银行hack的难度为 ...
随机推荐
- mysql的DUPLICATE KEY
经常遇到这样的情景,向一个表里插入一条数据,如果已经存在就更新一下,用程序实现麻烦而且在并发的时候可能会有问题,这时用mysql的DUPLICATE KEY 很方便 用法如下: INSERT INTO ...
- Apache Qpid 高可用集群
一.RHCS RHCS是Red Hat Cluster Suite(红帽子集群套件)的缩写.RHCS是一个功能完备的集群应用解决方案,它从应用的前端访问到后端的数据存储都提供了一个行之有效的集群架构实 ...
- Python 006- python socket编程详细介绍
转自https://blog.csdn.net/rebelqsp/article/details/22109925 Python 提供了两个基本的 socket 模块. 第一个是 Socket,它提供 ...
- An O(ND) Difference Algorithm and Its Variations (1986)
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927 The problems of finding a longest com ...
- react native 之 redux
第一章 认识redux 说的通俗且直白一点呢,就是redux提供了一个store,独立的一个内存区,然后放了一些state,你可以在任何component中访问到state,这些state要更改怎么 ...
- javascript flash 弹框
1. [代码]FlashBox // JavaScript Documentfunction FlashBox(src,width,height){var docbody = document ...
- 各种java生成word解决方案的优缺点对比
解决方案 优点 缺点 Jacob 功能强大 直接调用VBA接口,程序异常复杂:服务器必须是:windows系统+安装Office:服务器端自动化com接口容易产生死进程造成服务器宕机 Apache P ...
- 使用 Word 2013 维护博客
博客的发布.修改是一件非常耗时.耗精力的事情.借助 Word 2013,维护博客将变得非常简单. 1 新建博客文章 运行 Word 2013,新建文档.如下图所示: 图1 鼠标左键单击上图的" ...
- CodeForces979D:Kuro and GCD and XOR and SUM(Trie树&指针&Xor)
Kuro is currently playing an educational game about numbers. The game focuses on the greatest common ...
- [Selenium] 如何在老版本的Chrome 浏览器上使用selenium
由于Chrome Driver 只兼容Chrome 浏览器12.0.712.0 和之后的新版本,会因此如果要在老版本的Chrome 浏览器上使用Selenium, 则只能使用 SeleniumRC ...