CF796C Bank Hacking 思维】的更多相关文章

Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search for Zane, he would need a lot of money, of which he sadly has none. To deal with the problem, he has decided to hack the banks. There are n banks, numb…
洛谷链接 题目 Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search for Zane, he would need a lot of money, of which he sadly has none. To deal with the problem, he has decided to hack the banks. There are n ban…
思路十分简单,答案只有 3 种可能,但是有一些细节需要额外注意一下. code: #include <bits/stdc++.h> #define N 300002 #define setIO(s) freopen(s".in","r",stdin) using namespace std; int val[N],hd[N],to[N<<1],nex[N<<1],d1[N],d2[N],n,edges,maxx,mx,m2,cnt…
Codeforce 796 C. Bank Hacking 解析(思維) 今天我們來看看CF796C 題目連結 題目 略,請直接看原題. 前言 @copyright petjelinux 版權所有 觀看更多正版原始文章請至petjelinux的blog 想法 首先稍微在腦中模擬一下大概整個流程是怎麼進行的,會發現以下幾件事: 選取點\(v\)開始整個流程,之後是對以\(v\)為根的樹"Hack",並且銀行防禦力增加只會加到子節點 每個點最多被\(+2\) 那麼我們可以想到以下的結論:…
Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再将这些刚刚加过一的点的相邻的点的权值+=1 也就是说,除了与根节点相邻的点+=1,其余点+=2 然后求最大集合的最小点权 solution 一看是要求最大的的最小值,首先想到的就是二分,显然想到这个目前没有什么卵用,二分是用来卡最佳答案的,所以使用二分的前提是要给它一个范围去选择,那么现在的任务就是…
题目 Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search for Zane, he would need a lot of money, of which he sadly has none. To deal with the problem, he has decided to hack the banks. There are n banks, n…
思路:共有n-1条边连接n个点,即形成一棵树.一开始需要选择一个点hack--将这个点视为根结点,与它相邻的点防御值加1,与它相隔一个在线点的点的防御也加1.当根节点被hack,即这个点被删除,又变成多棵树.此时,Inzane只有一种选择,因为题目规定"Bank x is neighboring to some offline bank.",即选完第一个点,接下来他只能选择剩下的数的根结点,每个节点的防御值都变得有规律可循--假设把根结点看做第一层,那么第二层的防御值都会加一,其它层都…
一开始以为是个树形dp,特地去学了..结果是个思维题 /* 树结构,设最大点权值为Max,则答案必在在区间[Max,Max+2] 证明ans <= Max+2 任取一个点作为根节点,那么去掉这个点之后其儿子结点,孙子结点的权值+1,同理,每去掉一个点之后其儿子结点,孙子结点的权值都会加上1 即每个点的权值最多只能被+2,即它的父亲,爷爷结点会导致其增加权值 考虑什么时候ans=Max:只有一个Max结点,以其为根,若有权值Max-1的点,那么这些点只有一个父亲就是Max ans=Max+1:所有…
http://codeforces.com/contest/796/problem/C Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search for Zane, he would need a lot of money, of which he sadly has none. To deal with the problem, he has decide…
题目链接:http://codeforces.com/problemset/problem/796/C 题目大意:有n家银行,第一次可以攻击任意一家银行(能量低于自身),跟被攻击银行相邻或者间接相邻(距离<=2)的银行能量+1,除了第一次外,攻击一家银行需要满足以下条件: ①:跟被攻击过后的银行相邻: ②:能量低于攻击者 ③:银行没有被攻击过 题解:可以从题意得知,比如攻击银行i,如果说银行i能量为t,跟银行距离>=2的银行中能量最大的为mx,自身至少所需能量=max(t+1,mx+2),因为…