AC code:
#include<bits/stdc++.h>
using namespace std;
int n = 0,m = 0,x = 0,y = 0;
typedef long long LL;
LL ans = 1e18;
multiset<int> v,p[3005];
int main(){
scanf("%d %d",&n,&m);
for(int i = 0;i < n;++i){
scanf("%d %d",&x,&y);
p[x].insert(y);//每一个party所需要的票价
if(x != 1){
v.insert(y);//收买其他人的票价
}
}
int tkn = 0;
LL rem = 0;
for(int i = n;i >= 1;--i){
for(int j = 2;j <= m;++j){
if(p[j].size() < i){//类似于将最大票数控制在i以下
continue;
}
while(p[j].size() >= i){//类似于将最大票数控制在i以下
++tkn; //目前取走的高于 i的票
rem += *(p[j].begin()); //set集合自动排序,取出最小值
v.erase(v.find(*p[j].begin()) );//j不小心写成i了,改了我好久,无语
p[j].erase(p[j].begin());//要先在v里面清除,在再在p里面清除
}
}
LL res = rem;
int cnt = i - (int)p[1].size() - tkn;//这是1与其他政党中票数最多的政党的大小比较
for(auto a : v){
if(cnt <= 0){//cnt<=0说明不需要更多的票数了,否则还需要全局最小票数,来凑数超越第一大党
//其中可能选第一大党的票数,是他的票数-1,效果等价于-2,但是这里贪心没考虐
//但是后面遍历i时,会把这种情况算进去
break;
}
res += a;
--cnt;
}
ans = min(res,ans);
}
printf("%I64d\n",ans);
//cout << ans << endl;
return 0;
}
相关推荐
sap外币重估流程图_SAP 外币评估方法(Valuation Method,评估方法)
在FI-GL模块评估外币时(T-code:F.05),需要输入ValuationMethod。下面分解一下评估方法是如何定义的。IMG -> FI -> General LedgerAccounting ->Business Transactions ->Closing ->Valuating -> ForeignCurrency Valuation ->...
Codeforces Round #503 (by SIS, Div. 2) C. Elections
贪心题
matlab kwave模拟超声换能器学习笔记
kwave模拟超声换能器的学习笔记,从零开始造车轮
Codeforces Round #503 (by SIS, Div. 2) C Elections
地址:http://codeforces.com/contest/1020/problem/C 比赛的时候知道是贪心,不知道怎么贪,其实n的数据是3000,就可以枚举除1号以外的其他人所得到的票数,让其他人的票数都小于i;1号的票数大于i; 将收买价值一排序,每次都贪心的把收买价值较大的,让他们顺利投上他们自己心仪的目标,收买那些收买价值较小的; #include<bits/stdc+...
docker配置国内镜像源
【代码】docker配置国内镜像源。
便携式水下动态实时视频色彩还原设备,一键快速实现对水下偏色视频和图像的色彩还原处理
便携式水下动态实时视频色彩还原,一键快速对水下图像进行色彩校正,清晰度提升和亮度均衡处理,为水下资源勘探和科学考古,海洋生态环境监测,水下机器作业等应用提供有力的协助
Codeforces Round #503 (by SIS, Div. 2) C. Elections(贪心)
题目链接:http://codeforces.com/contest/1020/problem/C 题意描述: 有n个选民, m个政党 (n,m<=3000) ,第i个选民有两个数 pi ,ci (pi<=m, ci<=1e9),表示该选民投票给政党 pi ,但如果你给他 ci 金币,他会改变他的投票对象为政党 1 (政党编号1到m)。 现在要求使得政党 1 票数最...
【WRF-Chem第二期】WRF-Chem有关 namelist 详解
【WRF-Chem第二期】WRF-Chem有关 namelist 详解
Codeforces Round #503 (by SIS, Div. 2)-C. Elections
枚举每个获胜的可能的票数+按照花费排序 #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #define ll long long using namespace std; struct node { int ...
编写python脚本调用ordinals以及BRC20的接口
1、钱包地址生成walletreceive,对应ord命令:ord wallet receive。6、测试手动出块generate,这个只在regtest链节点用得上。所有接口都是post请求,采用postman进行测试。4、测试bitcoin转币sendtoaddress。7、测试其他的wallet方法wallet。2、钱包币种铭刻inscription,对应bitcoin-cli命令。对应bitcoin-cli命令。对应bitcoin-cli命令。fee.json文本模板。还可以加很多根据需要加减。
SKUA-GOCAD入门教程-第六节
DisplayElements窗口是用于浏览和处理项目数据的工具,包含多个数据浏览器,如模型列表、对象、未分类对象、属性数据及资源数据。
Codeforces Round #503 (by SIS, Div. 2) C. Elections(思维)
题目链接:https://codeforces.com/contest/1020/problem/C 题意是有n个政客,m个政党,每个政客都有一个支持的政党,现在想要让1政党成功选举,那么它的条件就是它的票数要大于其他的任意一个政党,现在可以去贿赂政客使他去投1号政党,问最小花费。 一道巧妙的思维题,思路就是枚举1号政党的最终票数,如果有的政党的票数大于1号的...
cuRobo 入门教程(二)基于CUDA的机器人运动规划加速库
cuRobo是一款基于CUDA加速的机器人算法库,提供正向/逆向运动学、碰撞检测、数值优化等核心功能,支持在NVIDIA Jetson Orin等平台上实现毫秒级运动规划。该库创新性地采用并行轨迹优化技术,结合nvblox工具实现深度摄像头避障功能,并通过多层ESDF结构处理动态障碍物。性能测试显示,在RTX 6000 Ada显卡上可实现99.85%的成功率,平均规划时间仅39毫秒。cuRobo还提供Python API支持神经网络集成,并具备批量环境处理能力,特别适用于工业机器人应用场景。最新版本通过算法
Codeforces Round #503 (by SIS, Div. 2) C Elections 暴力枚举贪心
贪心 打的时候思路对 但自己比较菜 码力不足 看了大神的代码 #include<bits/stdc++.h> using namespace std; struct Node{ int p,c; bool operator<(const Node&a)const { return c<a.c; } }node[3005]; int x[3005]; int ...
温度PID控制PLC程序
温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值
C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片
基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正
Codeforces Round #503 (by SIS, Div. 2) C Elections (思维 + 模拟)
题目链接:http://codeforces.com/contest/1020/problem/C 题意:n个人被选举,n个人投票,一开始这n个人都有自己的投票人,但是你可以花钱贿赂这个人,让他改票。你想要1号投票选举胜出。请问最小花费为多少。 题解:题目正常去处理的话 ,正常贪心的很复杂,我们需要考虑,是从比1号少的人中贿赂,还是从比1号多的人去贿赂。思路还是比较复杂的。但是我们可以换个思路...
深度学习工具包 DeepLearningToolbox
深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[](https://bitdeli.com/free "Bitdeli Badge")
Codeforces Round #503 (by SIS, Div. 2) - C. Elections - 枚举+贪心
题目链接、 题意:给你n个人,m个政党,选举,你是1号政党,你想要赢(你的得到的票要大于其他任何一个政党才行), 每个人一开始都会选一个政党,也可以花xi让他投你的票,求你赢的最小花费 思路:枚举你最终的得票,贪最小的花费 对于最终投你票是i张的时候,不投你的有n-i张,将花费从大到小排序 从大到小考虑,统计出现的每个政党次数,当次数大于等于i的时候,你必须花钱买这个人的票了 ...
LinePhone3.2.7(android端最新版本) sip客户端
SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/
Codeforces Round #503 (by SIS, Div. 2) C. Elections
C. Elections As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the f...
C:Elections(枚举+贪心)Codeforces Round #503 (by SIS, Div. 2)
题意: n个人给m个人投票,可以通过钱把其他人的票买过来。。问至少花费多少钱可以使候选人1的票数最多 分析: 枚举每一种可能候选人1最后可能的票数,然后看是否存在所有人的票数小于他的可能,存在找到最小的花费,这个时候需要用到的是贪心的方法,要把钱从小到大排序就好 代码: #include<bits/stdc++.h> using namespace std; const i...
Codeforces Round #503 (by SIS, Div. 2) C. Elections
题目 题意:有n个学生,m个政党,每个学生有支持的政党,但是如果你给他一些钱,他就可以给你想让他投的党投票,现在想付出最少的钱使得1政党有绝对优势(票数严格大于其他党)。 分析:运用一种枚举贪心的思想,枚举胜利的必要条件,就是枚举改变了I个人,就可以达到胜利 #include<cstdio> #include<cstring> #include<io...
Codeforces Round #503 (by SIS, Div. 2) C. Elections (暴力+贪心)
【题目描述】 Elections are coming. You know the number of voters and the number of parties—nandmrespectively. For each voter you know the party he is going to vote for. However, he can easily...
2358


C. Elections&spm=1001.2101.3001.11974&articleId=81709447&d=1&t=3&u=1848a3f7f5134cc6b306d0ba2ef0530e)

被折叠的 条评论
为什么被折叠?



