[toc]

Testing Round #16 (Unrated)

A - A+B (Trial Problem)

You are given two integers and . Print .

Input
The first line contains an integer () — the number of test cases in the input. Then t test cases follow.

Each test case is given as a line of two integers and ().

Output
Print t integers — the required numbers .

Example

input

4
1 5
314 15
-99 99
123 987

output

6
329
0
1110

题意:求A+B

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;

int main(){
    int a,b;
    int t;
    cin>>t;
    while(t--){
        cin>>a>>b;
        cout<<a+b<<endl;
    }
    return 0;
}

B - Square?

Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.

Input

The first line contains an integer t () — the number of test cases in the input. Then t test cases follow.

Each test case is given in two lines.

The first line contains two integers and () — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).

The second line contains two integers and () — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).

Output
Print t answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).

Example

input

3
2 3
3 1
3 2
1 3
3 3
1 3

output

Yes
Yes
No

题意:判断两个矩形是否能组成一个正方形

题解:找到两个矩形相同的边,判断其邻边之和是否与其相等

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;

int main(){
    int a1,b1,a2,b2;
    int a,b,c;
    int t;
    cin>>t;
    while(t--){
        cin>>a1>>b1;
        cin>>a2>>b2;
        a=max(a1,b1),b=min(a1,b1);
        if(a==a2) c=b2;
        else if(a==b2) c=a2;
        else{
            cout<<"NO"<<endl;
            continue;
        }

        if(a==b+c) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

C - Skier

Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to meter movement in the south, north, west or east direction respectively).

It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes second.

Find the skier's time to roll all the path.

Input
The first line contains an integer () — the number of test cases in the input. Then test cases follow.

Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed characters.

The sum of the lengths of t given lines over all test cases in the input does not exceed .

Output
For each test case, print the desired path time in seconds.

Example

input

5
NNN
NS
WWEN
WWEE
NWNWS

output

15
6
16
12
25

题意:'S', 'N', 'W', 'E'代表南,北,西,东四个方向,如果a,b两点的这条路没有走过需要5 s,走过需要1 s,求一共需要多少时间。

题解:先用pair存某点的横纵坐标,再用pair存a->b这条路,放入set集合中。 因为a->b和b->a是同一条路,所以走过a->b 时也要记录b->a。字符串的长度(len)表示需要走多少路的数量 *2,set集合的大小(n)表示走过哪几条路 *2。最后所需花时间为5 * len/2 + n/2 。

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int main(){
    int t;
    cin>>t;
    while(t--){
        set<pair<pair<int,int>,pair<int,int>>> s;
        string str;
        cin>>str;
        int x=0,y=0;
        for(int i=0;i<str.length();i++){
            int xx=x, yy=y;
            if(str[i]=='N') y++;
            else if(str[i]=='S') y--;
            else if(str[i]=='W') x--;
            else if(str[i]=='E') x++;
            s.insert({{x,y},{xx,yy}});
            s.insert({{xx,yy},{x,y}});
        }

        cout<<5*s.size()/2+str.length()-s.size()/2<<endl;
    }
    return 0;
}