Codeforces 591

A. Wizards' Duel
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length l. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of p meters per second, and the impulse of You-Know-Who's magic spell flies at a speed of q meters per second.

The impulses are moving through the corridor toward each other, and at the time of the collision they turn round and fly back to those who cast them without changing their original speeds. Then, as soon as the impulse gets back to it's caster, the wizard reflects it and sends again towards the enemy, without changing the original speed of the impulse.

Since Harry has perfectly mastered the basics of magic, he knows that after the second collision both impulses will disappear, and a powerful explosion will occur exactly in the place of their collision. However, the young wizard isn't good at math, so he asks you to calculate the distance from his position to the place of the second meeting of the spell impulses, provided that the opponents do not change positions during the whole fight.

Input

The first line of the input contains a single integer l (1 ≤ l ≤ 1 000) — the length of the corridor where the fight takes place.

The second line contains integer p, the third line contains integer q (1 ≤ p, q ≤ 500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, respectively.

Output

Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10 - 4.

Namely: let's assume that your answer equals a, and the answer of the jury is b. The checker program will consider your answer correct if .

Examples
input
100
50
50
output
50
input
199
60
40
output
119.4
Note

In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.


/*
  水题
  题意:哈利波特和伏地魔在长度为l的走廊上决斗。
        哈利波特在走廊的最左边 伏地魔在走廊的最右边
        然后哈利波特发出的魔法速度为p 伏地魔的魔法速度为q
        它们的魔法碰撞后会反弹 当返回到它们的时候
        他们两个立刻又使用相同速度的魔法 问第二次碰撞的位置在哪。
        假设哈利波特在x轴的0点 伏地魔在l点。
  解法:因为时间不变 所以还是第一次碰撞的那个点
*/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdlib>
using namespace std;
int main(void)
{
    double l,p,q;
    while(scanf("%lf%lf%lf",&l,&p,&q)!=EOF)
    {
        double sum=l*p/(p+q);
        printf("%.4f\n",sum);
    }
	return 0;
}

B. Rebranding
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The name of one small but proud corporation consists of n lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name.

For this purpose the corporation has consecutively hired m designers. Once a company hires the i-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters xi by yi, and all the letters yi by xi. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen thatxi coincides with yi. The version of the name received after the work of the last designer becomes the new name of the corporation.

Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive.

Satisfy Arkady's curiosity and tell him the final version of the name.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the length of the initial name and the number of designers hired, respectively.

The second line consists of n lowercase English letters and represents the original name of the corporation.

Next m lines contain the descriptions of the designers' actions: the i-th of them contains two space-separated lowercase English letters xiand yi.

Output

Print the new name of the corporation.

Examples
input
6 1
police
p m
output
molice
input
11 6
abacabadaba
a b
b c
a d
e g
f a
b b
output
cdcbcdcfcdc
Note

In the second sample the name of the corporation consecutively changes as follows:


/*
  题意很简单:
  给你一个长度为n的字符串 然后m个操作
  每个操作输入两个字符 x 与 y
  按输入的顺序操作 将字符串中的x字符全部替代为y
  然后输出新串
  因为n和m都是≤2*1e5 暴力不可取 
  所以我们可以把所有的操作化简一下 然后再进行交换
*/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdlib>
using namespace std;
const int maxn = 200000+100;
char s[maxn],a[maxn];
int main(void)
{
    int n,m;
    char x[2],y[2];
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        for(int i=0;i<26;i++)
            a[i]=i+'a';
        scanf("%s",s);
        while(m--)
        {
            scanf("%s%s",x,y);
            for(int i=0;i<26;i++)
            {
                if(a[i]==x[0]) a[i]=y[0];
                else if(a[i]==y[0]) a[i]=x[0];
            }
        }
        for(int i=0;i<n;i++)
            printf("%c",a[s[i]-'a']);
        puts("");
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值