Codeforces 458C - Elections】的更多相关文章

458C - Elections 思路: 三分凹形函数极小值域 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) ; const int INF=0x7f7f7f7f; vector<int>g[N],vc; int n; int cost(int x){ ].size(),…
题目描述: 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…
题目链接: http://codeforces.com/problemset/problem/258/B B. Little Elephant and Elections time limit per test2 secondsmemory limit per test256 megabytes 问题描述 There have recently been elections in the zoo. Overall there were 7 main political parties: one…
Little Elephant and Elections CodeForces - 258B 题意:给出m,在1-m中先找出一个数x,再在剩下数中找出6个不同的数y1,...,y6,使得y1到y6中数字4和7出现的总次数严格小于x中数字4和7出现的总次数.求方案数. 方法:先数位dp分别预处理出:1到m之间,数字4和7出现的总次数为0到9的数.(总共最多10个数字,第一个最大1,因此4和7出现的总次数最多9次)然后枚举x,再暴力dfs枚举6个数,统计方案数. 问题(细节): 1.(13行)数位…
[题目描述] Elections are coming. You know the number of voters and the number of parties — n and m respectively. For each voter you know the party he is going to vote for. However, he can easily change his vote given a certain amount of money. In particu…
                                                A. Bear and Elections                                                                                                                                                                            time limi…
369C - Valera and Elections 思路:dfs,对于搜索到的每个节点,看他后面有没有需要修的路,如果没有,那么这个节点就是答案. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back ; vector<int>g[N]; vector<int>edge[N]; vector<int>ans; int dfs(i…
You are running for a governor in a small city in Russia. You ran some polls and did some research, and for every person in the city you know whom he will vote for, and how much it will cost to bribe that person to vote for you instead of whomever he…
A. Bear and Elections time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearla…
原文地址 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.…
Valera and Elections 题意:现在有n个候选人, 有n-1条路, 如果选择了这个候选人, 这个候选人就会将从自己这个城市到1号城市上所有坏的路都修复一下,现在求最小的候选人数目, 如果答案有多种情况输出任何一种都可以. 输入:x y k 表示x与y之间有一条双向通道, k==1 表示这路是好的, k == 2表示这条路是坏的. 题解: 从1开始dfs搜索, 往外走, 如果遇到坏的城市就标记一下, 然后继续往外走, 如果更远的地方有一个坏的路就用更远地方的城市候选人代替这个标记的…
[题目] A. Elections [描述] Awruk和Elodreip参加选举,n个人投票,每个人有k张票,第i个人投a[i]张票给Elodreip,投k-a[i]张票给Awruk.求最小的k,使得Awruk比Elodreip得票多. 数据范围:1<=n<=100,1<=a[i]<=100 [思路] Awruk得票数为n*k-(a[1]+...+a[n]),Elodreip得票数为a[1]+...+a[n].n*k-(a[1]+...+a[n])>a[1]+...+a[n…
数位DP部分,不是很难.DP[i][j]前i位j个幸运数的个数.枚举写的有点搓... #include <cstdio> #include <cstring> using namespace std; #define LL __int64 #define MOD 1000000007 ][]; ],num; ]; int dfs(int pos,int pre,int bound) { int ans,i,end; ans = ; ) ; ) return dp[pos][pre]…
题目:Click here #include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; +; int n, m; ]; ]; int main() { while( ~scanf("%d%d", &n, &m ) ) { memset( b, , sizeof(b) ); ; i<=m; i++ ) { ; j<=n…
FWT裸题,写了下模板 #include<cstdio> #define ll long long #define r register int #define MN (1<<20) #define MOD 1000000007 ]; ]; ll a[MN+]; inline int mod(int x){return x<MOD?x:x-MOD;} void fwt(int v) { ;i<n;++i),x;j<<<n;++j)<<i),…
枚举每个获胜的可能的票数+按照花费排序 #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #define ll long long using namespace std; struct node { int id,cost; } a[]; bool cmp(node a,node b) { return a.cost<b.cost; } ]; ];…
大意: 有n个选民, m个党派, 第i个选民初始投$p_i$一票, 可以花费$c_i$改变投票, 求最少花费使得第一个党派的票数严格最大 假设最终第一个党派得票数$x$, 枚举$x$, 则对于所有票数$\ge x$的党派, 贪心选择尽量小的c改选第一个党派.若最后票数还不够, 再从没改过的人中选择尽量小的改选即可 #include <iostream> #include <algorithm> #include <cstdio> #include <vector&…
C. Travelling Salesman and Special Numbers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he…
优先队列模拟一下就好. #include<bits/stdc++.h> using namespace std; priority_queue<int>q; int main() { int n; scanf("%d",&n); int t; scanf("%d",&t); ; i <= n; i++){ int v; scanf("%d",&v); q.push(v); } ; while(…
题目: 党派竞争投票 有n个人,m个党派,这n个人每个人有一个想要投的党派的编号Pi,如果想要这个人改变他的想法,那么就需要花费Ci元钱. 现在你是编号为1的党派,如果你想要赢(你的票数严格大于其他党派的票数),需要花费的最少的钱是多少. 思路: 将每个人按花费从小到大排序,从0到n枚举获胜需要的票数,遍历所有要投票的人,如果他要投的党派的票数大于当前枚举的票数,就把这个人的票给买过来,最后取所有花费中最小的那个就可以了. 爆int…… 代码: #include <bits/stdc++.h>…
[链接] 我是链接,点我呀:) [题意] 给你一棵树 让你选择若干个修理点. 这些修理点被选中之后,节点i到1号节点之间的所有"坏路"都会被修好 问最少需要选择多少个点才能将所有的坏路修好 [题解] 以1为根节点建立一棵树 对于每一棵子树,如果里面有"坏路",必然要选择一个修理点,怎么选择呢? 肯定是"最底下"的那条坏路的下面那个点. 因此记录下每个子树下面的修理点的个数(我们是贪心选择的,能统计出来) 然后如果i和直系儿子j之间有一条坏路,且j…
[链接] 我是链接,点我呀:) [题意] 每个人都有自己喜欢的队员 但是如果贿赂他们可以让他们更改自己喜欢的队员 问你最少要花多少钱贿赂队员才能让1号队员严格有最多的人喜欢? [题解] 除了1号之外,其他队员最后喜欢的人数不太好确定. 我们可以这样,用up枚举其他人最后喜欢的人数的上限(即除了1之外所有人都不能超过up) 如果某个人的被喜欢人数超过了,则把所有喜欢这个人当中需要贿赂用的钱数最低的几个贿赂了.让他低于up 然后我们再在这种情况下,让1号队员成为最被喜欢的人(选择之前没被贿赂的且原本…
[链接] 我是链接,点我呀:) [题意] [题解] 枚举k 那么另外一个人的得票就是nk-sum(ai) 找到最小的满足nk-sum(ai)>sum(ai)的k就ok了 [代码] #include <bits/stdc++.h> #define rep1(i,a,b) for (int i = a;i <= b;i++) #define rep2(i,a,b) for (int i = a;i >= b;i--) using namespace std; const int…
我的参考的博客地址 题目 逆向考虑. 暴力遍历 k(k是1到n/2+1 范围内的),挑出对于每一个k,记对于党派 i,num[ i ]为其票数.num[ i ]小于k-1的就不用改变投票了(这部分是比较贵的),而 >=k-1的,都让他们投票给党派1(这部分是比较便宜的),这意味着要逆着贪心 简言之,就是尽量使贵的不改,便宜的改,控制贵的票数小于k. 做法:按照p的大小 把结构体按从小到大排序.对于每一个k,从大到小 找出对于这个k 不需要改变投票给1的最大值(总钱数-原来就投给1的钱数-不需要改…
题意: 有 n个人,m个党派,第i个人开始想把票投给党派pi,而如果想让他改变他的想法需要花费ci元.你现在是党派1,问你最少花多少钱使得你的党派得票数大于其它任意党派. n,m<3000 思路: 枚举“除了党派1之外其他党派最多有的票的数量”,贪心一下即可 坑点: 1.爆int 2.inf太小,要设成0x3f3f3f3f3f3f3f3f 3.sort忘了从第一个开始排(被Wa7支配) #include<iostream> #include<iomanip> #include…
连接:http://codeforces.com/contest/1020 C.Elections 题型:你们说水题就水题吧...我没有做出来...get到了新的思路,不虚.好像还有用三分做的? KN Point(注意复杂度性能):优先队列1,优先队列2 #include<bits/stdc++.h> using namespace std; #define ll long long ; priority_queue<int,vector<int>,greater<in…
链接:https://codeforces.com/contest/570 A - Elections - [水] AC代码: #include<bits/stdc++.h> using namespace std; int n,m; ]; int main() { cin>>n>>m; ;i<=m;i++) { , id=; ,x;j<=n;j++) { cin>>x; if(x>mx) mx=x, id=j; } cnt[id]++;…
链接:http://codeforces.com/contest/1043 A - Elections - [水水水水题] 题意: 我和另一个人竞争选举,共有 $n$ 个人投票,每个人手上有 $k$ 票,必须投给我或者另一个人. 现在已知每个人给另一个人投 $a_i$ 票,也就是说会给我投 $k-a_i$ 票.求最小的整数 $k$,使得我的票数严格大于另一个人. 题解: 暴力枚举 $k$. AC代码: #include<bits/stdc++.h> using namespace std; ;…
从这里开始 题目列表 瞎扯 Problem A New Building for SIS Problem B Badge Problem C Elections Problem D The hat Problem E Sergey's problem 瞎扯 例行快速切A.B.C. 然后发现D是交互.E也不像是我能做的题,感觉完蛋了. 最后8分钟想出D.狂码代码,然后比赛结束后1分钟过样例. 第二天早上再花4分钟AC.我真是个大菜逼.. 于是这场cf比赛变成了真·手速场.几个friends手速比我…
Codeforces Round #519 by Botan Investments #include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<queue> #include<vect…