CF Educational Codeforces Round 21
1 second
256 megabytes
standard input
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.
The first line contains integer number n (1 ≤ n ≤ 109) — current year in Berland.
Output amount of years from the current year to the next lucky one.
4
1
201
99
4000
1000
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;
1 second
256 megabytes
standard input
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.
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 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.
3 2
3 4 7
9.0000000000
1 1
10
10.0000000000
8 2
1 2 4 100000 123 456 789 1
28964.2857142857
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 ;
}
1 second
256 megabytes
standard input
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.
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 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.
2 10
8 7
6 4
4 4
1 1 1 1
1 1 1 1
3 10
9 8 10
-1
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的更多相关文章
- Educational Codeforces Round 21
Educational Codeforces Round 21 A. Lucky Year 个位数直接输出\(1\) 否则,假设\(n\)十进制最高位的值为\(s\),答案就是\(s-(n\mod ...
- CF Educational Codeforces Round 10 D. Nested Segments 离散化+树状数组
题目链接:http://codeforces.com/problemset/problem/652/D 大意:给若干个线段,保证线段端点不重合,问每个线段内部包含了多少个线段. 方法是对所有线段的端点 ...
- CF Educational Codeforces Round 3 E. Minimum spanning tree for each edge 最小生成树变种
题目链接:http://codeforces.com/problemset/problem/609/E 大致就是有一棵树,对于每一条边,询问包含这条边,最小的一个生成树的权值. 做法就是先求一次最小生 ...
- 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 ...
- 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 ...
- Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心
After several latest reforms many tourists are planning to visit Berland, and Berland people underst ...
- 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 ...
- Educational Codeforces Round 21 Problem A - C
Problem A Lucky Year 题目传送门[here] 题目大意是说,只有一个数字非零的数是幸运的,给出一个数,求下一个幸运的数是多少. 这个幸运的数不是最高位的数字都是零,于是只跟最高位有 ...
- 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 ...
随机推荐
- 用户登陆界面(jquery)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Android 实现类似于QQ空间相册的点击图片放大,再点后缩小回原来位置
前几天看到了有人在android5.0上实现了如下图一样的效果,我自己就去搜了下.参考了国外一篇文章和国内的一篇文章,最终实现了想要的效果.具体参考的网址我已经贴到文章末尾,大家可以去英文的那个网站看 ...
- Android View 背景选择器编写技巧
在项目中选择器的使用是非常多的,以下是本人在项目中的一些常用的背景选择器的写法 带边框下划线背景选择器效果图: 上面布局中放了10个CheckBox,然后设置了CheckBox的背景图片位,背景选择器 ...
- Mysql如何为表字段添加索引???
1.添加PRIMARY KEY(主键索引): ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` ) 2.添加UNIQUE(唯一索引) : ALTE ...
- SM2-DE
SM2单证书认证 下端 导入根证书以及通用证书[具有签名和加密证书的功能]和远端的证书[获取远端公钥信息] 1.配置证书域 crypto ca identity gernal exit 2.通过复制粘 ...
- JBOSS连接池默认连接数是多少?在哪个配置文件有这个默认的连接数?
如果你用的是是4.x的Jboss的话,请参考:docs/dtd/jboss-ds_1_0.dtd,相信你很容易就能找到控制最大/最小连接数的选项,应该是诸如:max-pool-size/min-poo ...
- LINUX提高openfire并发数(网上收集)
谷歌博客地址:http://tsaiquinn.blogspot.com/2014/10/linuxopenfire.html 影响连接数的元素包含三种:1)Linux的系统参数2)进程自身可以创建的 ...
- 状态压缩---区间dp第一题
标签: ACM 题目 Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is ...
- JavaScript实现的水果忍者游戏,支持鼠标操作
智能手机刚刚普及时,水果忍者这款小游戏可谓风靡一时.几年过去了,现在,让我们用纯JavaScript来实现这个水果忍者游戏,就算是为了锤炼我们的JavaScript开发技能吧. 大家可以通过这个链接在 ...
- bootstrap历练实例: 垂直胶囊式的导航菜单
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...