您的位置:首页 > 大数据 > 人工智能

codeforces-752【A找规律】【set+pair】

2016-12-25 22:58 417 查看
题目链接:点击打开链接

A. Santa Claus and a Place in a Class

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are n lanes
of m desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to n from
the left to the right, the desks in a lane are numbered from 1 to m starting
from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture).

The organizers numbered all the working places from 1 to 2nm.
The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at
each desk, the place on the left is numbered before the place on the right.


The
picture illustrates the first and the second samples.

Santa Clause knows that his place has number k. Help him to determine at which lane at which desk he should sit, and whether his place
is on the left or on the right!

Input

The only line contains three integers n, m and k (1 ≤ n, m ≤ 10 000, 1 ≤ k ≤ 2nm) —
the number of lanes, the number of desks in each lane and the number of Santa Claus' place.

Output

Print two integers: the number of lane r, the number of desk d,
and a character s, which stands for the side of the desk Santa Claus. The character s should
be "L", if Santa Clause should sit on the left, and "R"
if his place is on the right.

Examples

input
4 3 9


output
2 2 L


input
4 3 24


output
4 3 R


input
2 4 4


output
1 2 R


Note

The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.

In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.

找规律咯

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,k;
int main()
{
while(~scanf("%d%d%d",&n,&m,&k))
{
int t=k/(2*m);
if(k%(2*m)==0)
{
printf("%d %d R\n",t,m);
continue;
}
int st=t*2*m+1;
int ans;
if(k&1)
{
ans=(k-st)/2+1;
printf("%d %d L\n",t+1,ans);
}
else
{
ans=(k-st-1)/2+1;
printf("%d %d R\n",t+1,ans);
}
}
return 0;
}

题目链接:点击打开链接

B. Santa Claus and Keyboard Check

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another
key, which is located exactly where the first key should be.

In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.

You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.

Input

The input consists of only two strings s and t denoting
the favorite Santa's patter and the resulting string. s and t are
not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.

Output

If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without
quotes).

Otherwise, the first line of output should contain the only integer k (k ≥ 0) —
the number of pairs of keys that should be swapped. The following k lines should contain two space-separated letters each, denoting
the keys which should be swapped. All printed letters must be distinct.

If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair.

Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.

Examples

input
helloworld
ehoolwlroz


output
3
h e
l o
d z


input
hastalavistababy
hastalavistababy


output
0


input
merrychristmas
christmasmerry


output
-1


大意:给出两个串,第一个是正确的串,第二个是写错的串。可以变化第二个串中的字符,变化的字符只能变化为某一种字符,而且这个串中的所有这两种字符互换。问能否得到正确的串

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
typedef pair<int,int> pii;
char str1[1010],str2[1010];
int pos[50];
set<pii> ans;
int main()
{
while(~scanf("%s%s",str1,str2))
{
ans.clear();
memset(pos,-1,sizeof(pos));
int len=strlen(str1);
bool flag=0;
for(int i=0;i<len;i++)
{
int x=str1[i]-'a';
int y=str2[i]-'a';
if(x>y)
swap(x,y);
if(pos[x]!=-1&&pos[x]!=y)
flag=1;
if(pos[y]!=-1&&pos[y]!=x)
flag=1;
pos[x]=y; pos[y]=x;
if(x!=y)
ans.insert(pii(x,y));
}
if(flag)
{
puts("-1");
continue;
}
printf("%d\n",ans.size());
set<pii>::iterator it;
for(it=ans.begin();it!=ans.end();it++)
{
printf("%c %c\n",(*it).first+'a',(*it).second+'a');
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: