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.
题意:一个周期的变化 给你一部分 判断下一个数的升降
题解:特殊数据为 0,15 特判就可以了
hack 上分
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#define ll long long
#define mod 1000000007
#define PI acos(-1.0)
using namespace std;
int n;
int ans[];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&ans[i]);
}
if(n==&&ans[]==){
cout<<"UP"<<endl;
return ;
}
if(n==&&ans[]==){
cout<<"DOWN"<<endl;
return ;
}
if(n==)
{
cout<<"-1"<<endl;
return ;
}
if(ans[n]==)
{
cout<<"UP"<<endl;
return ;
}
if(ans[n]==)
{
cout<<"DOWN"<<endl;
return ;
}
if(ans[n-]>ans[n])
cout<<"DOWN"<<endl;
else
cout<<"UP"<<endl; 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 to alternate. 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.
题意:给你一段'r''b'组成的串 两种操作 1.交换两个位置的字符 2.更改某个位置的字符
通过两种操作使得串变为‘r’‘b’交替的字符串 输出最小的操作步数。
题解:‘r’‘b’交替的字符串只有两种 暴力跑两遍
另外有一点 一次交换两个位置的字符相当于更改了两个位置的字符 所以优先交换
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#define ll long long
#define mod 1000000007
#define PI acos(-1.0)
using namespace std;
int n;
char a[];
char visr[];
char visb[];
int main()
{
scanf("%d",&n);
getchar();
int flag=;
for(int i=;i<=n;i++)
{
scanf("%c",&a[i]);
if(flag){
visr[i]='r';
visb[i]='b';
flag=;
}
else
{
visr[i]='b';
visb[i]='r';
flag=;
}
}
int ans=;
int jishu1=,jishu2=;
for(int i=;i<=n;i++)
{
if(visb[i]=='b'&&a[i]=='r')
jishu1++;
if(visb[i]=='r'&&a[i]=='b')
jishu2++;
}
int maxn=max(jishu1,jishu2);
ans=min(ans,maxn);
jishu1=;
jishu2=;
for(int i=;i<=n;i++)
{
if(visr[i]=='r'&&a[i]=='b')
jishu1++;
if(visr[i]=='b'&&a[i]=='r')
jishu2++;
}
maxn=max(jishu1,jishu2);
ans=min(ans,maxn);
cout<<ans<<endl;
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.
题意:长度为n的数 小数部分可以进位t次 使得进位之后大于原来的值 否则输出原来的值
题解:(对于逢9的一直进位算一次) 恶心模拟 去掉前导零 后导零 注意小数点
/*/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
#define A first
#define B second
const int N=;
const int mod=;
const int MOD1=;
const int MOD2=;
const double EPS=0.00000001;
//typedef long long ll;
typedef __int64 ll;
const ll MOD=;
const int INF=;
const ll MAX=1ll<<;
const double eps=1e-;
const double inf=~0u>>;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
int n,t;
char a[];
int main()
{
scanf("%d %d",&n,&t);
//getchar();
scanf("%s",a+);
int be;
a[]='';
for(int i=; i<=n; i++)
{
if(a[i]=='.')//找到小数点
{
be=i;
break;
}
}
int flag=-;
for(int i=be+; i<=n; i++)
{
if(a[i]>=''&&a[i]<='')
{
flag=i;//从左向右找到第一个能进位的地方
break;
}
}
int last=n;
while(t--)
{
if(flag==-)
break;
if(flag<=be)
break;
if(a[flag]>=''&&a[flag]<='')
{
a[flag]='';
flag--;
last=flag;
while()
{
if(a[flag]=='')//逢9一直进位
{
a[flag]='';
flag--;
}
else
{
if(flag==be){//对于小数点的处理
flag--;
continue;}
a[flag]=a[flag]+''+-'';
break;
}
}
}
else
break;//若已经不存在可进位 则高位更不会有 跳出
}
for(int i=last; i>=; i--)
{
if(a[i]=='')//去掉后导零
continue;
else
{
last=i;
break;
}
}
if(last==be)
last=be-;
be=;
if(a[]=='')
be=;
for(int i=be; i<=last; i++)
printf("%c",a[i]);
return ;
}
/*
12 5
872.04488525 */
Codeforces Round #373 (Div. 2) A B C 水 贪心 模拟(四舍五入进位)的更多相关文章
- Codeforces Round #372 (Div. 2) A B C 水 暴力/模拟 构造
A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #401 (Div. 2) A B C 水 贪心 dp
A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #550 (Div. 3) D. Equalize Them All (贪心,模拟)
题意:有一组数,可以选择某个数\(a_i\)相邻的一个数\(a_j\),然后可以让\(a_i\)加上或者减去\(|a_i-a_j|\),问最少操作多少次使得数组中所有数相同. 题解:不难发现,每次操作 ...
- Codeforces Round #481 (Div. 3) G. Petya's Exams (贪心,模拟)
题意:你有\(n\)天的时间,这段时间中你有\(m\)长考试,\(s\)表示宣布考试的日期,\(d\)表示考试的时间,\(c\)表示需要准备时间,如果你不能准备好所有考试,输出\(-1\),否则输出你 ...
- Codeforces Round #656 (Div. 3) C. Make It Good (贪心,模拟)
题意:给你一个数组\(a\),可以删除其前缀,要求操作后得到的数组是"good"的.对于"good":可以从数组的头和尾选择元素移动到新数组,使得所有元素移动后 ...
- 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 #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心
Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
随机推荐
- jQuery中的quickExpr
jQuery 源码中的 quickExpr 是用来检测参数 selector 是否是复杂的 HTML 代码(如“abc<div>”)或 #id,匹配结果存放在数组 match 中 // A ...
- S1:函数上下文
函数的上下文是可以变化的,因此,函数内的this也是可以变化的,函数可以作为一个对象的方法,也可以同时作为另一个对象的方法,总之,函数本身是独立的.可以通过Function对象上的call或者appl ...
- 免费提供一些公开的SOCK4/5/HTTP/HTTPS代理服务器(经测试可以用)
Last update IP address Port Country Type Anonymity 54 secs 116.228.55.217 8000 flag China HTTP High ...
- 使用read write 读写socket
一旦,我们建立好了tcp连接之后,我们就可以把得到的fd当作文件描述符来使用. 由此网络程序里最基本的函数就是read和write函数了. 写函数: ssize_t write(int fd, con ...
- POJ 2187 求凸包上最长距离
简单的旋转卡壳题目 以每一条边作为基础,找到那个最远的对踵点,计算所有对踵点的点对距离 这里求的是距离的平方,所有过程都是int即可 #include <iostream> #includ ...
- C++本质:类的赋值运算符=的重载,以及深拷贝和浅拷贝
关键词:构造函数,浅拷贝,深拷贝,堆栈(stack),堆heap,赋值运算符摘要: 在面向对象程序设计中,对象间的相互拷贝和赋值是经常进行的操作. 如果对象在申明的同时马上进行的初始化操作 ...
- 【转】linux下如何查看某个软件 是否安装?安装路径在哪
以redhat\centos 中php-mysql为例1:如果包是通过yum或者rpm方式安装[root@localhost yum.repos.d]# rpm -qa //找出系统所有的包,找到对应 ...
- app store 上架流程
前言:作为一名IOS开发者,把开发出来的App上传到App Store是必须的.下面就来详细介绍下具体流程. 1.打开苹果开发者中心:https://developer.apple.com 打开后点击 ...
- greenDao 3.0基础
引入greenDao3.0 首先在project的gradle文件中引入greenDAO插件 dependencies { classpath 'com.android.tools.bui ...
- InterruptedException 线程异常
InterruptedException 这个异常一般发生在线程中,当一个正在执行的线程被中断时就会出现这个异常-! 简单的说就是:假如有两个线程,第一个线程正在运行,第二个没有运行,这时第二个线程启 ...