codeforces 1020 C Elections(枚举+贪心)】的更多相关文章

题意: 有 n个人,m个党派,第i个人开始想把票投给党派pi,而如果想让他改变他的想法需要花费ci元.你现在是党派1,问你最少花多少钱使得你的党派得票数大于其它任意党派. n,m<3000 思路: 枚举“除了党派1之外其他党派最多有的票的数量”,贪心一下即可 坑点: 1.爆int 2.inf太小,要设成0x3f3f3f3f3f3f3f3f 3.sort忘了从第一个开始排(被Wa7支配) #include<iostream> #include<iomanip> #include…
我的参考的博客地址 题目 逆向考虑. 暴力遍历 k(k是1到n/2+1 范围内的),挑出对于每一个k,记对于党派 i,num[ i ]为其票数.num[ i ]小于k-1的就不用改变投票了(这部分是比较贵的),而 >=k-1的,都让他们投票给党派1(这部分是比较便宜的),这意味着要逆着贪心 简言之,就是尽量使贵的不改,便宜的改,控制贵的票数小于k. 做法:按照p的大小 把结构体按从小到大排序.对于每一个k,从大到小 找出对于这个k 不需要改变投票给1的最大值(总钱数-原来就投给1的钱数-不需要改…
题目描述: C. Elections time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year…
D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ii-th lamp is sisi ('…
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include<bits/stdc++.h> using namespace std; typedef unsigned long long ull; ; ull base[maxbit], n, k; void preDeal() { ] = ; ; i < maxbit; i++){ *]; } } voi…
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的货币越优.如有1,2,5,10,20,50,那么我们尽量用面值为1的.如果我们把原始货币换成面值为x的货币,设汇率为d,那么需要的原始货币为dx的倍数.显然dx越小,剩下的钱,即n取模dx会尽量小. 然后就可以枚举换某一种货币的数量,时间复杂度\(O(\frac{n}{d})\) 代码 #inclu…
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625 题意:中文题诶- 思路:枚举+贪心 一开始写的行和列同时枚举,写的时候就担心可能行和列会相互影响,提交结果证明我的担心是对的: 注意到1 <= n <= 10, 1 <= m <= 200,n很小,那么所有行的状态不超过1024种,所以可以枚举所有行的状态,对于每一种行的状态下再对列贪心.. 枚举行的所有状态可以用dfs.. 代码: #in…
题目传送门 /* 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则往右边放, 判断一下,取最大值.这题二分的内容少 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; ; const…
题目: 党派竞争投票 有n个人,m个党派,这n个人每个人有一个想要投的党派的编号Pi,如果想要这个人改变他的想法,那么就需要花费Ci元钱. 现在你是编号为1的党派,如果你想要赢(你的票数严格大于其他党派的票数),需要花费的最少的钱是多少. 思路: 将每个人按花费从小到大排序,从0到n枚举获胜需要的票数,遍历所有要投票的人,如果他要投的党派的票数大于当前枚举的票数,就把这个人的票给买过来,最后取所有花费中最小的那个就可以了. 爆int…… 代码: #include <bits/stdc++.h>…
题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was…