Codeforces 994B. Knights of a Polygonal Table
解题思路
- 将骑士按力量从小到大排序,到第i个骑士的时候,前面的i-1个骑士他都可以击败,找出金币最多的k个。
- 用multiset存金币最多的k个骑士的金币数,如果多余k个,则删除金币数最小的,直到只有k个数字。
我就是因为没有用multiset在最后5分钟被hack了。
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k;
//输入,p表示力量,c表示金币,idx表示输入时的位置
struct node{
ll p;ll c;int idx;
}a[500050];
bool cmp(node x, node y){
return x.p < y.p;
}
ll ans[500050];
int main(){
ios::sync_with_stdio(false);
cin >> n >> k;
//输入并按力量从小到大排序
for(int i = 1;i <= n; ++i) cin >> a[i].p, a[i].idx = i;
for(int i = 1;i <= n; ++i) cin >> a[i].c;
sort(a+1,a+1+n,cmp);
multiset <int> s; //存第i个骑士可以击败的不超过k个骑士的金币数
for(int i = 1;i <= n; ++i){
ans[a[i].idx] = a[i].c;
for(auto t:s){
ans[a[i].idx] += t;
}
s.insert(a[i].c);
//如果将第i个骑士的金币数插入之后大于k个数字,就删除到只有k个
while(s.size() > k){
s.erase(s.begin());
}
}
for(int i = 1;i <= n; ++i) cout << ans[i] << " ";
cout << endl;
return 0;
}
Codeforces 994B. Knights of a Polygonal Table的更多相关文章
- CodeForces 994B Knights of a Polygonal Table(STL、贪心)
http://codeforces.com/problemset/problem/994/B 题意: 给出n和m,有n个骑士,每个骑士的战力为ai,这个骑士有bi的钱,如果一个骑士的战力比另一个骑士的 ...
- [C++]Knights of a Polygonal Table(骑士的多角桌)
[程序结果:用例未完全通过,本博文仅为暂存代码之目的] /* B. Knights of a Polygonal Table url:http://codeforces.com/problemset/ ...
- CF994B Knights of a Polygonal Table 第一道 贪心 set/multiset的用法
Knights of a Polygonal Table time limit per test 1 second memory limit per test 256 megabytes input ...
- Knights of a Polygonal Table CodeForces - 994B (贪心)
大意:n个骑士, 每个骑士有战力p, 钱c, 每个骑士可以抢战力比他低的钱, 每个骑士最多抢k次, 对每个骑士求出最大钱数 按战力排序后, 堆维护动态前k大即可 #include <iostre ...
- [CF994B] Knights of a Polygonal Table - 贪心,堆
有 n 个骑士想决战.每个骑士都有能力值(互不相同),且身上带有一些金币.如果骑士 A 的能力值大于骑士 B ,那么骑士 A 就可以杀死骑士 B ,并获得骑士 B 身上的所有金币.但就算是骑士也不会残 ...
- POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 12439 Acce ...
- POJ 2942 Knights of the Round Table
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 10911 Acce ...
- poj 2942 Knights of the Round Table 圆桌骑士(双连通分量模板题)
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 9169 Accep ...
- 【LA3523】 Knights of the Round Table (点双连通分量+染色问题?)
Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in distress ...
随机推荐
- pwiz, a model generator
文档链接 pwiz is a little script that ships with peewee and is capable of introspecting an existing data ...
- 页面footer在底部
页脚动态贴在底部需要满足以下两个条件: 当主体的内容高度不超过可视区域高度的时候,页脚贴在页面底部. 当主体的内容高度超过可视区域高度的时候,页脚将按正常布局. 方法一:footer高度固定+绝对定位 ...
- 一系列令人敬畏的.NET核心库,工具,框架和软件
内容 一般 框架,库和工具 API 应用框架 应用模板 身份验证和授权 Blockchain 博特 构建自动化 捆绑和缩小 高速缓存 CMS 代码分析和指标 压缩 编译器,管道工和语言 加密 数据库 ...
- 【BZOJ3451】Tyvj1953 Normal - 点分治+FFT
题目来源:NOI2019模拟测试赛(七) 非原题面,题意有略微区别 题意: 吐槽: 心态崩了. 好不容易场上想出一题正解,写了三个小时结果写了个假的点分治,卡成$O(n^2)$ 我退役吧. 题解: 原 ...
- [poj 3539] Elevator (同余类bfs)
Description Edward works as an engineer for Non-trivial Elevators: Engineering, Research and Constru ...
- docker 命令部分
本文只记录docker命令在大部分情境下的使用,如果想了解每一个选项的细节,请参考官方文档,这里只作为自己以后的备忘记录下来. 根据自己的理解,总的来说分为以下几种: 看一个变迁图 看一个变迁图 ...
- cliendataset中自增长字段的处理
cliendataset中自增长字段的处理: id:自增长字段. 在client中的处理方法:clientdataset.Fields.FieldByName('id').ReadOnly:=Fals ...
- codevs——T1576 最长严格上升子序列
http://codevs.cn/problem/1576/ 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Descr ...
- SDUT 1225-编辑距离(串型dp)
编辑距离 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 如果字符串的基本操作仅为:删除一个字符.插入一个字符和将一个字符改动 ...
- JavaScript、SSH知识点整理
七.Javascript部分 1:什么是Javascript JavaScript是一种基于对象(Object)和事件驱动(Event Driven)并具有安全性能的脚本语言. 2:Java和Java ...