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 // 不难发现:如果图中存在有向环,则不存在拓 ...
随机推荐
- 记录一则xtts测试遇到的诡异现象
背景:在一次xtts的测试中遇到因源库数据文件名称包含特殊字符导致表空间全量备份缺失文件,之所以说是诡异现象,是因为xtts的全备日志不报任何错误,在恢复阶段才发现缺少文件,这个缺陷比较隐晦,尤其在迁 ...
- win7共享打印机和防火墙配置
今天给公司一台Win7电脑连接的打印机做共享.办公司共6台电脑,其中1台是连接了打印机,并安装了打印机驱动,可以正常本机使用打印机.现在需要其他5台电脑也共享使用打印机. 1.当共享的时候,提示“无法 ...
- 知识在与温故、总结-再读CLR
序 CLR,通用语言运行时,每个.Net 程序猿,都会第一时间接触到.记得2008年,第一次学习Jeffrey Richter的CLR Via C#,读的懵懵懂懂,大抵因为编码太少,理解的只是概念和皮 ...
- 记录Ok6410 sd 启动uboot
1\参考资料https://github.com/SeanXP/ARM-Tiny6410/tree/master/no-os/sd-no-os/u-boot 2\参考资料https://blog.cs ...
- Android项目第一天,下载安装Android Studio和“我的第一个安卓项目”
一.AS的下载我是在AS官方网站进行下载的最新版本,如图所示 二.AS的安装过程 点击你下载的安装包安装即可,傻瓜式一站到底. 到这一步时选择第二个按钮, 随后出现如下界面 这个窗口是提示我们设置代理 ...
- 解决CentOS6.5虚拟机克隆后无法上网(网卡信息不一致)的问题
一.问题描述 虚拟机克隆后,由于网卡信息不一致的问题,导致不能上网或者执行“service network restart”命令失败 [root@lyy 桌面]# ifconfig //查看当前网卡信 ...
- 常用python的标准库
1.itsdangerous # 加密签名的数据 2.re # 正则表达式 3.time # 时间模块 4.keyword # 查看关键字5.random # 随机6.uuid
- python scrapy baidu image【转】
原 https://github.com/vivianLL/baidupictures #!/usr/bin/env Python # coding=utf-8 #__author__ = 'leil ...
- python之路——模块和包
阅读目录 一 模块 3.1 import 3.2 from ... import... 3.3 把模块当做脚本执行 3.4 模块搜索路径 3.5 编译python文件 二 包 2.2 import 2 ...
- [ajax] - 上传图片,视频后的路径回传及确定逻辑
业务场景1: 后台要上传视频,图片到网站的首页或者附页,上传后,视频,图片存储到服务器或cdn,但是此时还要加确定按钮以实现该视频,图片路径数据库的插入操作. 页面展现: 点击操作按钮,触发input ...