• 第六周周赛——AK机会不易得,好好把握题解(出自HDU5650,codeforces 616A,624A,659A,655A,658A)


    A题:

    A题题目链接

    题目描写叙述:

    位运算

    TimeLimit:1000MS  MemoryLimit:65536KB
    64-bit integer IO format:%I64d

    Problem Description

    已知一个包括 n 个元素的正整数集合S。设 f(S) 为集合S中全部元素的异或(XOR)的结果。

    如:S={1,2,3}, 则 f(S) = 0。


    给出集合S,你须要计算 将全部f(s)进行异或后的值, 这里 s⊆S.


    Input

    多组測试数据。第一行包括一个整数T(T≤20) 表示组数。


    每组測试数据第一行包括一个数 n(1≤n≤1,000) 表示集合的大小,第二行为 n个数表示集合


    元素。第 i(1≤i≤n) 个数 0 ≤ai ≤1000,000,000 且数据保证所给集合中没有反复元素。


    Output

    对于每组測试数据,输出一个数,表示将全部的 f(s)异或之后的值。

    SampleInput
    1
    3
    1  2  3
    SampleOutput
    0
    
    例子中,S={1,2,3}, 它的子集有∅, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}
    解析:

    这道题乍看上去让人摸不着头脑,事实上却是一道很easy的题目。

    一開始做题目没有头绪的时候。我们能够从简单枚举開始。从而

    寻找一般规律。

    首先,须要了解的是一些异或运算的基本性质:

    异或的性质和运算

    异或运算是满足结合律和交换律的,能够用卡诺图和真值表进行证明,这里就不细说了。

    当集合S中仅仅有一个元素的时候,子集仅仅有空集和其本身。非常明显。全部f(s)异或后的值就是其本身

    当集合S中有两个元素{a1,a2}的时候,子集有空集,{a1},{a2},{a1。a2}。那么全部集合进行异或运算的结果即为:

    a1 ^ a2 ^ a1 ^ a2 = a1 ^ a1 ^ a2 ^ a2 = 0

    当集合S中有三个元素{a1,a2,a3}的时候,子集有空集。{a1},{a2},{a3},{a1,a2},{a1。a3},{a2,a3}。{a1,a2。a3}。

    那么所

    有集合进行异或运算的结果即为:

    a1 ^ a2 ^ a3 ^ a1 ^ a2 ^ a1 ^ a3 ^ a2 ^ a3 ^ a1 ^ a2 ^ a3= a1 ^ a1 ^ a1 ^ a1 ^ a2 ^ a2 ^ a2 ^ a2 ^ a3 ^ a3^ a3 ^ a3  = 0

    枚举到这里,因此我们能够猜想,集合S中元素个数大于1时。全部子集异或后的结果为0。否则则为其本身。

    简单证明:

    如果集合S中有n个元素,对于当中的任一元素x,则总共2^(n-1)个子集包括元素x(排列组合证明,这里不具体说。有兴趣的可

    自己证明。结合二项式定理),那么当n>1时,x在全部子集中个数之和为偶数。那么全部x异或后的结果必为0,当n = 1时,则

    特判仅仅含有一个元素的情况。

    完整代码实现:

    #include<cstdio>
    int main(){
        int T,n,value;
        scanf("%d",&T);
        while(T--){
            scanf("%d",&n);
            for(int i = 1;i <= n;++i){
                scanf("%d",&value);
            }
            if(n==1){
                printf("%d
    ",value);
            }
            else{
                printf("0
    ");
            }
        }
    }
    

    B题:

    B题题目链接

    题目描写叙述:

    Comparing Two Long Integers

    TimeLimit:2000MS  MemoryLimit:256MB
    64-bit integer IO format:%I64d

    Problem Description

    You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal.

    The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.

    As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to usescanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input().

    Input

    The first line contains a non-negative integer a.

    The second line contains a non-negative integer b.

    The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits.

    Output

    Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=".

    SampleInput 1
    9
    10
    SampleOutput 1
    <
    SampleInput 2
    11
    10
    SampleOutput 2
    >
    SampleInput 3
    00012345
    12345
    SampleOutput 3
    =
    SampleInput 4
    0123
    9
    SampleOutput 4
    >
    SampleInput 5
    0123
    111
    SampleOutput 5
    >
    题意:

    给定两个整数,这两个整数可能含有前缀0。然后比較这两个数的大小,输出对应符号(< > =)

    解析:

    用字符串处理,分三种情况,除去前缀0之后。长者更大。反之短者更小。相同长则调用strcmp函数推断。

    完整代码实现:

    #include <cstdio>
    #include <cstring>
    char s[1000001], t[1000001];
    int main()
    {
    	scanf("%s %s", s, t);
    	int n = 0, m = 0;
    	while (s[n] == '0')
    		n++;
    	while (t[m] == '0')
    		m++;
    	int l1 = strlen(s + n);
    	int l2 = strlen(t + m);
    	if (l1 < l2)
    		puts("<");
    	else if (l1 > l2)
    		puts(">");
    	else
    	{
    		int cmp = strcmp(s + n, t + m);
    		puts(cmp > 0 ?

    ">" : (cmp == 0 ? "=" : "<")); } return 0; }


    C题:

    C题题目链接

    题目描写叙述:

    Save Luke

    TimeLimit:1000MS  MemoryLimit:256MB
    64-bit integer IO format:%I64d

    Problem Description

    Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and L, and they move towards each other with speed v1 and v2, respectively. Luke has width d and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive.

    Input

    The first line of the input contains four integers dLv1v2 (1 ≤ d, L, v1, v2 ≤ 10 000, d < L) — Luke's width, the initial position of the second press and the speed of the first and second presses, respectively.

    Output

    Print a single real value — the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

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

    SampleInput 1
    2 6 2 2
    SampleOutput 1
    1.00000000000000000000
    SampleInput 2
    1 9 1 2
    SampleOutput 2
    2.66666666666666650000
    Note

    In the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed.

    In the second sample he needs to occupy the position . In this case both presses move to his edges at the same time.

    题意:

    两个人分别从A,B两地相向而行,当两个人的距离达到d时,停止运动,问此时两个人运动的时间,距离L,两人速度v1,v2均给出。

    解析:

    相遇问题,列个一元一次方程求解就可以

    完整代码实现:

    #include<cstdio>
    int main(){
        int d,L,v1,v2;
        while(scanf("%d %d %d %d",&d,&L,&v1,&v2)==4){
            printf("%.20f
    ",double(L-d)/(v1+v2));
        }
        return 0;
    }
    

    D题:

    D题题目链接

    题目描写叙述:

    Round House

    TimeLimit:1000MS  MemoryLimit:256MB
    64-bit integer IO format:%I64d

    Problem Description

    Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent.

    Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance a and he decided that during his walk he will move around the house b entrances in the direction of increasing numbers (in this order entrance n should be followed by entrance 1). The negative value of b corresponds to moving |b| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance n). If b = 0, then Vasya prefers to walk beside his entrance.

     Illustration for n = 6a = 2b =  - 5.

    Help Vasya to determine the number of the entrance, near which he will be at the end of his walk.

    Input

    The single line of the input contains three space-separated integers na and b (1 ≤ n ≤ 100, 1 ≤ a ≤ n,  - 100 ≤ b ≤ 100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.

    Output

    Print a single integer k (1 ≤ k ≤ n) — the number of the entrance where Vasya will be at the end of his walk.

    SampleInput 1
    6 2 -5
    SampleOutput 1
    3
    SampleInput 2
    5 1 3
    SampleOutput 2
    4
    SampleInput 3
    3 2 7
    SampleOutput 3
    3
    Note

    The first example is illustrated by the picture in the statements.

    题意:

    给定n,a,b分别表示入口的个数,初始位置以及要走过的路口数。b值为负时逆时针走动,否则则顺时针走动。

    问最后走到的路口

    的标号。

    解析:

    直接模拟题意就可以,注意防止标号为负。

    完整代码实现:

    #include<cstdio>
    int main(){
        int n,a,b;
        while(scanf("%d %d %d",&n,&a,&b)==3){
            printf("%d
    ",(a+100*n+b)%n ? (a+100*n+b)%n : n);
        }
        return 0;
    }
    

    E题:

    E题题目链接

    题目描写叙述:


    Amity Assessment

    TimeLimit:2000MS  MemoryLimit:256MB
    64-bit integer IO format:%I64d

    Problem Description

    Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2 × 2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below:

    In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed.

    Input

    The first two lines of the input consist of a 2 × 2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2 × 2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position.

    Output

    Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes).

    SampleInput 1
    AB
    XC
    XB
    AC
    SampleOutput 1
    YES
    SampleInput 2
    AB
    XC
    AC
    BX
    SampleOutput 2
    NO
    Note

    The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.

    In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all...

    题意:

    给定两个2*2的宫格,问左边的宫格通过若干次移动之后,是否可以移成右边宫格的形状。

    解析:

    因为宫格仅仅有2*2。直接暴力模拟就可以。

    完整代码实现:

    #include<iostream>
    #include<string>
    #include<algorithm>
    using namespace std;
    string a[2], b[2];
    int main()
    {
        cin >> a[0] >> a[1] >> b[0] >> b[1];
        for (int i = 0; i < 1000; ++i) {
            if (a[0] == b[0] && a[1] == b[1]) {
                cout << "YES";
                return 0;
            }
            if (a[0][0] == 'X') swap(a[0][0], a[0][1]);
            else if (a[0][1] == 'X') swap(a[0][1], a[1][1]);
            else if (a[1][1] == 'X') swap(a[1][1], a[1][0]);
            else if (a[1][0] == 'X') swap(a[1][0], a[0][0]);
        }
        cout << "NO";
    
        return 0;
    }
    

    F题:

    F题题目链接

    题目描写叙述:

    Bear and Reverse Radewoosh

    TimeLimit:2000MS  MemoryLimit:256MB
    64-bit integer IO format:%I64d

    Problem Description

    Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.

    There will be n problems. The i-th problem has initial score pi and it takes exactly ti minutes to solve it. Problems are sorted by difficulty — it's guaranteed that pi < pi + 1 and ti < ti + 1.

    A constant c is given too, representing the speed of loosing points. Then, submitting the i-th problem at time x (x minutes after the start of the contest) gives max(0,  pi - c·x) points.

    Limak is going to solve problems in order 1, 2, ..., n (sorted increasingly by pi). Radewoosh is going to solve them in ordern, n - 1, ..., 1 (sorted decreasingly by pi). Your task is to predict the outcome — print the name of the winner (person who gets more points at the end) or a word "Tie" in case of a tie.

    You may assume that the duration of the competition is greater or equal than the sum of all ti. That means both Limak and Radewoosh will accept all n problems.

    Input

    The first line contains two integers n and c (1 ≤ n ≤ 50, 1 ≤ c ≤ 1000) — the number of problems and the constant representing the speed of loosing points.

    The second line contains n integers p1, p2, ..., pn (1 ≤ pi ≤ 1000, pi < pi + 1) — initial scores.

    The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 1000, ti < ti + 1) where ti denotes the number of minutes one needs to solve the i-th problem.

    Output

    Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points.

    SampleInput 1
    3 2
    50 85 250
    10 15 25
    SampleOutput 1
    Limak
    SampleInput 2
    3 6
    50 85 250
    10 15 25
    SampleOutput 2
    Radewoosh
    SampleInput 3
    8 1
    10 20 30 40 50 60 70 80
    8 10 58 63 71 72 75 76
    SampleOutput 3
    Tie
    Note

    In the first sample, there are 3 problems. Limak solves them as follows:

    1. Limak spends 10 minutes on the 1-st problem and he gets 50 - c·10 = 50 - 2·10 = 30 points.
    2. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85 - 2·25 = 35 points.
    3. He spends 25 minutes on the 3-rd problem so he submits it 10 + 15 + 25 = 50 minutes after the start. For this problem he gets 250 - 2·50 = 150 points.

    So, Limak got 30 + 35 + 150 = 215 points.

    Radewoosh solves problem in the reversed order:

    1. Radewoosh solves 3-rd problem after 25 minutes so he gets 250 - 2·25 = 200 points.
    2. He spends 15 minutes on the 2-nd problem so he submits it 25 + 15 = 40 minutes after the start. He gets 85 - 2·40 = 5 points for this problem.
    3. He spends 10 minutes on the 1-st problem so he submits it 25 + 15 + 10 = 50 minutes after the start. He gets max(0, 50 - 2·50) = max(0,  - 50) = 0 points.

    Radewoosh got 200 + 5 + 0 = 205 points in total. Limak has 215 points so Limak wins.

    In the second sample, Limak will get 0 points for each problem and Radewoosh will first solve the hardest problem and he will get 250 - 6·25 = 100 points for that. Radewoosh will get 0 points for other two problems but he is the winner anyway.

    In the third sample, Limak will get 2 points for the 1-st problem and 2 points for the 2-nd problem. Radewoosh will get 4 points for the 8-th problem. They won't get points for other problems and thus there is a tie because 2 + 2 = 4.

    解析:

    因为在题目后方,题意已经解释得很清楚。因此题意不再多说。事实上这就是codeforces本地比赛的规则(codeforces daily 、

    round)。因此在处理从前往后做题和从后往前做题的两种情况时,我们分别能够用后缀和以及前缀和先预处理一下就可以。

    完整代码实现:

    #include<cstdio>
    #include<algorithm>
    using namespace std;
    const int maxn = int(1e3) + 10;
    int p[maxn],t[maxn],t1[maxn],t2[maxn];
    int main(){
        int n,c;
        while(scanf("%d %d",&n,&c)==2){
            for(int i = 1;i <= n;++i){
                scanf("%d",&p[i]);
            }
            for(int i = 1;i <= n;++i){
                scanf("%d",&t[i]);
                t1[i] = t[i];
                t2[i] = t[i];
            }
            for(int i = 1;i < n;++i){
                t1[i+1] += t1[i];
            }
            for(int i = n;i > 1;--i){
                t2[i-1] += t2[i];
            }
            int score1 = 0,score2 = 0;
            for(int i = 1;i <= n;++i){
                score1 += max(0,p[i]-c*t1[i]);
            }
            for(int i = n;i >= 1;--i){
                score2 += max(0,p[i]-c*t2[i]);
            }
            if(score1 > score2){
                printf("Limak
    ");
            }
            else if(score1 < score2){
                printf("Radewoosh
    ");
            }
            else{
                printf("Tie
    ");
            }
        }
        return 0;
    }
    


    如有错误,还请指正,O(∩_∩)O谢谢


  • 相关阅读:
    自己写的DBHelper感慨颇深
    23种设计模式:观察者模式,第一次对观察者模式理解的这么通透。
    自己用心写的 存储过程分页 给自己的平台用
    开篇成长的开始[废话一把]
    C# 中i++在ref参数调用下的有趣现象
    点点滴滴的成长[2011111]:理解C#修饰符
    点点滴滴的成长[2011114]:自定义config文件
    扩展方法在Json字符串转化中的应用
    jquery学习二:jquery性能优化
    javascript系列1:函数
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7401470.html
Copyright © 2020-2023  润新知