UVA 10905 Children's Game 孩子们的游戏 【贪心】
2015-10-01 17:45
232 查看
题目链接:
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21354
贪心
将数字转化为字符串,排序函数是bool cmp(string s1, string s2){ return s1+s2 > s2+s1; }
以此保证每两个数字排序后的链接结果都是最优的,最后直接输出即可。
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21354
贪心
将数字转化为字符串,排序函数是bool cmp(string s1, string s2){ return s1+s2 > s2+s1; }
以此保证每两个数字排序后的链接结果都是最优的,最后直接输出即可。
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #include<string> #include<vector> #include<set> #include<queue> #include<map> #include<stack> using namespace std; const int MAXL = 55; string num[MAXL]; int n; bool cmp(string s1, string s2){ // 规定了“小于”的规则 return s1+s2 > s2+s1; } int main(){ while(cin>>n){ if(!n) break; for(int i = 0; i < n; i++) cin>>num[i]; sort(num, num+n, cmp); for(int i = 0; i < n; i++) cout<<num[i]; cout<<endl; } return 0; }
相关文章推荐
- QT 让窗口(或控件)居中
- mysql编码的查看和修改
- PAT1007 素数对猜想(20)
- 骑士走棋盘
- HDU-3826-Squarefree number
- LightOJ 1236 Pairs Forming LCM
- 打造android更加完美的万能adapter
- 变量作用域
- java11:数组试用
- iOS 开发之网络请求
- swift练习二
- 简单缓存的实现
- JAVA基础--db11_java异常_Object类
- CSS样式背景样式
- hdu1133
- Arrays.asList()
- Aizu 2300 Calender Colors(暴力)
- 黑马程序员——java学习笔记--枚举
- UITabBarController详细说明(简介和设置)
- MongoDB聚合整理