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 ...
随机推荐
- POJ 1573 Robot Motion 模拟 难度:0
#define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...
- UVa 11427 - Expect the Expected
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- DatagridView的CellLeave光标离开响应事件,实现某列数字自动求和
//光标离开DatagridView,循环获取DatagridView的每一行的第3列的值,相加传给重量 private void dgpz_dataGridView_CellLeave(object ...
- 一键制作u盘启动盘教程
第一步:制作完成u深度u盘启动盘 第二步:下载Ghost Win7系统镜像文件包,存入u盘启动盘 第三步:电脑模式更改成ahci模式,不然安装完成win7系统会出现蓝屏现象 正式安装步骤: u ...
- MySql插入记录时判断
我们在开发数据库相关的逻辑过程中, 经常检查表中是否已经存在这样的一条记录, 如果存在则更新或者不做操作, 如果没有存在记录,则需要插入一条新的记录. 这样的逻辑固然可以通过两条sql语句完成. SE ...
- COleDateTime类型的应用
使用COleDateTime类1) 获取当前时间. CTime time; time = CTime::GetCurrentTime();2) 获取时间元素. int y ...
- hash算法
作者:July.wuliming.pkuoliver 说明:本文分为三部分内容, 第一部分为一道百度面试题Top K算法的详解:第二部分为关于Hash表算法的详细阐述:第三部分为打造一个最快的Hash ...
- SharePoint 2013 Nintex Workflow 工作流帮助(七)
博客地址 http://blog.csdn.net/foxdave 工作流动作 11. Check out item(Libraries and lists分组) 与上一个对应,用于签出条目.如果一个 ...
- color 的一些处理
1.UIImage转换成UIcolor cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@" ...
- 转 如何用mt7620方案的rt2860v2驱动实现wifi探针功能,网上能搜到一些方法,但是讲的好模糊?
原文:http://www.zhihu.com/question/33559283 如何用mt7620方案的rt2860v2驱动实现wifi探针功能,网上能搜到一些方法,但是讲的好模糊? 如何用mt7 ...