CF 672D Robin Hood(二分答案)】的更多相关文章

D. Robin Hood time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, a…
题目链接:http://codeforces.com/contest/672/problem/D 有n个人,k个操作,每个人有a[i]个物品,每次操作把最富的人那里拿一个物品给最穷的人,问你最后贫富差距有多少. 先sort一下,最富的人很明显不会低于sum(a1 ~ an) / n , 所以二分一下最富人的最小值 看是否满足操作k. 最穷的人不会高于sum(a1 ~ an) / n + 1 ,所以二分一下最穷人的最大值 看是否满足操作k. (注意一点的是二分以后最穷的人的最大值和最富的人的最小值…
D. Robin Hood time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, a…
题目链接: D. Robin Hood time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from r…
D. Robin Hood   We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor. There are n citizens in Kekoland, each person has ci coins. Each day, Robin Hood…
B. Robin Hood 题目连接: http://www.codeforces.com/contest/671/problem/B Description We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor. There are n citiz…
D. Robin Hood We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor. There are n citizens in Kekoland, each person has ci coins. Each day, Robin Hood wi…
题意:有n个人,每个人a[i]个物品,进行k次操作,每次都从最富有的人手里拿走一个物品给最穷的人 问k次操作以后,物品最多的人和物品最少的人相差几个物品 分析:如果次数足够多的话,最后的肯定在平均值上下,小的最多被补到sum/n,大最多减少到sum/n,或者sum/n+1 然后就二分最小值,看所有小的是否能在k次被填满 二分最大值,看所有大的是否都在k次被抹平 然后就是二分的写法,小和大的不一样,需要加等号,避免死循环 #include <stdio.h> #include <strin…
思维. 当$k$趋向于正无穷时,答案会呈现出两种情况,不是$0$就是$1$.我们可以先判断掉答案为$1$和$0$的情况,剩下的情况都需要计算. 需要计算的就是,将最小的几个数总共加$k$次,最小值最大会是多少,以及将最大的几个数总共减$k$次,最大值最小可能是多少.两者相减就是答案. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring>…
题目:http://codeforces.com/contest/949/problem/D 先二分一个答案,让两边都至少满足这个答案: 由于越靠中间的房间越容易满足(被检查的时间靠后),所以策略就是优先满足中间的房间,舍弃两边边缘的: 所以就由外到内推过来就可以了,用一个指针记录现在已经使用到的房间... 具体可以看这篇博客:https://www.cnblogs.com/Narh/p/9706060.html 代码如下: #include<iostream> #include<cst…