Code Forces 796C Bank Hacking(贪心)】的更多相关文章

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.",即选完第一个点,接下来他只能选择剩下的数的根结点,每个节点的防御值都变得有规律可循--假设把根结点看做第一层,那么第二层的防御值都会加一,其它层都…
题目大意 洛谷链接 给定一棵带点权树,选出一个最佳的根节点,使得根节点的点权不变,它的儿子点权加1,其余点点权加2,并使最大点权最小,输出这个最小的最大点权. 其他见链接(懒). PS:原题面很不好总结题意,洛谷的翻译的确很清楚. 思路 先枚举最大点权设为\(v_{max}\). 若最大点权的点只有一个 若没有\(v=v_{max}-1\)的点,答案即为\(v_{max}\) 若存在且为最大权值点的子节点,答案为\(v_{max}-1+1=v_{max}\) 若存在且不是最大权值点的子节点,答案…
思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Now Serval is a junior high school student in Japari Middle School, and he is…
Code Forces 833 A The Meaningless Game 题目大意 有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数 不得不吐槽一下那么长的英文题面翻译完只有一句话-- solution 也很好想叭 乘积开立方判断是否为两个数的因数 如果是的话,显然不成立 否则输出Yes即可 #include <iostream> #include <cstring> #include <cstdio>…
Codeforce 796 C. Bank Hacking 解析(思維) 今天我們來看看CF796C 題目連結 題目 略,請直接看原題. 前言 @copyright petjelinux 版權所有 觀看更多正版原始文章請至petjelinux的blog 想法 首先稍微在腦中模擬一下大概整個流程是怎麼進行的,會發現以下幾件事: 選取點\(v\)開始整個流程,之後是對以\(v\)為根的樹"Hack",並且銀行防禦力增加只會加到子節點 每個點最多被\(+2\) 那麼我們可以想到以下的結論:…
题目 题意: 一条笨狗要去黑银行,银行有n个,它们之间用n-1条边连接.可以选择任意一个银行开始黑,但是后面每一次黑的银行都要求与已经黑过的银行直接相连.每个银行初始有一个防御值,每一个银行被黑后,与其直接相连的未被黑的银行的防御值会+1,与“与其直接相连的未被黑的银行”相连的未被黑的银行的防御值也会+1,.笨狗要黑完所有银行,且其电脑的强度要求大于等于所有银行被黑那一刻的防御值.现在要求电脑的最小强度. 分析: 记点x在被hack时比原来高的强度为s[x], 稍微尝试一下就会发现,s[第一次选…
[题目链接]:http://codeforces.com/contest/796/problem/C [题意] 给你n个节点,你一开始选择一个节点,然后打掉它,然后与被打掉过的节点相连的节点才能被 打掉,但打掉一个点之后,与它距离小于等于2的节点的权值会增加1(如果中间节点有被打掉的,则不增加,即被切断了); 重复上述步骤,直至所有节点被打掉,能打掉某个节点,你需要满足:你的权值大于等于这个节点的权值.求一开始你的 权值的最小值; [题解] 思路在这里http://blog.csdn.net/h…
[题目链接]:http://codeforces.com/contest/796/problem/C [题意] 给你n个节点,你一开始选择一个节点,然后打掉它,然后与被打掉过的节点相连的节点才能被 打掉,但打掉一个点之后,与它距离小于等于2的节点的权值会增加1(如果中间节点有被打掉的,则不增加,即被切断了); 重复上述步骤,直至所有节点被打掉,能打掉某个节点,你需要满足:你的权值大于等于这个节点的权值.求一开始你的 权值的最小值; [题解] 枚举每一个点作为第一个打掉的点,除了和它距离为1的那些…
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…
1098 均分纸牌 2002年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解   题目描述 Description 有 N 堆纸牌,编号分别为 1,2,…, N.每堆上有若干张,但纸牌总数必为 N 的倍数.可以在任一堆上取若于张纸牌,然后移动. 移牌规则为:在编号为 1 堆上取的纸牌,只能移到编号为 2 的堆上:在编号为 N 的堆上取的纸牌,只能移到编号为 N-1 的堆上:其他堆上取的纸牌,可以移到相邻左边或右边的堆上. 现在…
J - Sockets Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Valera has only one electrical socket in his flat. He also has m devices which require electricity to work. He's got n plug multipliers to plug the devices, the…
题目描述 Programmers working on a large project have just received a task to write exactly mm lines of code. There are nn programmers working on a project, the ii -th of them makes exactly a_{i}ai​ bugs in every line of code that he writes. Let's call a…
题目链接:http://codeforces.com/problemset/problem/796/C 题目大意:有n家银行,第一次可以攻击任意一家银行(能量低于自身),跟被攻击银行相邻或者间接相邻(距离<=2)的银行能量+1,除了第一次外,攻击一家银行需要满足以下条件: ①:跟被攻击过后的银行相邻: ②:能量低于攻击者 ③:银行没有被攻击过 题解:可以从题意得知,比如攻击银行i,如果说银行i能量为t,跟银行距离>=2的银行中能量最大的为mx,自身至少所需能量=max(t+1,mx+2),因为…
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…
传送门 题意 给出n个银行,银行之间总共有n-1条边,定义i与j有边相连为neighboring,i到j,j到k有边,则定义i到k的关系为semi- neighboring, 每家银行hack的难度为a[i], 如果hack了一家银行,会使与它关系为neighboring.semi- neighboring的银行难度+1,每次hack的银行满足三个条件: 1.未被hack过 2.与hack的银行相邻,即为neighboring的关系 3.被hack的银行难度不大于 Inzane电脑的hack力(…
思路十分简单,答案只有 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…
洛谷链接 题目 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…
题意:你在一家公司工作\(t\)天,负责给饮水机灌水,饮水机最初有\(k\)升水,水的范围必须要在\([l,r]\)内,同事每天白天都会喝\(x\)升水,你在每天大清早可以给饮水机灌\(y\)升水,问你在公司工作的这几天内,饮水机会不会发生故障. 题解:假如\(x>=y\),那么,我们贪心的思路一定是每天让水减的尽可能少,所以每天都要加水,这里要注意第一天的情况,如果第一天加水后大于\(r\)话,那么第一天大清早是不能加水的,这里我们要特判一下,接下来用if判断就行了. 假如\(x < y\)…
Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As you have noticed, there are lovely girls in Arpa's land. People in Arpa's land are numbered from 1…
Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) bur…
/* * Watermelon.cpp * * Created on: 2013-10-8 * Author: wangzhu */ /** * 若n是偶数,且大于2,则输出YES, * 否则输出NO */ #include<cstdio> #include<iostream> using namespace std; int main() { int n; while (~scanf("%d", &n)) { && (n & )…
/* * c.cpp * * Created on: 2013-10-7 * Author: wangzhu */ #include<cstdio> #include<iostream> using namespace std; #define NMAX 100010 struct Node { //index:表示两个数直接的距离(-1:表示未开始,0:表示开始:> 0:表示有了距离 //val:记录最后一次的位置 //flag:不符合条件 (0:表示符合条件,1:表示不符…
D - Laying Cables Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u One-dimensional country has n cities, the i-th of which is located at the point xi and has population pi, and all xi, as well as all pi, are distinct. Whe…
D. Directed Roads time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it consists of n towns numb…
C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be…
Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b&q…
略有上升称号,最近有很多问题,弥补啊,各类竞赛滥用,来不及做出了所有的冠军.这个话题 这是一个长期记忆的主题.这是不是太困难,基本技能更灵活的测试,每次我们来看看这个问题可以被删除,处理然后分段层,贪婪的想法画一幅画,可以发现,下一步骤是如何应用,搜递归就能够了.当时写错了.还是漏了一些,如今补题才发现,长记性咯 http://codeforces.com/contest/448/problem/C #include<iostream> #include<cstdio> #incl…
http://codeforces.com/problemset/problem/414/B 题目挺不错的.留个纪念,活动脑筋不错的题目 #include<iostream> #include<cstdio> #include<list> #include<algorithm> #include<cstring> #include<string> #include<queue> #include<stack>…