UVa 10905 - Children's Game 排序,题目没有说输入是int 难度: 0
题目
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1846
题意
n个数字按照字符串方式直接组合成大数字,问最大组合成多少
思路
排序
感想
1. 因为脑洞的原因以为只要把所有数的数位填到一样长就好了,比如27,273,72,723把27填到272,72填到727,就能把它们顺利排出来。结果这样无法区别345, 3453这种情况和543, 5435这种情况。总之为了这种脑洞花费了过多时间。
2. 后来对每个元素x,按照x / (basex - 1)排序
3. 最后发现每个元素可能非常长。。。
代码
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#define LOCAL_DEBUG
using namespace std;
typedef pair<double, long long> MyPair;
const int MAXN = ;
long long base[];
string a[MAXN];
bool cmp(string s1, string s2) {
return s1 + s2 < s2 + s1;
} int main() {
#ifdef LOCAL_DEBUG
freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\input.txt", "r", stdin);
freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\output.txt", "w", stdout);
#endif // LOCAL_DEBUG
int T;
base[] = ;
for (int i = ; i < ; i++)base[i] = base[i - ] * ;
int n;
for (int ti = ;cin>>n && n; ti++) {
for (int i = ; i < n; i++) {
cin >> a[i];
}
sort(a, a + n, cmp);
for (int i = n - ; i >= ;i--) {
cout << a[i];
}
cout << endl;
} return ;
}
UVa 10905 - Children's Game 排序,题目没有说输入是int 难度: 0的更多相关文章
- uva 10905 Children's Game (排序)
题目连接:uva 10905 Children's Game 题目大意:给出n个数字, 找出一个序列,使得连续的数字组成的数值最大. 解题思路:排序,很容易想到将数值大的放在前面,数值小的放在后面.可 ...
- UVA 10905 Children's Game 孩子的游戏 贪心
题意:给出N个数,要求把它们拼凑起来,让得到的数值是最大的. 只要分别比较两个数放前与放后的值的大小,排序后输出就可以了. 比如123和56,就比较12356和56123的大小就行了. 写一个比较函数 ...
- 【字符串排序,技巧!】UVa 10905 - Children’s Game
There are lots of number games for children. These games are pretty easy to play but not so easy to ...
- UVA 10905 Children's Game (贪心)
Children's Game Problem Description There are lots of number games for children. These games are pre ...
- UVa 10905 - Children's Game(求多个正整数排列后,所得的新的数字的极值)
4thIIUCInter-University Programming Contest, 2005 A Children’s Game Input: standard input Output: st ...
- UVa 10905 Children's Game
注意!这不是单纯的字典序排序,比如90.9,应该是990最大 对字符串排序蛋疼了好久,因为别人说string很慢,所以一直没有用过. 看别人用string还是比较方便的,学习一下 对了,这里的cmp函 ...
- UVA 10905 Children's Game (贪心)
贪心,假如任意给出一个序列,如果两两交换了以后会变大,那么就交换,直到不能交换为止. #include<bits/stdc++.h> using namespace std; ; stri ...
- UVa 10382 - Watering Grass 贪心,水题,爆int 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVA 1572 Self-Assembly(拓扑排序)
1 // 把一个图的所有结点排序,使得每一条有向边(u,v)对应的u都排在v的前面. 2 // 在图论中,这个问题称为拓扑排序.(toposort) 3 // 不难发现:如果图中存在有向环,则不存在拓 ...
随机推荐
- js回溯法计算最佳旅行线路
假如有 A,B,C,D四个城市,他们之间的距离用 G[V][E] 表示,为 无穷大,则表示两座城市不相通 现在从计算从某一个城市出发,把所有的城市不重复旅行一次,最短路径 其中G为: (Infinit ...
- Python基础(九) type元类
python元类:type() 元类是python高阶语法. 合理的使用可以减少大量重复性的代码. 元类实际上做了以下三方面的工作: 干涉创建类的过程 修改类 返回修改之后的类 为什么使用元类? ...
- laravel框架基础(2)---laravel项目加载机制
当我们,通过浏览器请求laravel的时候 laravel就会根据我们的请求链接来选择对应的方法执行并返回我们所需要的实际结果. 那么这个过程是怎样的呢? 1.生命周期 2018-12-28 17:0 ...
- db2空值、null
1. 输入参数为字符类型,且允许为空的,可以使用COALESCE(inputParameter,'')把NULL转换成''; 2. 输入类型为整型,且允许为空的,可以使用COALESCE(inputP ...
- TP无限回复
引入文件和css样式 <script src="__PUBLIC__/bootstrap/js/jquery-1.11.2.min.js"></script> ...
- Spring Boot IoC 容器初始化过程
1. 加载 ApplicationContextInializer & ApplicationListener 2. 初始化环境 ConfigurableEnvironment & 加 ...
- 文件夹放到VS2015显示不出来
在该项目中,点这个按钮 , 会显示没有包括进项目的文件 在要包括的文件上右键--包括在项目中即可 同理也可以从项目排除
- 软件工程实践小项目之模拟wc.exe的小程序
github源码和工程文件地址:https://github.com/Jackchenyu/Word_counts/tree/smart 基本要求:要实现wc的基本功能即文件中字符数.单词数.行数的统 ...
- 正则表达式 re.findall 用法
正则 re.findall 的简单用法(返回string中所有与pattern相匹配的全部字串,返回形式为数组)语法: findall(pattern, string, flags=0) import ...
- Centos7.4配置虚拟环境
environment Centos7.4 Python3.7 download pip isntall virtualenv create environment virtualenv enviro ...