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.

读英语啦,刚背完英语的我真是脑壳痛,其实就是”no more than 1 non-zero digit in its number“这点东西的意思,不超过1位不是0,找到比他大的,减一下就好。

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie();
int n;
cin>>n;
int t=,m=log10(n);
while(m--){
t=t*;
}
for(int i=;i<=;i++){
if(t*i>n){
cout<<t*i-n<<endl;
break;
}
}
return ;
}

本来使用用个循环处理的位数,用了log10真是清爽了许多。这个循环应该也可以省的直接cout<<(n/t+1)*t-n<<endl;

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.

K个连续子序列的和,用前缀和很简单啊,求贡献的话省时间也省空间

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie();
int n,k;
cin>>n>>k;
long long s=;
int p=n-k+;
int t=min(p,k);
for(int i=;i<n;i++){
long long q;
cin>>q;
s+=min(min(i+,n-i),t)*q;
}
printf("%.10f",(double)s/(double)p);
return ;
}
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.

C题是贪心啊,特判的

#include <bits/stdc++.h>
using namespace std;
int a[],b[],c[];
bool cmp(int x,int y)
{return a[x]>a[y];}
int main() {
ios::sync_with_stdio(false);
cin.tie();
int n,w,i;
cin>>n>>w;
for(i=;i<=n;++i){
cin>>a[i];
w-=b[i]=a[i]+>>;
c[i]=i;}
if(w<){
puts("-1");
return ;}
sort(c+,c+n+,cmp);
while(w)
for(i=;w&&i<=n;++i)
if(b[c[i]]<a[c[i]])++b[c[i]],--w;
for(i=;i<=n;++i)
printf("%d ",b[i]);
return ;
}

CF Educational Codeforces Round 21的更多相关文章

  1. Educational Codeforces Round 21

    Educational Codeforces Round 21  A. Lucky Year 个位数直接输出\(1\) 否则,假设\(n\)十进制最高位的值为\(s\),答案就是\(s-(n\mod ...

  2. CF Educational Codeforces Round 10 D. Nested Segments 离散化+树状数组

    题目链接:http://codeforces.com/problemset/problem/652/D 大意:给若干个线段,保证线段端点不重合,问每个线段内部包含了多少个线段. 方法是对所有线段的端点 ...

  3. CF Educational Codeforces Round 3 E. Minimum spanning tree for each edge 最小生成树变种

    题目链接:http://codeforces.com/problemset/problem/609/E 大致就是有一棵树,对于每一条边,询问包含这条边,最小的一个生成树的权值. 做法就是先求一次最小生 ...

  4. Educational Codeforces Round 21 D.Array Division(二分)

    D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  5. Educational Codeforces Round 21(A.暴力,B.前缀和,C.贪心)

    A. Lucky Year time limit per test:1 second memory limit per test:256 megabytes input:standard input ...

  6. Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心

    After several latest reforms many tourists are planning to visit Berland, and Berland people underst ...

  7. Educational Codeforces Round 21 Problem D(Codeforces 808D)

    Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into t ...

  8. Educational Codeforces Round 21 Problem A - C

    Problem A Lucky Year 题目传送门[here] 题目大意是说,只有一个数字非零的数是幸运的,给出一个数,求下一个幸运的数是多少. 这个幸运的数不是最高位的数字都是零,于是只跟最高位有 ...

  9. CF# Educational Codeforces Round 3 F. Frogs and mosquitoes

    F. Frogs and mosquitoes time limit per test 2 seconds memory limit per test 512 megabytes input stan ...

随机推荐

  1. Django的学习需要掌握的一些基础和初步搭建自己的框架

    一.Django的学习需要掌握的一些基础 第一个需要注意的点:客户端发送过来的数据结构组成: 第二个需要注意的点:动态网页和静态网页 静态网页:用户发送请求,服务端找到对应的静态文件返回给浏览器,静态 ...

  2. 自定义Mega菜单的巧妙实现

    查看了<云制造>官网源码,为其mega菜单的巧妙实现打call. 其另辟蹊径,采取父级主控分支的方法,仅对父级“增加/删除”控制标识,从而控制子层显示. <!DOCTYPE html ...

  3. 常用验证函数isset()/empty()/is_numeric()函数

    1) isset()用来检查变量是否设置,若变量存在且值不为NULL时为TRUE: 检查多个变量时变量要全部存在且值不为NULL时为TRUE: 若用函数unset()释放后再用isset()检测时为F ...

  4. vue.js学习总结

    下面使用的命令工具为git bash 使用命令行工具搭建vue.js项目 vue.js官网命令行工具安装 为了提升安装速度,建议将 npm 的注册表源设置为国内的镜像 1.输入命令:npm insta ...

  5. (三)mybatis之对Hibernate初了解

    前言:为什么会写Hibernate呢?因为HIbernate跟Mybatis一样,是以ORM模型为核心思想的,但是这两者有相似的地方也有差异的地方.通过这两种框架的比对,可以对mybatis有着更深的 ...

  6. Example of how to implement a view-based source list (NSOutlineView) using Cocoa Bindings

    You tagged this with the cocoa-bindings tag, so I assume you mean "with bindings." I whipp ...

  7. PJSIP-iOS源码编译

    官方文档https://trac.pjsip.org/repos/wiki/Getting-Started/iPhone 功能 在iPhone上可以实现的功能: 包含基于CoreAudio的音频设备, ...

  8. LeetCode || 双指针 / 单调栈

    11. Container With Most Water 题意:取两根求最大体积 思路:使用两个指针分别指向头和尾,然后考虑左右两根: 对于小的那根,如果选择了它,那么能够产生的最大体积一定是当前的 ...

  9. iOS 设计模式

    很赞的总结 iOS Design Patterns 中文版 IOS设计模式之一(MVC模式,单例模式) IOS设计模式之二(门面模式,装饰器模式) IOS设计模式之三(适配器模式,观察者模式) IOS ...

  10. 两种常见JS面向象写法

    基于构造函数 function Circle(r) { this.r = r; } Circle.PI = 3.14159; Circle.prototype.area = function() { ...