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:

  1. A B

Output

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


Sample Input 1

Copy
  1. 9 12

Sample Output 1

Copy
  1. 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
  1. 19 0

Sample Output 2

Copy
  1. 19

The contest has just started.


Sample Input 3

Copy
  1. 23 2

Sample Output 3

Copy
  1. 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)%<<endl;
  8. return ;
  9. }

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:

  1. N M
  2. a1 b1
  3. :
  4. aN bN
  5. c1 d1
  6. :
  7. 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
  1. 2 2
  2. 2 0
  3. 0 0
  4. -1 0
  5. 1 0

Sample Output 1

Copy
  1. 2
  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
  1. 3 4
  2. 10 10
  3. -10 -10
  4. 3 3
  5. 1 2
  6. 2 3
  7. 3 5
  8. 3 5

Sample Output 2

Copy
  1. 3
  2. 1
  3. 2

There can be multiple checkpoints at the same coordinates.


Sample Input 3

Copy
  1. 5 5
  2. -100000000 -100000000
  3. -100000000 100000000
  4. 100000000 -100000000
  5. 100000000 100000000
  6. 0 0
  7. 0 0
  8. 100000000 100000000
  9. 100000000 -100000000
  10. -100000000 100000000
  11. -100000000 -100000000

Sample Output 3

Copy
  1. 5
  2. 4
  3. 3
  4. 2
  5. 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[],b1[],a2[],b2[];
  10. int main()
  11. {
  12. cin>>n>>m;
  13. for(int i=;i<=n;i++)
  14. {
  15. cin>>a1[i]>>b1[i];
  16. }
  17. for(int i=;i<=m;i++)
  18. {
  19. cin>>a2[i]>>b2[i];
  20. }
  21. for(int i=;i<=n;i++)
  22. {
  23. int pos;
  24. int Max=(<<)-;
  25. for(int j=;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 ;
  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:

  1. 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
  1. 10000

Sample Output 1

Copy
  1. 3

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


Sample Input 2

Copy
  1. 1000003

Sample Output 2

Copy
  1. 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
  1. 9876543210

Sample Output 3

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

  1. N A B
  2. v1
  3. v2
  4. ...
  5. 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
  1. 5 2 2
  2. 1 2 3 4 5

Sample Output 1

Copy
  1. 4.500000
  2. 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
  1. 4 2 3
  2. 10 20 10 10

Sample Output 2

Copy
  1. 15.000000
  2. 3

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


Sample Input 3

Copy
  1. 5 1 5
  2. 1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996

Sample Output 3

Copy
  1. 1000000000000000.000000
  2. 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[][],sum[][];
  4. long long a[];
  5. long long n,l,r;
  6. int main()
  7. {
  8. for(int i=;i<=;i++)
  9. {
  10. sum[][i]=;
  11. sum[i][]=;
  12. sum[i][i]=;
  13. }
  14. for(int i=;i<=;i++)
  15. {
  16. for(int j=;j<=;j++)
  17. {
  18. dp[i][j]=-;
  19. }
  20. }
  21. dp[][]=;
  22. cin>>n>>l>>r;
  23. for(int i=;i<=n;i++)
  24. {
  25. cin>>a[i];
  26. }
  27. for(int i=;i<=n;i++)
  28. {
  29. dp[i][]=;
  30. for(int j=;j<=i&&j<=r;j++)
  31. {
  32. long long x=dp[i-][j];
  33. long long y=dp[i-][j-]+a[i];
  34. if(x==y)
  35. {
  36. dp[i][j]=x;
  37. sum[i][j]=sum[i-][j]+sum[i-][j-];
  38. }
  39. else if(x>y)
  40. {
  41. dp[i][j]=x;
  42. sum[i][j]=sum[i-][j];
  43. }
  44. else
  45. {
  46. dp[i][j]=y;
  47. sum[i][j]=sum[i-][j-];
  48. }
  49. }
  50. }
  51. int pos=;
  52. long long k=;
  53. for(int i=l;i<=r&&i<=n;i++)
  54. {
  55. if(pos==)
  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\n",dp[n][pos]*1.0/pos*1.0);
  71. cout<<k<<endl;
  72. return ;
  73. }

AtCoder Beginner Contest 057 ABCD题的更多相关文章

  1. AtCoder Beginner Contest 068 ABCD题

    A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...

  2. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  3. AtCoder Beginner Contest 069 ABCD题

    题目链接:http://abc069.contest.atcoder.jp/assignments A - K-City Time limit : 2sec / Memory limit : 256M ...

  4. AtCoder Beginner Contest 070 ABCD题

    题目链接:http://abc070.contest.atcoder.jp/assignments A - Palindromic Number Time limit : 2sec / Memory ...

  5. AtCoder Beginner Contest 051 ABCD题

    A - Haiku Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement As a New Yea ...

  6. AtCoder Beginner Contest 052 ABCD题

    A - Two Rectangles Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement The ...

  7. AtCoder Beginner Contest 054 ABCD题

    A - One Card Poker Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Ali ...

  8. AtCoder Beginner Contest 058 ABCD题

    A - ι⊥l Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Three poles st ...

  9. AtCoder Beginner Contest 050 ABC题

    A - Addition and Subtraction Easy Time limit : 2sec / Memory limit : 256MB Score : 100 points Proble ...

随机推荐

  1. Principle of least astonishment

    Principle of least astonishment - Wikipedia https://en.wikipedia.org/wiki/Principle_of_least_astonis ...

  2. 关于在PHP中当一个请求未完成时,再发起另一个请求被阻塞的问题

    最近做项目的时候遇到个问题,就是做阿里云oss大文件上传进度条显示,因为要实时查询上传分片进度,所以在上传的同时必须要再发起查询的请求,但是一直都是所有分片上传完成后查询的请求才执行,刚开始以为是阿里 ...

  3. 分享一个好用的函数吧,将js中的对象转成url参数

    JavaScript&jQuery获取url参数方法 这个函数呢是自己在写基于Vue+ElementUI管理后台时用到的,,下面列出来两种使用方式: 最普通的,封装一个js函数 /** * 对 ...

  4. 完美解决pip install scrapy,安装Scrapy错误:Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

    1,在Python3.6 安装Scrapy 出现以下报错 2,错误分析 红色报的错误指向的是Twisted 1,Twisted 没安装上 2,Twisted 没安装成功 3,Twisted 版本与Py ...

  5. set STL 简单说说

    set 这个容器,可以排序,以及去掉重复的东西 #include<bits/stdc++.h> using namespace std; int main() { string s; se ...

  6. 无限轮播器的bug修复

    前言:上一回实现了轮播器的自动滚动,但是有两个需要处理的bug. 1.增加需求:当用手拖拽控制轮播器的时候,停止自动滚动. 2.当同一个页面中有tableView,textView或scrollvie ...

  7. Ski Course Design

    链接 分析:读题!读题!读题!重要的事说三遍,中文翻译漏掉了一个重要的地方,每个只能用一次,调了一下午还以为标程错了,其实就是找一段长为17的区间,然后使所有都处于这个区间中代价最小,暴力枚举即可. ...

  8. NOIP2007普及 守望者的逃离

    传送门 普及组的题目……很水. 原来写了一个模拟不过好像状态考虑的不全得了80,这次我们考虑一下dp做法. 守卫者有两种移动的方法,一种是闪现,一种是跑,我们可以把闪现和跑分开处理. 首先只处理闪现的 ...

  9. input type=password 浏览器会自动填充密码的问题

    解决办法是在form上或input上添加autoComplete="off"这个属性. form表单的属性如下所示: 但是这个解决方案在谷歌和火狐上均有bug,下面来一个一个解决. ...

  10. 在 Ubuntu 系统中有三种设置环境变量 PATH 的方法。(ZT) repost

    来源地址: http://blog.csdn.net/jernymy/article/details/6547671 第一种适用于为单一用户设置PATH.第二种是为全局设置 PATH.第三种方法适合于 ...