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 ...
随机推荐
- Eclipse+Tomcat环境集成
1.下载Eclipse: 我用的Version: Mars.2 Release (4.5.2),直接在官网上下:http://www.eclipse.org/downloads/packages/re ...
- 保存 http request 的数据到数据库表
开发需求:把 http request 对象的数据保存到数据库中 第一步:编写 RequestInfoService 类,保存方法名是 saveRequestInfo // 保存request信息 p ...
- C# 操作字符串,在某些特定的字符后面或前面添加其它字符
C# 操作字符串,在某些特定的字符后面或前面添加其它字符,解决方法: 字符串替换或正则表达式替换即可. 示例:实现的是在每个“第”前面添加一个逗号,在每个“方案”后面添加一个冒号. string s ...
- VS远程调试虚拟机中的程序
1. 设置VS项目属性 => 调试页 例子如下 远程命令: C:\test.exe 工作目录 : C:\ 远程服务器名称: 192.168.xx.xx 查看网络共享 => 本地连 ...
- HDU 1398 Square Coins 平方硬币 (普通母函数,水)
题意: 有17种硬币,每种的面值为编号的平方,比如 1,4,9,16.....给出一个数字,求组成这个面值有多少种组法? 思路: 用普通母函数解,主要做的就是模拟乘法,因为硬币是无限的,所以每个构造式 ...
- CSS BEM 命名规范简介
[前言] BEM 是一个简单又非常有用的命名约定.让你的前端代码更容易阅读和理解,更容易协作,更容易控制,更加健壮和明确,而且更加严密.这篇文章主要介绍了CSS BEM 命名规范简介(推荐)的相关资料 ...
- Go统计键盘输入随机字母的个数
package main import "fmt" //通过键盘输入20个小写字母,统计个数 func main(){ //通过键盘器获取字符 var arr [20]byte f ...
- RN踩坑
使用夜神 使用夜神作为模拟器,这个模拟器启动就会监听62001端口. 开发工具与模拟器的通信都是通过adb.夜神模拟器的安装目录/bin下有一个adb.exe,android sdk tools下也有 ...
- Python面向对象(约束,异常处理,md5加密)(五)
1. 类的约束 1. 写一个父类. 父类中的某个方法要抛出一个异常 NotImplementedError class Base: def login(self): raise NotImplemen ...
- LeetCode(7)Reverse Integer
题目: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 分析: ...