• AtCoder Beginner Contest 057 ABCD题


    A - Remaining Time


    Time limit : 2sec / Memory limit : 256MB

    Score : 100 points

    Problem Statement

    Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
    In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
    The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.

    Constraints

    • 0≤A,B≤23
    • A and B are integers.

    Input

    The input is given from Standard Input in the following format:

    A B
    

    Output

    Print the hour of the starting time of the contest in 24-hour time.


    Sample Input 1

    Copy
    9 12
    

    Sample Output 1

    Copy
    21
    

    In this input, the current time is 9 o'clock, and 12 hours later it will be 21 o'clock in 24-hour time.


    Sample Input 2

    Copy
    19 0
    

    Sample Output 2

    Copy
    19
    

    The contest has just started.


    Sample Input 3

    Copy
    23 2
    

    Sample Output 3

    Copy
    1
    

    The contest will begin at 1 o'clock the next day.

    题意:没啥好说的

    解法:也没啥好说的

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int n,m;
     4 int main()
     5 {
     6     cin>>n>>m;
     7     cout<<(n+m)%24<<endl;
     9     return 0;
    10 }

    B - Checkpoints


    Time limit : 2sec / Memory limit : 256MB

    Score : 200 points

    Problem Statement

    There are N students and M checkpoints on the xy-plane.
    The coordinates of the i-th student (1≤iN) is (ai,bi), and the coordinates of the checkpoint numbered j (1≤jM) is (cj,dj).
    When the teacher gives a signal, each student has to go to the nearest checkpoint measured inManhattan distance
    The Manhattan distance between two points (x1,y1) and (x2,y2) is |x1x2|+|y1y2|.
    Here, |x| denotes the absolute value of x.
    If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
    Which checkpoint will each student go to?

    Constraints

    • 1≤N,M≤50
    • −108≤ai,bi,cj,dj≤108
    • All input values are integers.

    Input

    The input is given from Standard Input in the following format:

    N M
    a1 b1
    :  
    aN bN
    c1 d1
    :  
    cM dM
    

    Output

    Print N lines.
    The i-th line (1≤iN) should contain the index of the checkpoint for the i-th student to go.


    Sample Input 1

    Copy
    2 2
    2 0
    0 0
    -1 0
    1 0
    

    Sample Output 1

    Copy
    2
    1
    

    The Manhattan distance between the first student and each checkpoint is:

    • For checkpoint 1|2−(−1)|+|0−0|=3
    • For checkpoint 2|2−1|+|0−0|=1

    The nearest checkpoint is checkpoint 2. Thus, the first line in the output should contain 2.

    The Manhattan distance between the second student and each checkpoint is:

    • For checkpoint 1|0−(−1)|+|0−0|=1
    • For checkpoint 2|0−1|+|0−0|=1

    When there are multiple nearest checkpoints, the student will go to the checkpoint with the smallest index. Thus, the second line in the output should contain 1.


    Sample Input 2

    Copy
    3 4
    10 10
    -10 -10
    3 3
    1 2
    2 3
    3 5
    3 5
    

    Sample Output 2

    Copy
    3
    1
    2
    

    There can be multiple checkpoints at the same coordinates.


    Sample Input 3

    Copy
    5 5
    -100000000 -100000000
    -100000000 100000000
    100000000 -100000000
    100000000 100000000
    0 0
    0 0
    100000000 100000000
    100000000 -100000000
    -100000000 100000000
    -100000000 -100000000
    

    Sample Output 3

    Copy
    5
    4
    3
    2
    1
    题意:问最短的集合点是哪个站?如果有多个最短则输出序号最小的
    解法:模拟
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int n,m;
     4 set<int>q;
     5 int dis(int x1,int y1,int x2,int y2)
     6 {
     7     return abs(x1-x2)+abs(y1-y2);
     8 }
     9 int a1[10000],b1[100000],a2[10000],b2[100000];
    10 int main()
    11 {
    12     cin>>n>>m;
    13     for(int i=1;i<=n;i++)
    14     {
    15         cin>>a1[i]>>b1[i];
    16     }
    17     for(int i=1;i<=m;i++)
    18     {
    19         cin>>a2[i]>>b2[i];
    20     }
    21     for(int i=1;i<=n;i++)
    22     {
    23         int pos;
    24         int Max=(1<<31)-1;
    25         for(int j=1;j<=m;j++)
    26         {
    27             int ans=dis(a1[i],b1[i],a2[j],b2[j]);
    28             //cout<<ans<<endl;
    29             if(ans<Max)
    30             {
    31                 pos=j;
    32                // cout<<pos<<endl;
    33                 Max=ans;
    34             }
    35         }
    36         cout<<pos<<endl;
    37     }
    38     return 0;
    39 }

    C - Digits in Multiplication


    Time limit : 2sec / Memory limit : 256MB

    Score : 300 points

    Problem Statement

    You are given an integer N.
    For two positive integers A and B, we will define F(A,B) as the larger of the following: the number of digits in the decimal notation of A, and the number of digits in the decimal notation of B.
    For example, F(3,11)=2 since 3 has one digit and 11 has two digits.
    Find the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such thatN=A×B.

    Constraints

    • 1≤N≤1010
    • N is an integer.

    Input

    The input is given from Standard Input in the following format:

    N
    

    Output

    Print the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such thatN=A×B.


    Sample Input 1

    Copy
    10000
    

    Sample Output 1

    Copy
    3
    

    F(A,B) has a minimum value of 3 at (A,B)=(100,100).


    Sample Input 2

    Copy
    1000003
    

    Sample Output 2

    Copy
    7
    

    There are two pairs (A,B) that satisfy the condition: (1,1000003) and (1000003,1). For these pairs, F(1,1000003)=F(1000003,1)=7.


    Sample Input 3

    Copy
    9876543210
    

    Sample Output 3

    Copy
    6
    题意:把N分解成a*b,求出a,b中最长的长度,然后所有最长的长度中取最小的
    解法:模拟
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int n,m;
     4 long long num;
     5 int Max;
     6 int Maxn=30;
     7 int main()
     8 {
     9     cin>>num;
    10     for(int i=sqrt(num);i>=1;i--)
    11     {
    12         if(num%i==0)
    13         {
    14             int ans1=0;
    15             int ans2=0;
    16             int x=num/i;
    17             int y=i;
    18             while(x)
    19             {
    20                 x/=10;
    21                 ans1++;
    22             }
    23             while(y)
    24             {
    25                 y/=10;
    26                 ans2++;
    27             }
    28             Max=max(ans1,ans2);
    29             Maxn=min(Max,Maxn);
    30         }
    31     }
    32     cout<<Maxn<<endl;
    33     return 0;
    34 }

    D - Maximum Average Sets


    Time limit : 2sec / Memory limit : 256MB

    Score : 400 points

    Problem Statement

    You are given N items.
    The value of the i-th item (1≤iN) is vi.
    Your have to select at least A and at most B of these items.
    Under this condition, find the maximum possible arithmetic mean of the values of selected items.
    Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.

    Constraints

    • 1≤N≤50
    • 1≤A,BN
    • 1≤vi≤1015
    • Each vi is an integer.

    Input

    The input is given from Standard Input in the following format:

    N A B
    v1
    v2
    ...
    vN
    

    Output

    Print two lines.
    The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10−6.
    The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.


    Sample Input 1

    Copy
    5 2 2
    1 2 3 4 5
    

    Sample Output 1

    Copy
    4.500000
    1
    

    The mean of the values of selected items will be maximized when selecting the fourth and fifth items. Hence, the first line of the output should contain 4.5.
    There is no other way to select items so that the mean of the values will be 4.5, and thus the second line of the output should contain 1.


    Sample Input 2

    Copy
    4 2 3
    10 20 10 10
    

    Sample Output 2

    Copy
    15.000000
    3
    

    There can be multiple ways to select items so that the mean of the values will be maximized.


    Sample Input 3

    Copy
    5 1 5
    1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
    

    Sample Output 3

    Copy
    1000000000000000.000000
    1
    

    题意:求最大的平均值,再求出选a到选b个有几种选法可以得到最大平均值

    解法:dp[i][j] 从i中选取了j个的和,sum[i][j] 从i中选取j个有多少种

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 long long dp[300][300],sum[300][300];
     4 long long a[300];
     5 long long n,l,r;
     6 int main()
     7 {
     8     for(int i=0;i<=200;i++)
     9     {
    10         sum[0][i]=0;
    11         sum[i][0]=1;
    12         sum[i][i]=1;
    13     }
    14     for(int i=0;i<=200;i++)
    15     {
    16         for(int j=0;j<=200;j++)
    17         {
    18             dp[i][j]=-1;
    19         }
    20     }
    21     dp[0][0]=0;
    22     cin>>n>>l>>r;
    23     for(int i=1;i<=n;i++)
    24     {
    25         cin>>a[i];
    26     }
    27     for(int i=1;i<=n;i++)
    28     {
    29         dp[i][0]=0;
    30         for(int j=1;j<=i&&j<=r;j++)
    31         {
    32             long long x=dp[i-1][j];
    33             long long y=dp[i-1][j-1]+a[i];
    34             if(x==y)
    35             {
    36                 dp[i][j]=x;
    37                 sum[i][j]=sum[i-1][j]+sum[i-1][j-1];
    38             }
    39             else if(x>y)
    40             {
    41                 dp[i][j]=x;
    42                 sum[i][j]=sum[i-1][j];
    43             }
    44             else
    45             {
    46                 dp[i][j]=y;
    47                 sum[i][j]=sum[i-1][j-1];
    48             }
    49         }
    50     }
    51     int pos=0;
    52     long long k=0;
    53     for(int i=l;i<=r&&i<=n;i++)
    54     {
    55         if(pos==0)
    56         {
    57             pos=i;
    58             k=sum[n][i];
    59         }
    60         else if(dp[n][i]*pos>dp[n][pos]*i)
    61         {
    62             pos=i;
    63             k=sum[n][i];
    64         }
    65         else if(dp[n][i]*pos==dp[n][pos]*i)
    66         {
    67             k+=sum[n][i];
    68         }
    69     }
    70     printf("%.6f
    ",dp[n][pos]*1.0/pos*1.0);
    71     cout<<k<<endl;
    72     return 0;
    73 }
  • 相关阅读:
    用代码说话:如何正确启动线程
    我的2019——菜鸟互联网找实习和工作记录
    Python网络爬虫——Appuim+夜神模拟器爬取得到APP课程数据
    用代码说话:如何在Java中实现线程
    用代码说话:synchronized关键字和多线程访问同步方法的7种情况
    RabbitMQ(四):使用Docker构建RabbitMQ高可用负载均衡集群
    RabbitMQ(三):RabbitMQ与Spring Boot简单整合
    RabbitMQ(二):RabbitMQ高级特性
    RabbitMQ(一):RabbitMQ快速入门
    使用Docker部署Spring Boot项目
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/6653025.html
Copyright © 2020-2023  润新知