hdu 5927 Auxiliary Set 贪心】的更多相关文章

Auxiliary Set Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Given a rooted tree with n vertices, some of the vertices are important. An auxiliary set is a set containing vertices satisfying at…
Auxiliary Set Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 873    Accepted Submission(s): 271 Problem Description Given a rooted tree with n vertices, some of the vertices are important.An au…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5927 题意: 给你一棵树,其中有一些'不重要'的点,要是这些'不重要'的点的子树中有两个重要的点的LCA是这个点,那么这个点就是重要的点.每次询问 问你重要的点有多少? 思路: 用不重要的点建图,要是这个不重要点上的相邻子树至少有两个有重要的点不在同一子树上,那么这个不重要的点才变成重要的点. #include <iostream> #include <cstdio> #include…
传送门 分析:感觉这道题有点意思.就写一篇mark一下吧. 现场比赛的时候去枚举了儿子用了线段树+dfs序,和预想的一样T了. 可以换一个想法,从儿子对父亲的贡献来思考. 在点中先假设一个节点的每一个儿子对父亲节点都有的贡献,再考虑每个儿子 如果当前儿子有两个及以上的点,那么这个点也在集合中,计数加一:如果当前儿子有一个节点,那么虽然它不在集合中,但还是对它的父亲有的贡献:如果当前儿子没有节点,那么它既不在集合中,又对父亲没有贡献,它父亲中的贡献需要减一(之前假设了每个儿子对父亲都有贡献).于是…
题目链接: F - Auxiliary Set HDU - 5927 学习网址:https://blog.csdn.net/yiqzq/article/details/81952369题目大意一棵节点数为n的有根数,根节点为1,一开始所有的点都是重点,接下来有q次询问,每次询问把m个点变为轻点,问你树中还有多少个重点. 重点应该满足的条件为: 1.它本身是重点. 2.它为两个重点的最近公共祖先. 每次询问之后在下次询问前,所有的点都恢复为重点. 具体思路:对于每个点保存他的深度.因为每次输入的数…
HDU 4442 Physical Examination(贪心) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4442 Description WANGPENG is a freshman. He is requested to have a physical examination when entering the university. Now WANGPENG arrives at the hospital. Er-.. Th…
Danganronpa 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5835 Description Chisa Yukizome works as a teacher in the school. She prepares many gifts, which consist of n kinds with a[i] quantities of each kind, for her students and wants to hold a cl…
Ball 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5821 Description ZZX has a sequence of boxes numbered 1,2,...,n. Each box can contain at most one ball. You are given the initial configuration of the balls. For 1≤i≤n, if the i-th box is empty the…
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4004 题目意思是青蛙要过河,现在给你河的宽度,河中石头的个数(青蛙要从石头上跳过河,这些石头都是在垂直于河岸的一条直线上) 还有青蛙能够跳跃的 最多 的次数,还有每个石头离河岸的距离,问的是青蛙一步最少要跳多少米可以过河> 这是一道二分加贪心的题,从0到的河宽度开始二分,二分出一个数然后判断在这样的最小步数(一步跳多少距离)下能否过河 判断的时候要贪心 主要难在思维上,关键是要想到二分上去,能想到…
Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4638    Accepted Submission(s): 2111 Problem Description 话说上回讲到海东集团面临内外交困,公司的元老也只剩下XHD夫妇二人了.显然,作为多年拼搏的商人,XHD不会坐以待毙的.   一天,当他正在苦思冥想解困良策…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4714 题意: 给你一棵树,添加和删除一条边的代价都是1.问你将这棵树变成一个环的最小代价. 题解: 贪心. 将树变成环的过程,无非就是先拆掉k条边,将这棵树变成若干个链,然后再添加k+1条边,将所有链连成环. 所以要让最终代价最小,就是让拆的边最少. 对于节点i的子树,如果要将这棵子树全部变成链,则总共有两种情况: (1)节点i的儿子数 <= 1,这样的话根本就不用拆啊. (2)节点i的儿子数 >…
Delicious Apples Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) Total Submission(s): 199    Accepted Submission(s): 54 Problem Description There are n apple trees planted along a cyclic road, which is L metres l…
Detachment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 570    Accepted Submission(s): 192 Problem Description In a highly developed alien society, the habitats are almost infinite dimensiona…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5037 题解:为了让放的石头有意义肯定是没l+1的距离放2个也就是说假设现在位置为pos那么在pos+1放一个在pos+l+1放一个这样就需要跳两次.于是这题要考虑的就是当前位置和前一个石头放的位置因为如果前一个石头的位置到a[i]的距离小于等于l那么当前位置就不能被走到.所以就拿l+1的距离来贪心. #include <iostream> #include <cstring>…
2019 杭电多校 10 1005 题目链接:HDU 6695 比赛链接:2019 Multi-University Training Contest 10 Problem Description The annual welcome party of the Department of Computer Science and Technology is coming soon! Many students have been applying to show up at the welcom…
题目链接 题目都看不懂,做毛线...看懂了之后就是kmp出,所有的匹配区间,然后DP可以写,贪心也可以做把,DP应该需要优化一下,直接贪,也应该对的,经典贪心问题. #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; ],s2[]; ],o[]; ]; ]; int judge(…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2570 Ac code: #include<stdio.h> #include<stdlib.h> int cmp(const void *a,const void *b) { return *(int *)a-*(int *)b; } int main(void) { int c,n,v,w,iarr[110],i; double sum; scanf("%d",&…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 AC code: #include<stdio.h> #include<string.h> int m[210]; int main(void) { int t,n,i,j,st,en,ma; scanf("%d",&t); while(t--) { memset(m,0,sizeof(m)); scanf("%d",&n)…
Task 题目链接: http://acm.hust.edu.cn/vjudge/contest/121336#problem/B Description Today the company has m tasks to complete. The ith task need xi minutes to complete. Meanwhile, this task has a difficulty level yi. The machine whose level below this task…
分析:就是给一些拓补关系,然后求最大分数,所以贪心,大的越靠前越好,小的越靠后越好 剩下的就是toposort,当然由于贪心,所以使用优先队列 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <string> #include <stack> #include <…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4550 题意:有n(n <= 100)个0~9之间的卡片,从左往右将卡片放到之前的卡片最左边或者最右边:使得最后得到的数值最小,且无前导0: input: output: 思路:如果没有0,则直接用双指针,模拟前后插入值即可:但是由于存在0,所以需要找出最小的非零0,使得最前面以mn开头,之后是可填入的若干个0.所谓可填入的即指在最后一个mn填入之前的0,这就需要记录mn的个数,每次插入mn时,--c…
FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requ…
http://www.cnblogs.com/AOQNRMGYXLMV/p/4934747.html #include<iostream> #include<cstdio> #include<algorithm> using namespace std; ; const int inf=0x3f3f3f3f; int a[maxn]; int b[maxn]; ,,,,,,,,,}; int Solve(int t) { ; ;i>=;i--) { ||i==)…
题目链接 Problem Description You are a rich person, and you think your wallet is too heavy and full now. So you want to give me some money by buying a lovely pusheen sticker which costs pdollars from me. To make your wallet lighter, you decide to pay exa…
http://acm.hdu.edu.cn/showproblem.php?pid=5242 题意: 给出一棵树,每个节点都有一个权值,每次可以获得从根结点(1)到叶子节点上的所有权值和,每个节点只能获得一次.求k次操作后可以获得的最大权值和. 思路: 反向建图,首先求出所有节点到根节点的权值和,然后降序排序,从可以获得最大权值和的叶子节点开始计算.已经遍历过的节点就直接返回0.计算完后再次重新排序,取前面的k个较大值. #include<iostream> #include<algor…
Physical Examination Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6155 Accepted Submission(s): 1754 Problem Description WANGPENG is a freshman. He is requested to have a physical examination wh…
Description Steph is extremely obsessed with “sequence problems” that are usually seen on magazines: Given the sequence 11, 23, 30, 35, what is the next number? Steph always finds them too easy for such a genius like himself until one day Klay comes…
题目:http://acm.hdu.edu.cn/showproblem.php? pid=5360 题意:beta有n个朋友,beta要邀请他的朋友go hiking,已知每一个朋友的理想人数[L,R](现有L~R个人准备去,那么这个朋友就去). 求最多有多少人去. 及beta邀请朋友的顺序. 分析:每次邀请人的最优解就是:选会去的人里面R最小的那个人. 代码实现的话,cur代表已经准备go hiking的人数,每次将全部L<=cur的人放进优先队列,选出R最小的那个. 假设队列为空,那么剩下…
There is a tree having N vertices. In the tree there are K monkeys (K <= N). A vertex can be occupied by at most one monkey. They want to remove some edges and leave minimum edges, but each monkey must be connected to at least one other monkey throug…
题意:给定一个序列,让你构造出一个序列,满足条件,且最大.条件是 选取一个ai <= max{a[b[j], j]-j} 析:贪心,贪心策略就是先尽量产生大的,所以就是对于B序列尽量从头开始,由于数据比较大,采用桶排序,然后维护一个单调队列,使得最头上最大. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #i…