Codeforces Round #193 (Div. 2)
来源:互联网 发布:淘宝幸运抽奖 编辑:程序博客网 时间:2024/06/05 00:25
题意:
在n个规则中选择p个,每个规律不遵守的话,议员会有一定的愤怒值b,遵守的话,主席会有一定的白头发a。然后主席会在p个中选k个去遵守,主席的选择一定是要让议员的愤怒值最小的,其次才是自己的白头发。
问你这p个规则怎么选。
POINT:
先给n个规则从b小,在a大的顺序来排,那么前p-k个肯定是b很小,每次选这个规则,都会让主席去不遵守--来让愤怒值最小。
所以这几个规则是主席不考虑遵守的。
在这个基础上,在去排[p-k+1,n]个规则,从a大,b大来排。前k个就是最优的遵守规则。
然后在根据题意找出p-k个就好了。
时刻记住:我们是强迫主席去选愤怒小的,然后留下的却是头发最多的。
#include <iostream>#include <stdio.h>#include <algorithm>using namespace std;const int maxn = 1e5+123;struct node{ int a,b; int f; int ff;}a[maxn];bool cmd1(node a,node b){ if(a.b!=b.b) return a.b<b.b; return a.a>b.a;}bool cmd2(node a,node b){ if(a.a!=b.a) return a.a>b.a; return a.b>b.b;}struct n1{ int b,f,a;}b[maxn];bool cmd3(n1 a,n1 b){ if(a.b!=b.b) return a.b>b.b; return a.a>b.a;}int main(){ int n,k,p; scanf("%d %d %d",&n,&p,&k); for(int i=1;i<=n;i++){ scanf("%d %d",&a[i].a,&a[i].b); a[i].f=i; a[i].ff=0; } sort(a+1,a+1+n,cmd1); sort(a+p-k+1,a+1+n,cmd2); int Minb=1e9+2; int Mina; int ans[maxn]; int cnt=0; int num=0; for(int i=p-k+1;i<=p;i++){ ans[++cnt]=a[i].f; a[i].ff=1; if(Minb>a[i].b){ Minb=a[i].b; Mina=a[i].a; } } for(int i=1;i<=n;i++){ if(a[i].ff!=1){ b[++num].b=a[i].b; b[num].f=a[i].f; b[num].a=a[i].a; } } sort(b+1,b+1+num,cmd3); for(int i=1;i<=num;i++){ if(cnt==p){ break; } if(Minb==b[i].b&&b[i].a<Mina) continue; if(Minb>=b[i].b){ ans[++cnt]=b[i].f; } } for(int i=1;i<=cnt;i++){ if(i-1) printf(" "); printf("%d",ans[i]); }}
阅读全文
0 0
- Codeforces Round #193 (Div. 2)
- Codeforces Round #193 (Div. 2)
- Codeforces Round #193 (Div. 2)
- Codeforces Round #193 (Div. 2)总结
- Codeforces Round #193 (Div. 2) ABCD
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #107 (Div. 2)
- Codeforces Round #108 (Div. 2)
- Codeforces Round #110 (Div. 2)
- Codeforces Round #122 (Div. 2)
- Codeforces Round #121 (Div. 2)
- Codeforces Round #124 (Div. 2)
- Codeforces Round #124 (Div. 2)
- 考试易错点&&注意事项
- 严蔚敏数据结构——算法2.7改进
- Java数组越界错误:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 15
- 面试经验
- 数据结构——线性结构(9)——Vector的实现过程详解
- Codeforces Round #193 (Div. 2)
- FPGA自动售货机设计
- JavaScript 基础学习01
- 《每天学一个设计模式》 之 策略模式
- ccleaner后门完全分析报告
- 网络(HTTP与HTTPS的区别)
- 数据库中存储过程语法
- staticmethod和classmethod的区别
- swing 实现计算器