博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Educational Codeforces Round 21(A.暴力,B.前缀和,C.贪心)
阅读量:5737 次
发布时间:2019-06-18

本文共 6558 字,大约阅读时间需要 21 分钟。

A. Lucky Year

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.

You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year.

Input

The first line contains integer number n (1 ≤ n ≤ 109) — current year in Berland.

Output

Output amount of years from the current year to the next lucky one.

Examples
Input
4
Output
1
Input
201
Output
99
Input
4000
Output
1000
Note

In the first example next lucky year is 5. In the second one — 300. In the third — 5000.

题目链接:http://codeforces.com/contest/808/problem/A

分析:题目意思是要将下一个数字变为只有1个非0的数,打表即可,要注意开ll,否则会WA!

下面给出AC代码:

1 #include 
2 using namespace std; 3 typedef long long ll; 4 int main() 5 { 6 ll n; 7 while(scanf("%lld",&n)!=EOF) 8 { 9 if(n>=0&&n<=9)10 cout<<1<
=10&&n<=99)12 cout<<(n/10+1)*10-n<
=100&&n<=999)14 cout<<(n/100+1)*100-n<
=1000&&n<=9999)16 cout<<(n/1000+1)*1000-n<
=10000&&n<=99999)18 cout<<(n/10000+1)*10000-n<
=100000&&n<=999999)20 cout<<(n/100000+1)*100000-n<
=1000000&&n<=9999999)22 cout<<(n/1000000+1)*1000000-n<
=10000000&&n<=99999999)24 cout<<(n/10000000+1)*10000000-n<
=100000000&&n<=999999999)26 cout<<(n/100000000+1)*100000000-n<
=1000000000&&n<=9999999999)28 cout<<(n/1000000000+1)*1000000000-n<

B. Average Sleep Time

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days!

When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day.

The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is .

You should write a program which will calculate average sleep times of Polycarp over all weeks.

Input

The first line contains two integer numbers n and k (1 ≤ k ≤ n ≤ 2·105).

The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 105).

Output

Output average sleeping time over all weeks.

The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point.

Examples
Input
3 2 3 4 7
Output
9.0000000000
Input
1 1 10
Output
10.0000000000
Input
8 2 1 2 4 100000 123 456 789 1
Output
28964.2857142857
Note

In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7.

题目链接:http://codeforces.com/contest/808/problem/B
分析:计算上升和下降的序列数之和,再除以n-k+1即可,相当于求其中每k个数的和的平均值!
下面给出AC代码:
1 #include 
2 typedef long long ll; 3 using namespace std; 4 ll n,k; 5 double avg; 6 ll ans; 7 ll s[200005]; 8 int main() 9 {10 cin>>n>>k;11 for(int i=1;i<=n;i++)12 scanf("%I64d",s+i);13 ll c=0;14 for(int i=1;i<=n;i++)15 {16 if(i<=n-k+1)17 {18 if(c
n-i+1)25 c--;26 ans+=c*s[i];27 }28 }29 avg=ans*1.0/(n-k+1);30 printf("%0.12lf",avg);31 return 0;32 }

C. Tea Party

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that:

  • Every cup will contain tea for at least half of its volume
  • Every cup will contain integer number of milliliters of tea
  • All the tea from the teapot will be poured into cups
  • All friends will be satisfied.

Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj.

For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1.

Input

The first line contains two integer numbers n and w (1 ≤ n ≤ 100, ).

The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100).

Output

Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them.

If it's impossible to pour all the tea and satisfy all conditions then output -1.

Examples
Input
2 10 8 7
Output
6 4
Input
4 4 1 1 1 1
Output
1 1 1 1
Input
3 10 9 8 10
Output
-1
Note

In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available.

题目链接:http://codeforces.com/contest/808/problem/C

题意:n个茶杯,每个茶杯有容量。现在给一壶茶,总量为w。希望倒茶满足条件:每杯茶要超过容量的一半,并且w被倒光,茶杯内的茶水为整数,容量大的杯子内的茶不允许比容量小的杯子内的茶水少,特判不满足情况,然后将茶水给每一杯倒至一半以上。然后按照容量从大到小每次倒一个单位,直到倒完为止。

分析:贪心求解!
下面给出AC代码:
1 #include 
2 using namespace std; 3 class Tea 4 { 5 public: 6 int a,w,id; 7 }; 8 Tea t[105]; 9 int n,w;10 int cmp1(Tea a,Tea b)11 {12 return a.a>b.a;13 }14 int cmp2(Tea a,Tea b)15 {16 return a.id
>n>>w;21 for(int i=0;i
>t[i].a;24 t[i].id=i;25 }26 sort(t,t+n,cmp1); //杯子大到小排序27 for(int i=0;i
=x)36 {37 t[i].w+=x;38 w-=x;39 }40 else if(w>0)41 {42 t[i].w+=w;43 w=0;44 }45 else46 break;47 }48 sort(t,t+n,cmp2); //按照id 排序 排回原位49 if(w<0)50 cout<<-1;51 else52 for(int i=0;i

 

           
       

           

              
       

           

转载地址:http://hvwzx.baihongyu.com/

你可能感兴趣的文章
如何很好的Review自己的代码
查看>>
Castle.Net 基本应用
查看>>
echarts 应用数个样例
查看>>
Kafka
查看>>
《4》CentOS7.0+OpenStack+kvm云平台部署—配置Nova
查看>>
LoadRunner测试WebService的3种方式
查看>>
SQL0294N 容器已在使用中。 SQLSTATE=42730
查看>>
Oracle数据库启动时:ORA-00119: invalid specification for system parameter LOCAL_LISTENER; ORA-00132错误解决...
查看>>
JS jQuery json日期格式问题的办法
查看>>
Python LOGGING使用方法
查看>>
Vi编辑器的使用
查看>>
Could not evaluate expression
查看>>
System.BadImageFormatException: 未能加载文件或程序集""或它的某一个依赖项。试图加载格式不正确的程序。...
查看>>
DOM基础
查看>>
The user operation is waiting for "Building workspace" to complete
查看>>
【转】段错误调试神器 - Core Dump详解
查看>>
《C#本质论》读书笔记(14)支持标准查询操作符的集合接口
查看>>
创建零时表、表变量
查看>>
Mybatis 示例之 foreach
查看>>
cookie自动登录的实现
查看>>