Sicily 13460. Passwords

13460. Passwords

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

Mirko is an evil plotting genius and has gotten hold of a list of all possible passwords for a certain user account. The first thing he noticed was all the passwords are of odd length. Mirko assumes that the correct password is the one which can be found in
both the original and reverse order in the list. For example, if the word “tulipan” would be the correct password, the word “napilut” has to also appear in the list. Given that both words are correct passwords, Mirko will try to use both, one at a time.

Help Mirko discover what the correct password is and output its length and central character.

Input

The first line of input contains the integer N (1 ≤ N ≤ 100), the number of possible passwords. Each of the following N lines contains a single word, its length being an odd number greater than 2 and lesser than 14. All characters are lowercase letters of the
English alphabet.

Output

The first and only line of output must contain the length of the correct password and its central letter. The solution will be unique.

Sample Input

样例1:
4
las
god
psala
sal
样例2:
4
kisik
ptq
tttrp
tulipan

Sample Output

样例1:
3 a
样例2:
5 s

Hint

Clarification of the first example: The required pair of words is “las” and “sal”. Their length is 3 letters and the central character is ‘a‘.

Clarification of the second example: The word “kisik” can be found in both the original and reverse order on the list (the word is a palindrome), so it is a valid correct password.

Problem Source

2015年每周一赛第一场

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main() {
	std::ios::sync_with_stdio(false);

	int n;
	cin >> n;
	vector<string> v(n);
	for (int i = 0; i < n; i++) cin >> v[i];
	for (int i = 0; i < v.size(); i++) {
		string s = v[i];
		reverse(s.begin(), s.end());
		for (int j = 0; j < v.size(); j++) {
			if (s == v[j]) {
				cout << v[j].size() << " " << v[j][v[j].size() / 2] << endl;
				return 0;
			}
		}
	}

	return 0;
}
时间: 2024-10-18 19:24:54

Sicily 13460. Passwords的相关文章

Sicily 1146:Lenny&#39;s Lucky Lotto(dp)

题意:给出N,M,问有多少个长度为N的整数序列,满足所有数都在[1,M]内,并且每一个数至少是前一个数的两倍.例如给出N=4, M=10, 则有4个长度为4的整数序列满足条件: [1, 2, 4, 8], [1, 2, 4, 9], [1, 2, 4, 10], [1, 2, 5, 10] 分析:可用动态规划解题,假设dp[i][j],代表满足以整数i为尾数,长度为j的序列的个数(其中每一个数至少是前一个数的两倍).那么对于整数i,dp[i][j] 等于所有dp[k][j-1]的和,其中k满足:

UVALive 6507 Passwords

Passwords Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Original ID: 650764-bit integer IO format: %lld      Java class name: Main 解题:好高深的hash啊 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long

sicily 1345 能量项链

先模拟一下确定理解题意,然后再找状态转移方程,注意方向~ 1 //sicily 1345 能量项链 2 #include <bits/stdc++.h> 3 4 using namespace std; 5 6 int a[205]; 7 int dp[205][205]; 8 9 int main() 10 { 11 int n; 12 while(cin >> n) 13 { 14 memset(dp, 0, sizeof(dp)); 15 for(int i=0; i<

sicily 1063. Who&#39;s the Boss

Time Limit: 1sec    Memory Limit:32MB Description Several surveys indicate that the taller you are, the higher you can climb the corporate ladder. At TALL Enterprises Inc. this "de facto standard" has been properly formalized: your boss is alway

Sicily 1735 Encryption (模拟)

链接:http://soj.me/show_problem.php?pid=1735&cid= Description Let me introduce an easy method of encryption to you. Suppose there're N bytes (1 byte = 8 bits) data that are to be encrypted and we want to encrypt them in groups of M bytes, while for the

[mysql] ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.

今天安装mysql遇到这样一个问题: ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords. 意思就是密码过期了. 修改密码了: mysql> SET PASSWORD = PASSWORD('abc'); ERROR 1819 (HY000): Your password does not satisfy

Cracking Story - How I Cracked Over 122 Million SHA1 and MD5 Hashed Passwords

This is the story about how I cracked 122 million* password hashes with John the Ripper and oclHashcat-plus. Author: m3g9tr0n, Copy Editor: Thireus. It was several months ago, when I (m3g9tr0n) saw a tweet from KoreLogic about atorrent file containin

sicily 1219(记忆化搜索)

题目链接:sicily 1214 解题思路: 博弈题,用搜索来做.但是,如果用普通的搜索来做的话,是会超时的--复杂度大约是O( n^n ),所以需要采用记忆化搜索的方法(其实差不多就是动态规划了,但是这里是树形DP). 状态: 用集合S表示现在树的状态,i 表示现在轮到谁进行砍边,dp[ S ][ i ]表示最优值.集合S可以用二进制来表示,即001表示现在还剩下第0条边. 状态转移: 1)A的目标是取最大值,B的目标是取最小值,我们在推导当前状态的最优解时,需要分两种情况考虑!即A得维护较大

sicily 1136(线段树+最大子数组)

题目链接:sicily 1136 解题思路: 要求区间内的最大子数组,而且访问可能很频繁,时间复杂度需要达到o(n*logn),于是就很自然地想到了线段树.我们可以用线段树来保存区间的最大子数组,但是仔细想想又不对劲了,如果访问的区间跨越了两个小区间怎么破,所以,这并不只是一个简单的求区间连续和的问题,还要有点小技巧. 最大子数组怎么得到的,还记得<算法导论>里面讲过一种用分治法来求最大子数组的方法吗(分治法之最大子数组)? 假设我们要求区间[low , high]的最大子数组,并且已知[lo