普及练习场 排序Ex 瑞士轮
2017-12-14 21:41
211 查看
题目链接
比赛前分数是有序的,在比完之后,胜者组应该还是有序的,败者组应该还是有序的,因此用merge。
欢迎加入“不会算法一群菜鸟”,群号是⑥⑥①⑨②2025,这是我设置的一道很低的门槛用来阻止广告的。入群的验证暗号是:我爱编译原理
题意理解
这题我用Java写报RE,我当时不能理解,下载了数据一看,结果是对的啊,于是猜测是不是TLE了。。。然后就拿cpp重写了一下。果然,不仅测试用例多过掉了一个,之前报RE的也都变成TLE了。。。当然之前都是用的最简单粗暴的方式写的,但是这题数据量稍微有点大,不能简单粗暴,为此,需要针对这一题的内容,进行针对性优化排序算法。最后,我选择了用cpp写这题,但是为了补一下Java的知识,我决定还是去查一下吧。。。我想想要不要用Java重写一下。后来我查了一下,发现Java的sort就是merge sort,只能说明Java真的太慢了而不是我代码写的不好。 我写cpp真的不是因为我懒!!! 等我有时间还是重新写一个Java版本的merge吧。比赛前分数是有序的,在比完之后,胜者组应该还是有序的,败者组应该还是有序的,因此用merge。
代码
#include <cstring> #include <iostream> #include <cmath> #include <stdio.h> #include <stdlib.h> #include <string> #include <iomanip> #include <vector> #include <algorithm> using namespace std; void read(int &x) { x = 0; int f = 1; char ch = getchar(); while(ch > '9'||ch < '0') { if(ch == '-') { f = -1; } ch = getchar(); } while(ch >= '0' && ch <= '9') { x = x * 10 + (int)(ch - 48); ch = getchar(); } x = x * f; } const int maxn = 200050; typedef struct { int score; int strength; int index; } Player; Player players[maxn]; Player a1[maxn]; Player a2[maxn]; int cmp(Player p1, Player p2) { if(p1.score == p2.score) { return p1.index < p2.index; } else { return p1.score > p2.score; } } int main() { int N, R, Q; read(N); read(R); read(Q); for(int i = 0; i < 2 * N; i++) { read(players[i].score); players[i].index = i + 1; } for(int i = 0; i < 2 * N; i++) { read(players[i].strength); } sort(players, players + 2 * N, cmp); for(int i = 0; i < R; i++) { for(int j = 0; j < 2 * N; j += 2) { if(players[j].strength > players[j+1].strength) { players[j].score++; a1[j / 2] = players[j]; a2[j / 2] = players[j + 1]; } else { players[j+1].score++; a1[j / 2] = players[j + 1]; a2[j / 2] = players[j]; } } merge(a1, a1 + N, a2, a2 + N, players, cmp); } cout << players[Q - 1].index << endl; return 0; }
欢迎加入“不会算法一群菜鸟”,群号是⑥⑥①⑨②2025,这是我设置的一道很低的门槛用来阻止广告的。入群的验证暗号是:我爱编译原理
相关文章推荐
- 普及练习场 排序Ex 魔法照片
- 普及练习场之排序Ex
- 普及练习场 排序Ex 谁拿了最多奖学金
- 普及练习场 排序Ex 奖学金
- 普及练习场 排序 分数线划定
- 普及练习场 排序 宇宙总统
- 普及练习场 贪心EX 皇后游戏
- 普及练习场之排序
- 普及练习场 贪心EX 木棍加工
- 普及练习场 排序 【模板】快速排序
- 普及练习场 排序 明明的随机数
- |洛谷|排序|P1309 瑞士轮
- NOIP2011 普及组 T3 洛谷P1309 瑞士轮
- Problem F: 瑞士轮(快速排序过不了)
- NOIP2011普及组 瑞士轮(分治)
- (NOIP 普及2011) 瑞士轮
- 普及练习场 线性数据结构 约瑟夫问题
- 普及练习场 线性动态规划 合唱队形
- 普及练习场 多维动态规划 Likecloud-吃、吃、吃
- 普及练习场 普及常见模板 【模板】线性筛素数