1020C Elections】的更多相关文章

传送门 题目大意 现在有 n个人,m个党派,第i个人开始想把票投给党派pi,而如果想让他改变他的想法需要花费ci元.你现在是党派1,问你最少花多少钱使得你的党派得票数大于其它任意党派. 分析 我们枚举i,表示除了自己之外的其它任何党派最多得票数不超过i,而我们每次只需要改变一个党派中需要花费的钱最少的那几个人就行了,在保证其它党派德比得票数都小于i之后如果自己党派的得票小于i,则不断改变需花费钱最少的那一个人的想法就行了.详见代码. 代码 #include<iostream> #include…
大意: 有n个选民, m个党派, 第i个选民初始投$p_i$一票, 可以花费$c_i$改变投票, 求最少花费使得第一个党派的票数严格最大 假设最终第一个党派得票数$x$, 枚举$x$, 则对于所有票数$\ge x$的党派, 贪心选择尽量小的c改选第一个党派.若最后票数还不够, 再从没改过的人中选择尽量小的改选即可 #include <iostream> #include <algorithm> #include <cstdio> #include <vector&…
题目: 党派竞争投票 有n个人,m个党派,这n个人每个人有一个想要投的党派的编号Pi,如果想要这个人改变他的想法,那么就需要花费Ci元钱. 现在你是编号为1的党派,如果你想要赢(你的票数严格大于其他党派的票数),需要花费的最少的钱是多少. 思路: 将每个人按花费从小到大排序,从0到n枚举获胜需要的票数,遍历所有要投票的人,如果他要投的党派的票数大于当前枚举的票数,就把这个人的票给买过来,最后取所有花费中最小的那个就可以了. 爆int…… 代码: #include <bits/stdc++.h>…
                                                A. Bear and Elections                                                                                                                                                                            time limi…
C. Valera and Elections   The city Valera lives in is going to hold elections to the city Parliament. The city has n districts and n - 1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's…
[CF850E]Random Elections(FWT) 题面 洛谷 CF 题解 看懂题就是一眼题了... 显然三个人是等价的,所以只需要考虑一个人赢了另外两个人就好了. 那么在赢另外两个人的过程中,一定是两个长度为\(2^n\)的二进制串的对应值都是\(1\). 考虑每个人投票的贡献,如果是\(00\)或者\(11\)那么有两种排列,如果是\(01\)或者\(10\)就只有一种合法排列. 那么对于长度为\(2^n\)的数组自己对自己做一次异或卷积,每个数的贡献就是\(2\)的\(0\)的个数…
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(),…
[CF850E]Random Elections 题意:有n位选民和3位预选者A,B,C,每个选民的投票方案可能是ABC,ACB,BAC...,即一个A,B,C的排列.现在进行三次比较,A-B,B-C,C-A.每次比较的结果由一个给定的函数决定$f(x):{0,1}^n\rightarrow {0,1}$,即读入一个长度为n的bool数组,返回一个bool变量.假如是A和B比较,则读入数组的第i个bool是 第i个人的排列中,A是否在B的前面:返回的bool是 A获胜还是B获胜.现在给你函数f(…
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…
题目链接: 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…
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.…
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行)数位…
UVA 11748 - Rigging Elections option=com_onlinejudge&Itemid=8&page=show_problem&category=599&problem=2848&mosmsg=Submission+received+with+ID+14103876" target="_blank" style="">题目链接 题意:n个人选举,给出m个人的投票人对于每一个人的优…
Valera and Elections 题意:现在有n个候选人, 有n-1条路, 如果选择了这个候选人, 这个候选人就会将从自己这个城市到1号城市上所有坏的路都修复一下,现在求最小的候选人数目, 如果答案有多种情况输出任何一种都可以. 输入:x y k 表示x与y之间有一条双向通道, k==1 表示这路是好的, k == 2表示这条路是坏的. 题解: 从1开始dfs搜索, 往外走, 如果遇到坏的城市就标记一下, 然后继续往外走, 如果更远的地方有一个坏的路就用更远地方的城市候选人代替这个标记的…
题目描述: 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…
[题目描述] 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. 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…
Codeforces Round #318 居然可以看测试数据,哪里没过一目了然,哈哈哈 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<map> using namespace std; #define MOD 1000000007 cons…
数位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]…
http://codeforces.com/contest/369/problem/C 先见边,然后dfs,在回溯的过程中,如果在这个点之后有多条有问题的边,就不选这个点,如果没有而且连接这个点的边还是有问题的边,这个点就是所求的点. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 200000 using namespace std; int head[maxn],e,cnt…
题目: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…
给出1,2,3...m 任取7个互不同样的数a1,a2,a3,a4,a5,a6,a7 一个数的幸运度是数位上4或7的个数 比方244.470幸运度是2. 44434,7276727.4747,7474,幸运度都是4. 求出满足a1,a2,a3,a4,a5,a6,a7这种前6个数的幸运度之和严格小于第七个数的幸运度排列共同拥有多少种 1.先求出数组t t[i]代表1-m中幸运度为i的数的个数. 2.有了t数组后.问题变为一个排列组合问题(枚举a7幸运度.求有多少排列满足前6幸运度之和小于a7幸运度…
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),…
题目链接:codeforces 850E 翻译:luogu 读题是第一要务(大选这么随便真的好吗) 其实答案问你的就是在所有选民心中支持的人的所有情况中,能让一个人连赢两场的情况数是多少 我们假设\(A\)赢了\(B\)和\(C\),最后将答案\(\times 3\)即可 再记\(A\)赢\(B\)时的\(01\)串为\(S_1\),\(A\)赢\(C\)时的\(01\)串为\(S_2\),那么对于这两个串的第\(i\)位与该选民的支持情况的对应有如下\(4\)种情况 1)\((0,0)\),此…
枚举每个获胜的可能的票数+按照花费排序 #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; } ]; ];…
链接 [http://codeforces.com/contest/1043/problem/A] 题意 有n个投票人已经投个对手ai票,让你求最小的k使得k-ai加起来大于,对手得票总和 分析 一个个往后枚举即可 代码 #include<bits/stdc++.h> using namespace std; #define ll long long int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,…
http://codeforces.com/problemset/problem/369/C 树的遍历,dfs搜一下,从根节点搜到每个分叉末尾,记录一下路况,如果有需要修复的,就把分叉末尾的节点加入答案 10w个点要用邻接表存图 #include <iostream> using namespace std ; typedef struct L{ int s,t ; int v ; int nxt ; }L ; L e[] ; ] ; int cnt ; void ins(int s,int…
题目大意:有$n$个人,$m$个政党,每个人都想投一个政党,但可以用一定的钱让他选你想让他选的政党. 现在要$1$号政党获胜,获胜的条件是:票数严格大于其他所有政党.求最小代价 题解:暴力枚举其他政党的最多得票,然后把超过的贪心收买,若$1$号政党得票不够,就继续贪心收买,更新答案,复杂度$O(n^2 \log_2 n)$($n=3000,time\;limit=2s$卡过) 卡点:1.用$pb\_ds$的$priority\_queueTIL$,换成$std:priority\_queueAC…