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 ...
随机推荐
- xml数据解析调研
XML数据解析http://www.tuicool.com/articles/Nraau2(必用) http://www.cnblogs.com/pengyingh/articles/2342699. ...
- 2.精通前端系列技术之seajs模块化使工作更简单(二)
drag.js // JavaScript Document //B开发 define(function(require,exports,module){ function drag(obj){ ; ...
- ARC 类型转换:显式转换 id 和 void *
http://blog.csdn.net/chinahaerbin/article/details/9471419 /* * ARC有效时三种类型转换: */ 1.__bridge ...
- JSON:org.json的基本用法
java中用于解释json的主流工具有org.json.json-lib与gson,本文介绍org.json的应用. 官方文档: http://www.json.org/java/ http://de ...
- wp8.1 C#技巧: 计时器
public MainPage() { this.InitializeComponent(); this.timer = new DispatcherTimer();//新建委托时间实例 timer. ...
- 后台获取不规则排列RadioButton组的值
获取多个RadioButton的值,我们一般会使用服务器控件RadioButtonList: <asp:RadioButtonList ID="rbl" runat=&quo ...
- [转]理解WSRF之一 使用WS-ResourceProperties (整理自IBM网站)
理解 WSRF第1部分-使用 WS-ResourceProperties 本 教程是一个由 4 部分组成的系列文章中的第 1 部分,该系列介绍 WSRF(Web Services Resource ...
- iOS多线程之NSThread使用
iOS中的多线程技术 我们在iOS开发项目过程中,为了解决UI界面操作不被耗时操作阻塞,我们会使用到多线程技术.在iOS开发中,我们主要会用到三种多线程操作技术:NSThread,NSOperatio ...
- 重拾java系列一java基础(3)
这一章主要复习下以前所接触的算法, (1)选择排序法:在要排序的一组数中,选出最小的一个数与第一个位置的数交换:然后在剩下的数当中再找最小的与第二个位置的数交换,如此循环到倒数第二个数和最后一个数比较 ...
- apache http client vs urlconnection
Google has deprecated HttpClient Choose an HTTP Client Most network-connected Android apps use HTTP ...