zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 071 ABCD

    A - Meal Delivery


    Time limit : 2sec / Memory limit : 256MB

    Score : 100 points

    Problem Statement

    Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.

    Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence.

    Here, the distance between two points s and t on a number line is represented by |st|.

    Constraints

    • 1x1000
    • 1a1000
    • 1b1000
    • x,a and b are pairwise distinct.
    • The distances between Snuke's residence and stores A and B are different.

    Input

    Input is given from Standard Input in the following format:

    x a b
    

    Output

    If store A is closer, print A; if store B is closer, print B.


    Sample Input 1

    Copy
    5 2 7
    

    Sample Output 1

    Copy
    B
    

    The distances between Snuke's residence and stores A and B are 3 and 2, respectively. Since store B is closer, print B.


    Sample Input 2

    Copy
    1 999 1000
    

    Sample Output 2

    Copy
    A
    
    求x到a或b的最近的那个,水题。
     1 #include <bits/stdc++.h>
     2 #define ll long long
     3 using namespace std;
     4 const int N = 110;
     5 int main() {
     6     int x, a, b;
     7     cin >> x >> a >> b;
     8     if(abs(x-a) < abs(x-b)) printf("A
    ");
     9     else printf("B
    ");
    10     return 0;
    11 }

    B - Not Found


    Time limit : 2sec / Memory limit : 256MB

    Score : 200 points

    Problem Statement

    You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print None instead.

    Constraints

    • 1|S|105 (|S| is the length of string S.)
    • S consists of lowercase English letters.

    Input

    Input is given from Standard Input in the following format:

    S
    

    Output

    Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print None instead.


    Sample Input 1

    Copy
    atcoderregularcontest
    

    Sample Output 1

    Copy
    b
    

    The string atcoderregularcontest contains a, but does not contain b.


    Sample Input 2

    Copy
    abcdefghijklmnopqrstuvwxyz
    

    Sample Output 2

    Copy
    None
    

    This string contains every lowercase English letter.


    Sample Input 3

    Copy
    fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg
    

    Sample Output 3

    Copy
    d
    
    从a到z,看哪个没出现就输出谁,都出现了就输出None,接着水。
     1 #include <bits/stdc++.h>
     2 #define ll long long
     3 using namespace std;
     4 const int N = 1e5+10;
     5 char str[N];
     6 int a[30];
     7 int main() {
     8     cin >> str;
     9     for(int i = 0; str[i]; i ++) a[str[i]-'a']++;
    10     for(int i = 0; i < 26; i ++) {
    11         if(a[i] == 0) return 0*printf("%c
    ",i+'a');
    12     }
    13     printf("None
    ");
    14     return 0;
    15 }

    C - Make a Rectangle


    Time limit : 2sec / Memory limit : 256MB

    Score : 300 points

    Problem Statement

    We have N sticks with negligible thickness. The length of the i-th stick is Ai.

    Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.

    Constraints

    • 4N105
    • 1Ai109
    • Ai is an integer.

    Input

    Input is given from Standard Input in the following format:

    N
    A1 A2 ... AN
    

    Output

    Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.


    Sample Input 1

    Copy
    6
    3 1 2 4 2 1
    

    Sample Output 1

    Copy
    2
    

    1×2 rectangle can be formed.


    Sample Input 2

    Copy
    4
    1 2 3 4
    

    Sample Output 2

    Copy
    0
    

    No rectangle can be formed.


    Sample Input 3

    Copy
    10
    3 3 3 3 4 4 4 5 5 5
    

    Sample Output 3

    Copy
    20
    
    求最大的两个出现两次出现过的数字,继续水。
     1 #include <bits/stdc++.h>
     2 #define ll long long
     3 using namespace std;
     4 const int N = 110;
     5 map<int,int> mp;
     6 int main() {
     7     int n, x;
     8 
     9     cin >> n;
    10     int MAX1 = 0, MAX2 = 0;
    11     for(int i = 0; i < n; i ++) {
    12         scanf("%d", &x);
    13         if(mp.count(x)) {
    14             if(x > MAX1) {
    15                 MAX2 = MAX1;
    16                 MAX1 = x;
    17             } else if(x > MAX2) {
    18                 if(x == MAX1 && mp[x] >= 3) {
    19                     MAX2 = x;
    20                 } else if(x < MAX1) MAX2 = x;
    21             }
    22         }
    23         mp[x] ++;
    24     }
    25     printf("%lld
    ",1LL*MAX1*MAX2);
    26     return 0;
    27 }

    D - Coloring Dominoes


    Time limit : 2sec / Memory limit : 256MB

    Score : 400 points

    Problem Statement

    We have a board with a 2×N grid. Snuke covered the board with N dominoes without overlaps. Here, a domino can cover a 1×2 or 2×1 square.

    Then, Snuke decided to paint these dominoes using three colors: red, cyan and green. Two dominoes that are adjacent by side should be painted by different colors. Here, it is not always necessary to use all three colors.

    Find the number of such ways to paint the dominoes, modulo 1000000007.

    The arrangement of the dominoes is given to you as two strings S1 and S2 in the following manner:

    • Each domino is represented by a different English letter (lowercase or uppercase).
    • The j-th character in Si represents the domino that occupies the square at the i-th row from the top and j-th column from the left.

    Constraints

    • 1N52
    • |S1|=|S2|=N
    • S1 and S2 consist of lowercase and uppercase English letters.
    • S1 and S2 represent a valid arrangement of dominoes.

    Input

    Input is given from Standard Input in the following format:

    N
    S1
    S2
    

    Output

    Print the number of such ways to paint the dominoes, modulo 1000000007.


    Sample Input 1

    Copy
    3
    aab
    ccb
    

    Sample Output 1

    Copy
    6
    

    There are six ways as shown below:


    Sample Input 2

    Copy
    1
    Z
    Z
    

    Sample Output 2

    Copy
    3
    

    Note that it is not always necessary to use all the colors.


    Sample Input 3

    Copy
    52
    RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
    RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn
    

    Sample Output 3

    Copy
    958681902
    
    这题判断下就行了。
    四种情况。
    1、
    aac
    bbc
    当假设判断到c了,ans*=1, a为1,b为2时,c只能为3
    2、
    aabb
    ccdd
    当判断到bb这时,ans*=3 假设a为1,c为2时 那个b和d有三种情况 (2,1)(2,3)(3,1)
    3、
    abb
    acc
    当判断到bb时,ans*=2 a为1时 b和c有(2,3)(3,2)
    4、
    ab
    ab
    当判断到b时,ans*=2,a为1时,b有 2,3


    但在首个位置特殊判断下就行。
     1 #include <bits/stdc++.h>
     2 #define ll long long
     3 using namespace std;
     4 const ll N = 110;
     5 const ll mod = 1000000007;
     6 char str[N], str1[N];
     7 int main() {
     8     ll n, ans = 1;
     9     cin >> n >> str >> str1;
    10     bool flag = false;
    11     for(ll i = 0; i < n; i ++) {
    12         if(i == 0) {
    13             if(str[i] == str1[i]) {
    14                 ans = 3;
    15             } else {
    16                 ans = 6;flag = true;i++;
    17             }
    18         }else {
    19             if(str[i] == str1[i]) {
    20                 if(flag) {
    21                     flag = false;
    22                 }else {
    23                     ans *= 2;
    24                     ans %= mod;
    25                 }
    26                 flag = false;
    27             } else {
    28                 if(flag) {
    29                     ans *= 3;
    30                     ans %= mod;
    31                 }else {
    32                     ans *= 2;
    33                     ans %= mod;
    34                 }
    35                 flag = true;
    36                 i++;
    37             }
    38         }
    39     }
    40     printf("%lld
    ",ans%mod);
    41     return 0;
    42 }
  • 相关阅读:
    委托学习笔记一(调用委托)
    委托和事件— 一个虚构的故事
    WPF中控制窗口状态
    oracle创建DBLINK
    添加路由 route add
    通过脚本执行sql语句
    c#对声音系统的控制
    ProcessBuilder调用外部脚本
    sql server 重新编译所有视图
    silverlight 隐藏ChildWindow 右上角的关闭按钮
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/7401434.html
Copyright © 2011-2022 走看看