Codeforces Round #373 (Div. 2) A , B , C
1 second
256 megabytes
standard input
standard output
Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.
Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0.
As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has.
The first line of the input contains a single integer n (1 ≤ n ≤ 92) — the number of consecutive days Vitya was watching the size of the visible part of the moon.
The second line contains n integers ai (0 ≤ ai ≤ 15) — Vitya's records.
It's guaranteed that the input data is consistent.
If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1.
- 5
3 4 5 6 7
- UP
- 7
12 13 14 15 14 13 12
- DOWN
- 1
8
- -1
In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP".
In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN".
In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.
- #include<bits/stdc++.h>
- using namespace std;
- #define ll __int64
- #define mod 1000000007
- #define pi (4*atan(1.0))
- const int N=1e5+,M=4e6+,inf=1e9+;
- int a[N];
- int main()
- {
- int x;
- scanf("%d",&x);
- for(int i=;i<=x;i++)
- {
- scanf("%d",&a[i]);
- }
- if(a[x]==)
- {
- printf("UP\n");
- return ;
- }
- else if(a[x]==)
- {
- printf("DOWN\n");
- return ;
- }
- else if(x==)
- {
- printf("-1\n");
- return ;
- }
- if(a[x]-a[x-]==)
- printf("UP\n");
- else
- printf("DOWN\n");
- return ;
- }
1 second
256 megabytes
standard input
standard output
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line toalternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches.
The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.
Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.
- 5
rbbrr
- 1
- 5
bbbbb
- 2
- 3
rbr
- 0
In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0.
- #include<bits/stdc++.h>
- using namespace std;
- #define ll __int64
- #define mod 1000000007
- #define pi (4*atan(1.0))
- const int N=1e5+,M=4e6+,inf=1e9+;
- char a[N];
- char b[N];
- char c[N];
- int checkb(int x)
- {
- int ji=,ou=;
- for(int i=;i<=x;i++)
- {
- if(a[i]!=b[i])
- {
- if(i&)
- ji++;
- else
- ou++;
- }
- }
- return max(ji,ou);
- }
- int checkc(int x)
- {
- int ji=,ou=;
- for(int i=;i<=x;i++)
- {
- if(a[i]!=c[i])
- {
- if(i&)
- ji++;
- else
- ou++;
- }
- }
- return max(ji,ou);
- }
- int main()
- {
- int x;
- for(int i=;i<=;i++)
- if(i&)
- b[i]='r',c[i]='b';
- else
- b[i]='b',c[i]='r';
- scanf("%d",&x);
- scanf("%s",a+);
- printf("%d\n",min(checkb(x),checkc(x)));
- return ;
- }
1 second
256 megabytes
standard input
standard output
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer).
There are t seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than t seconds. Note, that he can choose to not use all t seconds. Moreover, he can even choose to not round the grade at all.
In this problem, classic rounding rules are used: while rounding number to the n-th digit one has to take a look at the digit n + 1. If it is less than 5 than the n-th digit remain unchanged while all subsequent digits are replaced with 0. Otherwise, if the n + 1 digit is greater or equal to 5, the digit at the position n is increased by 1 (this might also change some other digits, if this one was equal to 9) and all subsequent digits are replaced with 0. At the end, all trailing zeroes are thrown away.
For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if we round 1.5 to the nearest integer, the result is 2. Rounding number 1.299996121 in the fifth decimal place will result in number 1.3.
The first line of the input contains two integers n and t (1 ≤ n ≤ 200 000, 1 ≤ t ≤ 109) — the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with 0.
Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes.
- 6 1
10.245
- 10.25
- 6 2
10.245
- 10.3
- 3 100
9.2
- 9.2
In the first two samples Efim initially has grade 10.245.
During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all.
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define pi (4*atan(1.0))
- const int N=2e5+,M=4e6+,inf=1e9+,mod=1e9+;
- char a[N];
- int check(int st,int x)
- {
- for(int i=st+;i<=x;i++)
- if(a[i]>=''&&a[i]<='')
- return i;
- return -;
- }
- int main()
- {
- int x,y,st;
- a[]='';
- scanf("%d%d",&x,&y);
- scanf("%s",a+);
- for(int i=;i<=x;i++)
- if(a[i]=='.')
- {
- st=i;
- break;
- }
- int last=x;
- int v=check(st,last);;
- while(y--)
- {
- if(v==-)
- break;
- last=v-;
- int sta=v-;
- while()
- {
- if(a[sta]=='.')
- {
- sta--;
- while()
- {
- a[sta]+=;
- if(a[sta]>'')
- a[sta]='';
- else
- break;
- sta--;
- }
- v=-;
- break;
- }
- a[sta]+=;
- if(a[sta]>'')
- a[sta]='';
- else
- {
- if(a[sta]>='')
- v=sta;
- else
- v=-;
- break;
- }
- sta--;
- }
- }
- while()
- {
- if(a[last]=='.')
- {
- last--;
- break;
- }
- else if(a[last]=='')continue;
- else
- break;
- last--;
- }
- if(a[]!='')
- printf("%c",a[]);
- for(int i=;i<=last;i++)
- printf("%c",a[i]);
- printf("\n");
- return ;
- }
Codeforces Round #373 (Div. 2) A , B , C的更多相关文章
- Codeforces Round #373 (Div. 1)
Codeforces Round #373 (Div. 1) A. Efim and Strange Grade 题意 给一个长为\(n(n \le 2 \times 10^5)\)的小数,每次可以选 ...
- Codeforces Round #373 (Div. 2)A B
Codeforces Round #373 (Div. 2) A. Vitya in the Countryside 这回做的好差啊,a想不到被hack的数据,b又没有想到正确的思维 = = [题目链 ...
- Codeforces Round #373 (Div. 2) C. Efim and Strange Grade 水题
C. Efim and Strange Grade 题目连接: http://codeforces.com/contest/719/problem/C Description Efim just re ...
- Codeforces Round #373 (Div. 2) C. Efim and Strange Grade —— 贪心 + 字符串处理
题目链接:http://codeforces.com/problemset/problem/719/C C. Efim and Strange Grade time limit per test 1 ...
- Codeforces Round #373 (Div. 2)
A,B,C傻逼题,就不说了. E题: #include <iostream> #include <cstdio> #include <cstring> #inclu ...
- Codeforces Round #373 (Div. 2) A B C 水 贪心 模拟(四舍五入进位)
A. Vitya in the Countryside time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces Round #373 (Div. 2) E. Sasha and Array 线段树维护矩阵
E. Sasha and Array 题目连接: http://codeforces.com/contest/719/problem/E Description Sasha has an array ...
- Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题
B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...
- Codeforces Round #373 (Div. 2) A. Vitya in the Countryside 水题
A. Vitya in the Countryside 题目连接: http://codeforces.com/contest/719/problem/A Description Every summ ...
- 线段树+矩阵快速幂 Codeforces Round #373 (Div. 2) E
http://codeforces.com/contest/719/problem/E 题目大意:给你一串数组a,a[i]表示第i个斐波那契数列,有如下操作 ①对[l,r]区间+一个val ②求出[l ...
随机推荐
- java.lang.Error: Unresolved compilation problems: Syntax error on token "return", delete this token Type mismatch: cannot convert from Init to String
java.lang.Error: Unresolved compilation problems: Syntax error on token "return", delete ...
- NoSQL 数据库分类 颠覆
NoSQL 数据库分类 类型 部分代表特点 列存储 HbaseCassandraHypertable顾名思义,是按列存储数据的.最大的特点是方便存储结构化和半结构化数据,方便做数据压缩,对针对某一列或 ...
- webview自动循环播放
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=&q ...
- 博客没内容可写了怎么办?找BD!
博客写了一段时间可能会感觉没内容可以写了,或者说同一个领域的内容写多了感觉有点千篇一律,这时要考虑扩展自己的写作领域,怎么去扩展呢?利用关键词工具可以衍生很多长尾词,当然这个有点牵强,有点为优化而优化 ...
- 020-Spring Boot 监控和度量
一.概述 通过配置使用actuator查看监控和度量信息 二.使用 2.1.建立web项目,增加pom <dependency> <groupId>org.springfram ...
- 《Deep learning》第四章——数值计算
数值计算 机器学习算法通常需要大量的数值计算.这通常是指通过迭代过程更新解的估计值来解决数学问题的算法,而不是通过解析过程推导出公式来提供正确解的方法.常见的操作包括优化(找到最小化或最大化函数值的参 ...
- 交叉熵(Cross-Entropy) [转载]
交叉熵(Cross-Entropy) 交叉熵是一个在ML领域经常会被提到的名词.在这篇文章里将对这个概念进行详细的分析. 1.什么是信息量? 假设X是一个离散型随机变量,其取值集合为X,概率分布函数为 ...
- Oracle11g用户频繁锁定并且解锁后不允许登录
原因有可能是oracle的密码过期机制导致的:一.由于Oracle中默认在default概要文件中设置了“PASSWORD_LIFE_TIME=180天”所导致.解决办法:1.查看用户用的哪种prof ...
- Docker基础入门实践
原文地址 基本概念 Docker三个基本概念 镜像(Image) 容器(Container) 仓库(Repository) 镜像 镜像可以理解为只读模板,如包含一个centos操作系统环境 容器 Do ...
- 构建Ruby开发环境(Windows+Eclipse+Aptana Plugin)
1.安装Ruby ①.从http://rubyinstaller.org/downloads/下载安装包:rubyinstaller-2.2.5-x64.exe,直接安装.(so easy) 2.安装 ...