【Luogu】【关卡2-3】排序(2017年10月) 【AK】
任务说明:将杂乱无章的数据变得有规律。有各种各样的排序算法,看情况使用。
这里有空还是把各种排序算法总结下吧。qsort需要会写。。
P1177 【模板】快速排序
这个题目懒得写了,直接sort了...
以后要补上..
sort版本可以忽略了orz
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <algorithm> 5 6 using namespace std; 7 8 int main() { 9 int N; 10 cin >> N; 11 vector<int> vec(N); 12 for (int i = 0; i < N; ++i) { 13 cin >> vec[i]; 14 } 15 sort(vec.begin(), vec.end()); 16 if (N > 0) { 17 printf("%d", vec[0]); 18 for (int i = 1; i < N; ++i) { 19 printf(" %d", vec[i]); 20 } 21 printf("\n"); 22 } 23 return 0; 24 25 }
View Code
P1059 明明的随机数
要求排序+去重
我直接sort -> unique -> resize 了...
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <algorithm> 5 6 using namespace std; 7 8 int main() { 9 int N; 10 cin >> N; 11 vector<int> vec(N); 12 for (int i = 0; i < N; ++i) { 13 cin >> vec[i]; 14 } 15 sort(vec.begin(), vec.end()); 16 auto iter = unique(vec.begin(), vec.end()); 17 vec.resize(std::distance(vec.begin(), iter)); 18 printf("%d\n", vec.size()); 19 if (N > 0) { 20 printf("%d", vec[0]); 21 for (int i = 1; i < vec.size(); ++i) { 22 printf(" %d", vec[i]); 23 } 24 printf("\n"); 25 } 26 return 0; 27 28 }
View Code
P1068 分数线划定
感觉比模拟题还水,忽略吧
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <algorithm> 5 #include <utility> 6 7 using namespace std; 8 9 typedef pair<int, int> P; 10 11 bool cmp(P p1, P p2) { 12 if (p1.second != p2.second) { 13 return p1.second > p2.second; 14 } else { 15 return p1.first < p2.first; 16 } 17 } 18 19 20 int main() { 21 int n, m; 22 cin >> n >> m; 23 const int bar = m * 3 / 2 ; 24 //printf("bar = %d \n", bar); 25 26 vector<P> vec(n); 27 for (int i = 0; i < n; ++i) { 28 cin >> vec[i].first >> vec[i].second; 29 } 30 sort(vec.begin(), vec.end(), cmp); 31 if (bar == 0) { 32 printf("0\n"); 33 return 0; 34 } 35 const int score = vec[bar-1].second; 36 //printf("score = %d \n", score); 37 int idx = bar-1; 38 while(idx < n && vec[idx].second == score) { 39 ++idx; 40 } 41 //printf("final idx = %d \n", idx); 42 printf("%d %d\n", score, idx); 43 for(int i = 0; i < idx; ++i) { 44 printf("%d %d\n", vec[i].first, vec[i].second ); 45 } 46 47 return 0; 48 }
View Code
P1781 宇宙总统
候选人有编号和选票,输出最大票数候选人的编号和选票。因为选票很大,所以不能用long long型。用string类型来比较。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <algorithm> 5 #include <utility> 6 #include <string> 7 #include <cstring> 8 9 using namespace std; 10 11 typedef pair<int, int> P; 12 13 int main() { 14 int n; 15 cin >> n; 16 vector<string> vec(n); 17 string str; 18 for (int i = 0 ; i < n; ++i) { 19 cin >> str; 20 vec[i] = str; 21 } 22 string strMax = vec[0]; 23 int ansIdx = 0; 24 for (int i = 1; i < n; ++i) { 25 if (vec[i].size() > strMax.size()) { 26 strMax = vec[i]; 27 ansIdx = i; 28 } else if (vec[i].size() == strMax.size() && vec[i] > strMax) { 29 strMax = vec[i]; 30 ansIdx = i; 31 } 32 } 33 cout << ansIdx+1 << endl; 34 cout << strMax << endl; 35 return 0; 36 }
View Code
转载于:https://www.cnblogs.com/zhangwanying/p/7634658.html
【Luogu】【关卡2-3】排序(2017年10月) 【AK】相关推荐
- 数学分析高等代数考研试题荟萃[更新至2017年10月1日]
数学分析高等代数考研试题荟萃[更新至2017年10月1日], 需要的话见: http://www.followmath.com/forum.php?mod=viewthread&tid=469 ...
- 2017年10月31日结束Outlook 2007与Office 365的连接
2017 年10月31日 ,微软即将推出 Office 365中Exchange Online邮箱将需要Outlook for Windows的连接,即通过HTTP Over MAPI方式,传统使用R ...
- 2017年含金量最高的机器学习技能或知识有哪些? 翻译 2017年10月20日 14:22:44 标签: 机器学习 / quora 7504 原文:As of 2017, what set of
2017年含金量最高的机器学习技能或知识有哪些? 翻译 2017年10月20日 14:22:44 标签: 机器学习 / quora / 7504
- 从CNN视角看在自然语言处理上的应用 原创 2017年10月24日 00:00:00 1339 作者 | 卞书青 卷积神经网络(Convolutional Neural Network)最早是应用在
从CNN视角看在自然语言处理上的应用 原创 2017年10月24日 00:00:00 标签: 1339
- 获香港证监会颁发牌照的弘量研究,正用智能投顾帮助金融机构降低成本,提升资产管理能力 By 藤子2017年10月09日 17:16 撰文 | 藤子 2015 年,雷春然和黄耀东都是在香港科技大学的
获香港证监会颁发牌照的弘量研究,正用智能投顾帮助金融机构降低成本,提升资产管理能力 By 藤子2017年10月09日 17:16 撰文 | 藤子 2015 年,雷春然和黄耀东都是在香港科技大学的图书馆 ...
- VS Code 1.18版本更新内容整理(2017年10月 October 2017)
VS Code 1.18版本更新内容整理(2017年10月 October 2017) 久前开始使用的VS Code,使用一段时间以后确实感觉比之前在用的Sublime Text好很多,可能是汉化及插 ...
- SSL2811 2017年10月30日提高组T2 摘Galo(树形dp)
2017年10月30日提高组T2 摘Galo Description 0v0在野外看到了一棵Galo树,看到食物的0v0瞪大了眼睛,变成了OvO. 这棵Galo树可以看做是一棵以1号点为根的n个点的有 ...
- 2017年10月历史文章汇总
2017年10月历史文章汇总 2017-11-01 机器学习研究会 机器学习研究会 25610017年1月历史文章汇总 2017年2月历史文章汇总 2017年3月历史文章汇总 2017年4月历史文章汇 ...
- 下列不属于未来发展的计算机技术是,计算机系统结构自考2017年10月真题
计算机系统结构自考2017年10月真题及答案解析 本试卷为选择题型,填空题,简答题,应用题等题型. 一.单项选择题在每小题列出的四个备选项中只有一个是符合题目要求的,请将其代码填写在题后的括号内.错选 ...
- 极光大数据:2017年10月主流共享单车app运营报告(附下载)
报告下载:添加199IT官方微信[i199it],回复关键词[2017年10月主流共享单车app运营报告] 共享单车行业经历了一轮爆发式增长后,出现了马太效应,第一梯队的ofo摩拜越战越勇,而落后者则 ...
最新文章
- JavaScript强化教程——JavaScript 运算符
- js-new、object.create、bind的模拟实现【转载备忘】
- Docker Review - 使用docker volume数据卷实现容器内的数据与宿主机同步
- 计算机蠕虫的存在形式,计算机蠕虫
- H264 介绍[1]
- windows 2008 开机启动 Docker Toolbox 并运行容器
- 安卓与ios都是linux,随便来说两句,安卓、IOS不是那么容易被取代的
- 一加将于10月14日推出新款Buds系列真无线耳塞
- Codeforces Round #321 (Div. 2)
- 华为交换机的端口hybrid端口属性配置
- 面向对象(程序员最呆的地方,一切皆是对象)
- 戴尔:未来就绪的IT
- 手机闹钟软件测试用例,手机app测试用例.docx
- CRC循环冗余校验码
- windows7下制作苹果U盘启动盘
- SIEBEL基础学习
- 清音驱腐启鸿蒙,中华成语千句文解释.doc
- 690家门店送万份小食 汉堡王“战舰世界堡胃战”活动开启
- UOJ#192. 【UR #14】最强跳蚤
- 机器学习之模型评估方法总结