解题思路

  1. 将骑士按力量从小到大排序,到第i个骑士的时候,前面的i-1个骑士他都可以击败,找出金币最多的k个。
  2. 用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的更多相关文章

  1. CodeForces 994B Knights of a Polygonal Table(STL、贪心)

    http://codeforces.com/problemset/problem/994/B 题意: 给出n和m,有n个骑士,每个骑士的战力为ai,这个骑士有bi的钱,如果一个骑士的战力比另一个骑士的 ...

  2. [C++]Knights of a Polygonal Table(骑士的多角桌)

    [程序结果:用例未完全通过,本博文仅为暂存代码之目的] /* B. Knights of a Polygonal Table url:http://codeforces.com/problemset/ ...

  3. 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 ...

  4. Knights of a Polygonal Table CodeForces - 994B (贪心)

    大意:n个骑士, 每个骑士有战力p, 钱c, 每个骑士可以抢战力比他低的钱, 每个骑士最多抢k次, 对每个骑士求出最大钱数 按战力排序后, 堆维护动态前k大即可 #include <iostre ...

  5. [CF994B] Knights of a Polygonal Table - 贪心,堆

    有 n 个骑士想决战.每个骑士都有能力值(互不相同),且身上带有一些金币.如果骑士 A 的能力值大于骑士 B ,那么骑士 A 就可以杀死骑士 B ,并获得骑士 B 身上的所有金币.但就算是骑士也不会残 ...

  6. POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 12439   Acce ...

  7. POJ 2942 Knights of the Round Table

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 10911   Acce ...

  8. poj 2942 Knights of the Round Table 圆桌骑士(双连通分量模板题)

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 9169   Accep ...

  9. 【LA3523】 Knights of the Round Table (点双连通分量+染色问题?)

    Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in distress ...

随机推荐

  1. 基于SLIC分割的特征点检测

    一:pipeLIne (1):基于模型的pose估计综述: 对于一个3D模型,可以投影到平面,得到不同的位姿,而pose识别是利用所见的2.5D图像,来估计模型,并同时识别出位姿. 3D模型投影时注意 ...

  2. -1.#IND000 &&图像类型转换

    (1):float acos(float x) 参数x的范围为-1.0f到1.0f之间,返回值范围在0.0f到3.141592653f之间,值得注意的是:当x超出[-1.0f,1.0f]这个范围时此函 ...

  3. PLSQL 11注册码

    plsql 11 注册码:Product Code:4t46t6vydkvsxekkvf3fjnpzy5wbuhphqzserial Number:601769 password:xs374ca

  4. 如何快速在命令提示符(cmd)中打开指定的文件夹路径!

    按住shift键然后 右击,如图:

  5. apicloud开发方法。

    1.前端布局 window frame 子窗口 franmegroup  子窗口组. 一个页面比如有一个固定的顶部,然后中间区域是商品或者是什么内容,那么这个整体就是一个window,那么中间的就是i ...

  6. BZOJ 1355: [Baltic2009]Radio Transmission AC自动机/KMP

    被一个KMP傻题搞蒙圈了,此题AC自动机空间超限,只能用KMP写(我只会AC自动机QAQ)...... AC自动机 Code: // luogu-judger-enable-o2 #include & ...

  7. 【转载】springboot注解

    https://blog.csdn.net/yitian_66/article/details/80866571 springboot注解:@Service: 注解在类上,表示这是一个业务层bean@ ...

  8. Project Euler 30 Digit fifth powers

    题意:判断一个数 N 的每一位的5次方的和是否为其本身 ,求出所有满足条件的数的和 思路:首先设这个数 N 为 n 位,可以简单的判断一下这个问题的上界 10 ^ n <= 9 ^ 5 × n, ...

  9. [luogu2052 NOI2011] 道路修建 (树形dp)

    传送门 Description 在 W 星球上有 n 个国家.为了各自国家的经济发展,他们决定在各个国家 之间建设双向道路使得国家之间连通.但是每个国家的国王都很吝啬,他们只愿 意修建恰好 n – 1 ...

  10. SpringMVC的DispatcherServlet加载过程

    首先在web.xml中配置容器启动监听器,这样在容器启动后Spring会初始化一个ServletContext,负责加载springmvc的九大组件(调用DispatcherServlet.onRef ...