A. Vitya in the Countryside
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

Examples
Input
5
3 4 5 6 7
Output
UP
Input
7
12 13 14 15 14 13 12
Output
DOWN
Input
1
8
Output
-1
Note

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 ;
}
B. Anatoly and Cockroaches
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

Examples
Input
5
rbbrr
Output
1
Input
5
bbbbb
Output
2
Input
3
rbr
Output
0
Note

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 ;
}
C. Efim and Strange Grade
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes.

Examples
Input
6 1
10.245
Output
10.25
Input
6 2
10.245
Output
10.3
Input
3 100
9.2
Output
9.2
Note

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 水 贪心 模拟(四舍五入进位)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces Round #550 (Div. 3) D. Equalize Them All (贪心,模拟)

    题意:有一组数,可以选择某个数\(a_i\)相邻的一个数\(a_j\),然后可以让\(a_i\)加上或者减去\(|a_i-a_j|\),问最少操作多少次使得数组中所有数相同. 题解:不难发现,每次操作 ...

  4. Codeforces Round #481 (Div. 3) G. Petya's Exams (贪心,模拟)

    题意:你有\(n\)天的时间,这段时间中你有\(m\)长考试,\(s\)表示宣布考试的日期,\(d\)表示考试的时间,\(c\)表示需要准备时间,如果你不能准备好所有考试,输出\(-1\),否则输出你 ...

  5. Codeforces Round #656 (Div. 3) C. Make It Good (贪心,模拟)

    题意:给你一个数组\(a\),可以删除其前缀,要求操作后得到的数组是"good"的.对于"good":可以从数组的头和尾选择元素移动到新数组,使得所有元素移动后 ...

  6. Codeforces Round #373 (Div. 1)

    Codeforces Round #373 (Div. 1) A. Efim and Strange Grade 题意 给一个长为\(n(n \le 2 \times 10^5)\)的小数,每次可以选 ...

  7. Codeforces Round #373 (Div. 2)A B

    Codeforces Round #373 (Div. 2) A. Vitya in the Countryside 这回做的好差啊,a想不到被hack的数据,b又没有想到正确的思维 = = [题目链 ...

  8. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  9. 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  ...

随机推荐

  1. jsp和servlet的区别

    servlet是服务器端的程序,动态生成html页面发到客户端,但是这样 程序里有许多out.println(),java和html语言混在一起很乱.所以 后来推出了jsp.其实jsp就是servle ...

  2. 二模 (4) day1

    第一题: 题目描述: 有一个无穷序列如下:110100100010000100000…请你找出这个无穷序列中指定位置上的数字 解题过程: 1.考虑到1的数目比0少的多,就从1的位置的规律开始分析.前几 ...

  3. 【NOIP模拟_54测试】【并查集】【二进制】【搜索】【区间序列类】

    第一题 Mushroom的序列 大意: 给一个序列,求一段连续最长区间满足:最多改变一个数,使得区间是严格的上升子序列. 解: 直接扫描一遍,记一个最长上升子序列编号.然后从每一个编号为1 的点来判断 ...

  4. WebBrowers & HtmlViewers collection

    WebBrowers & HtmlViewers collection 浏览: 加入我的收藏 楼主: THtmlViewerhttps://github.com/BerndGabriel/Ht ...

  5. Redhat6.x下如何进行远程安装虚拟机

    远程主机IP:192.168.122.1 远程主机名:server1.example.com 本地主机IP:192.168.122.2 本地主机名:server2.example.com 1.登录到远 ...

  6. 凭借K2 SmartObject框架,在SharePoint中集成数据

    随着SharePoint 2013的发布,Microsoft已提供Business Connectivity Services(BCS)增强功能以及外部列表功能,确保您可以更简单地在SharePoin ...

  7. 图像显示与加载——opencv(转)

    cvLoadImage() 函数:IplImage* cvLoadImage("图像名称",参数): 函数作用:加载图片: 函数返回值:为IplImage结构体: 参数说明:参数值 ...

  8. PHP汉字转拼音类

    看到的文章,转过来留用,哈哈 汉字转拼音类(全拼与首字母) <?php class GetPingYing { private $pylist = array( 'a'=>-20319, ...

  9. Android 自定义属性

    values新建一个attrs.xml<resource>    <declare-styleable name = "MyTextView">    &l ...

  10. 2799元的HTC One时尚版要卖疯了

    俗话说“好人有好报”,这句话同样可以应用到手机上.本月初,HTC正式公布了HTC One时尚版的售价,裸机2799元,礼包价2999元(配智能立显保护套).该价格一出,立刻引来一片哗然.因为大家都不相 ...