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对象属性名驼峰式转下划线
一.题目示例: 思路: 1.匹配属性名字符串中的大写字母和数字 2.通过匹配后的lastIndex属性获取匹配到的大写字母和数字的位置 3.判断大写字母的位置是否为首位置以及lastIndex是否为0 ...
- Archlinux软件包管理pacman基本使用说明
熟悉APT和YUM包管理的应该都知道,这两个包管理的使用命令都是采用"主命令+参数"的格式,比如"sudo apt-get install --reinstall pac ...
- HDU 1160
FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take ...
- spring boot + vue + element-ui全栈开发入门——集成element-ui
一.IDE开发工具 常用的开发工具有webstorm和sublime. 我个人喜好用Atom+插件的形式 打开Atom,在file --> settings --> packages中收 ...
- 创建react项目的几种方法
前言: 构建React项目的几种方式: 构建:create-react-app 快速脚手架 构建:generator-react-webpack 构建:webpack一步一步构建 1)构建:creat ...
- oracle(2)
create table aaa( id number, name varchar2(100) ); select decode((select max(id) from aaa),null,'x', ...
- 51Nod 1058 N的阶乘的长度
输入N求N的阶乘的10进制表示的长度.例如6! = 720,长度为3. Input 输入N(1 <= N <= 10^6) Output 输出N的阶乘的长度 Input示例 6 Out ...
- 【题解】Luogu P2730 魔板
蒟蒻的第一道蓝题--好像也没有蓝的程度 一篇无STL的超弱题解(入门写法无误了QAQ 传送门 很经典的一道BFS 这是初始状态. 操作A 操作B 操作C 思路1 不使用cantor展开的情况 1. 对 ...
- jQuery 初知
jQuery 初知 介绍: jQuery是一个快速.简洁的JavaScript框架,是继Prototype之后又一个优秀的JavaScript代码库(或JavaScript框架).jQuery设计的宗 ...
- golang中 "下划线" 的用法
1.忽略返回值 这个应该是最简单的用途,比如某个函数返回三个参数,但是我们只需要其中的两个,另外一个参数可以忽略,这样的话代码可以这样写: v1, v2, _ := function(...) 2.用 ...