• AtCoder Beginner Contest 071 ABCD


    1001

    求个绝对值比较大小喽

    1002

    把字符串出现的字母记录一下,然后遍历a-z,谁第一个没出现就输出谁

    1003

    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

    • 4≤N≤105
    • 1≤Ai≤109
    • 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.

    题意:选出四个点能组成矩形,且面积最大

    解法:选4个一样的点或者是选两个出现两次以上的最大数字

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 map<int,int>Mp,mp,ap;
     4 int n;
     5 long long A[123456];
     6 int ans;
     7 int main(){
     8     long long x=1,y=1;
     9     int flag1=0,flag2=0;
    10     scanf("%d",&n);
    11     for(int i=1;i<=n;i++){
    12         cin>>A[i];
    13         Mp[A[i]]++;
    14     }
    15     sort(A+1,A+1+n);
    16     for(int i=n;i>=1;i--){
    17         if(Mp[A[i]]>=2&&mp[A[i]]==0){
    18             mp[A[i]]=1;
    19             x*=A[i];
    20             ans++;
    21         }
    22         if(ans==2){
    23             flag1=1;
    24             break;
    25         }
    26     }
    27     for(int i=n;i>=1;i--){
    28         if(Mp[A[i]]>=4){
    29             y*=(A[i]*A[i]);
    30             flag2=1;
    31             break;
    32         }
    33     }
    34     if(flag1||flag2){
    35         cout<<max(x,y)<<endl;
    36     }else{
    37     cout<<"0"<<endl;
    38     }
    39     return 0;
    40 }

    Problem Statement

    We have a board with a 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

    • 1≤N≤52
    • |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. 原来没有
    aa
    aa这种情况,就说嘛,想了好久
    2.
    第一次出现的是横还是竖
    横 *6
    竖 *3
    出现横时,上一次出现的是
    横 *3
    竖 *2
    出现竖时,上一次出现的是
    横 *1
    竖 *2
     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <algorithm>
     4 #include <vector>
     5 #include <string.h>
     6 #include <map>
     7 #define int long long
     8 
     9 using namespace std;
    10 
    11 const int mod=1000000007;
    12 
    13 char str[12][100];
    14 
    15 signed main()
    16 {
    17     int n;
    18     scanf("%lld",&n);
    19     for(int i=0; i<2; i++)
    20     {
    21         scanf("%s",str[i]);
    22     }
    23     bool flag=false;
    24     int f=0;
    25     int t=1;
    26     for(int i=0; i<n; i++)
    27     {
    28         if(str[0][i]==str[0][i+1])
    29         {
    30             if(f==0)
    31             {
    32                 t*=3;
    33                 t*=2;
    34                 f=1;
    35             }
    36             else
    37             {
    38                 if(flag)
    39                 {
    40                     t*=2;
    41                     t*=1;
    42                 }
    43                 else
    44                 {
    45                     t*=3;
    46                 }
    47             }
    48             flag=false;
    49             i++;
    50         }
    51         else
    52         {
    53             if(str[0][i]==str[1][i])
    54             {
    55                 if(f==0)
    56                 {
    57                     t*=3;
    58                     f=1;
    59                 }
    60                 else
    61                 {
    62                     if(flag) t*=2;
    63                     else t*=1;
    64                 }
    65                 flag=true;
    66             }
    67         }
    68         t%=mod;
    69     }
    70     cout<<t<<endl;
    71     return 0;
    72 }
  • 相关阅读:
    《趣谈网络协议》(刘超老师)读后笔记记录 001
    jenkins安装配置
    Linux 磁盘分区,挂载以及格式化
    Linux三剑客之awk
    Linux三剑客之sed
    Linux-三剑客之grep
    date那些事儿
    zookeeper集群的搭建以及命令详解
    Java多线程
    mybatis获取自增主键
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/7402079.html
Copyright © 2020-2023  润新知