zoukankan      html  css  js  c++  java
  • Testing Round #16 (Unrated)

    Testing Round #16 (Unrated)

    A - A+B (Trial Problem)

    You are given two integers (a) and (b). Print (a+b).

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

    Each test case is given as a line of two integers (a) and (b) ((−1000≤a,b≤1000)).

    Output
    Print t integers — the required numbers (a+b).

    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 ((1≤t≤10^4)) — 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 (a_1) and (b_1) ((1≤a_1,b_1≤100)) — 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 (a_2) and (b_2) ((1≤a_2,b_2≤100)) — 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 (1) 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 (5) 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 (1) second.

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

    Input
    The first line contains an integer (t) ((1≤t≤10^4)) — the number of test cases in the input. Then (t) 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 (10^5) characters.

    The sum of the lengths of t given lines over all test cases in the input does not exceed (10^5).

    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;
    }
    
    
  • 相关阅读:
    ubuntu将默认中文改成英文
    解决discuz模板插入jvascript脚本问题(Unexpected token <)
    解决discuz与jquery不兼容问题——下拉列表不能用(Uncaught TypeError: Cannot set property 'position' of undefined)
    wamp图标黄色的另一种可能原因
    解决$_REQUEST['name']Undefined问题
    $_SERVER 中重要的元素
    解决ashx文件下的Session“未将对象引用设置到对象的实例”
    远程桌面 虚拟打印 到本地打印机(虚拟化 终端 远程接入 RemoteApp)
    远程桌面 使用 本地输入法(虚拟化 终端 远程接入 RemoteApp)
    虚拟化 RemoteApp 远程接入 源码 免费
  • 原文地址:https://www.cnblogs.com/transmigration-zhou/p/12847009.html
Copyright © 2011-2022 走看看