每天一水SGU347
今天本来应该要写校题解报告的,但是CF跪了,一题都没JUDGE出来,最后比赛取消了~郁闷啊!
后来闲的无事,就到处看看contest,随便点进去一个,看到一水题,几分钟写完,马上就WA了!~
题目的信息含量太低了!我直接看样例。以为是字典序排序后连起来输出,没想到是使得最后连起来的字典序最小。
本来我因为mutilset轻松水过,后来……还是用mutilset水的。重载下小于就好了。
题目:
Description
His Royal Highness King of Berland Berl XV was a very wise man and had a very accomplished wife, who was aware of the fact, that prominent and outstanding personalities once having written down their names on the pages of glorious History, remain there forever.
His Royal Highness King Berl XV experienced an intrinsic, lost nowadays, deep and sincere sense of respect and trust for his beloved spouse. So he decided to acquire a chronicler of his own. Due to the ambiguous nature of misunderstanding and the crying injustice
of history to ambiguity, he decided to leave all his royal responsibilities aside and made up his royal mind to find the chronicler, who will make him famous, depicting all his heroic deeds truthfully and gloriously enough.
The King assembled the greatest minds of his kingdom at the Academic Chroniclers Meeting (ACM), as he named it, and decided to test their might. The task was to build the Smallest Lexicographical Concatenation (SLC) out of the given
N strings. SLC of N strings s1,..., sN is the lexicographically smallest their concatenation
si1 +... + siN, where
i1,..., iN is a permutation of integers from 1 through
N. It's a great privilege to be a chronicler, so don't miss your chance and don't screw it up! Make the king choose you!
Input
N (1 ≤ N ≤ 100) indicating the number of strings. The following
N lines contain N strings, one string per line. The length of each string is no more than 100 characters. Each string consists only of lowercase Latin letters. There are no any leading or trailing spaces.
Output
Sample Input
sample input |
sample output |
6 |
aneasyitlikelooksproblem |
付代码
#include<iostream>
#include<set>
#include<string>
using namespace std;
class mstring{
public:
string str;
bool operator<(const mstring &t1) const{
return (str+t1.str < t1.str+str);
}
mstring(){};
mstring(string a){str=a;}; };
int main(){
multiset<mstring> s;
int n;
while(cin>>n){
s.clear();
string str;
cin.ignore();
while(n--){
cin>>str;
s.insert( mstring(str));
}
multiset<mstring> ::iterator itr =s.begin();
while(itr!=s.end()){ cout<<(*itr).str; itr++;
}
cout<<endl; } return 0;
}
注意到测试数据
2
ac
aca
排出来的应该是acaac 而不是acaca!
比较的方法就是 a+b<b+a!
每天一水SGU347的更多相关文章
- Openjudge 1.13-23:区间内的真素数(每日一水)
总时间限制: 1000ms 内存限制: 65536kB 描述 找出正整数 M 和 N 之间(N 不小于 M)的所有真素数.真素数的定义:如果一个正整数 P 为素数,且其反序也为素数,那么 P 就为 ...
- poj2503--Babelfish(特里一水)
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 32988 Accepted: 14189 Descr ...
- 习题10-1 UVA 11040(无聊水一水)
题意: 给你一个残缺的塔,每个数字由他下面左右两个数相加得.给你其中一部分,要求输出全部的数字. #include <iostream> #include <cstdio> # ...
- POJ 1321 棋盘问题 DFS 期末前水一水就好……
A - 棋盘问题 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- 每日一水 POJ8道水题
1. POJ 3299 Humidex 链接: http://poj.org/problem?id=3299 这道题是已知H,D,T三者的运算关系,然后告诉你其中两个.求另一个. #include&l ...
- 数论E - Biorhythms(中国剩余定理,一水)
E - Biorhythms Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Subm ...
- poj1936 假期计划第一水
All in All Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 29651 Accepted: 12312 Desc ...
- 每天一水poj1502【最短路】
#include<iostream> #include<cstdio> #include<string.h> #include<algorithm> u ...
- codeforces346 Div.2 A.Round House
课间水一水,CCF备战 package com.company.cf346; import java.io.InputStreamReader; import java.util.Scanner; / ...
随机推荐
- 【Java基础】Java内部类
什么是内部类 把类定义在其他类的内部,这个类就被称为内部类. 内部类的分类 内部类分为两种,分别为成员内部类和局部内部类: 成员内部类:和成员变量和成员方法定义在同级 局部内部类:和局部变量定义在同级 ...
- php tcp socket 学习汇总
推荐实例:PHP socket 深入浅出讲解:php的socket通信 基于socket.io的实时消息推送 php socket通信(tcp/udp) PHP向socket服务器收发数据 php实现 ...
- ehcache简单使用
项目中需要实现一个功能,定时查询FTP服务器某个目录下的文件,并及时下载至本机,同时不能消耗太多系统资源. 最后实现是使用ehcache,将文件路径和文件大小缓存,如果前后两次无变化,则忽略.如果同一 ...
- Block介绍(一)基础
一.概述 Block是C级别的语法和运行时特性.Block比较类似C函数,但是Block比之C函数,其灵活性体现在栈内存.堆内存的引用,我们甚至可以将一个Block作为参数传给其他的函数或者Block ...
- iOS从生成证书到打包上架-01(详细2016-10最新)
今天项目上架成功,在此小结一下这个过程,希望对这个流程有疑惑的小伙伴少走弯路(大神请忽略此文) 关于证书是什么,请自行百度,Google,这里直接上流程. 1.首先打开苹果开发者网站,Apple De ...
- zookeeper-3.4.8 集群搭建
一.虚拟机环境 见我的另一篇博客http://www.cnblogs.com/xckk/p/6000881.html, zookeeper是用JAVA编写,因此需要安装JDK环境,centos下安装J ...
- Java通过JDBC连接Oracle之后查询结果和在sqlplus查询结果不一样
问题描述: 在sqlplus 下 orcl数据库中创建一张表后,使用insert语句插入几条数据 然后用java查询数据,发现在终端中输出的结果和在sqlplus中查询结果不一样. 在sqlplus中 ...
- hud 1241 Oil Deposits
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- Effective C# Chapter1-Language Elements
<EffectiveC#>这本书讲了一些关于C#语言的使用技巧和经验. 该系列文章是备忘录和自己的一些见解.程序猿们最喜欢这类问题了,欢迎讨论~ 菜单 Item 1 使用属性取代公共成员变 ...
- Java中Map的使用
Map以按键/数值对的形式存储数据,和数组很类似,在数组中存在的索引,它们本身也是对象. Map的接口 Map---实现Map Map.Entry--Map的内部类 ...