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. Several ports (8005, 8080, 8009) required by Tomcat v7.0 Server at localhost are already in use.

    Several ports (8005, 8080, 8009) required by Tomcat v7.0 Server at localhost are already in use. The ...

  2. win7 MS SQL SERVER 2000安装

    http://blog.chinaunix.net/uid-24398518-id-2156226.html MicrosoftInternetExplorer402DocumentNotSpecif ...

  3. virtualbox安装提示出现严重错误解决办法

    解决办法: 在服务里面启动1. Device Install Service2. Device Setup Manager 这两个服务就好了.也有可能只需要启动第一个.

  4. 深入理解dispatch_queue

    Grand Central Dispatch是苹果过去几年创造出来的非常强大的API,在Let's Build系列的最新一期中,我们将探究dispatch_queue基础功能的重新实现.该主题是Rob ...

  5. checkbox的全选、反选、删除(适配器)

    package com.example.adapter; import java.util.List; import com.example.ay.R;import com.example.vo.Fl ...

  6. ios 检测应用程序升级问题

    app 上其实已经有自动检测我们版本的功能.  其实我也觉得对于一个程序员来说检测功能让,系统来维护更合适和合理.开发者只要告诉苹果即可. 然而今天老大非要实现自己版本更新的问题,因此也查找了相关的资 ...

  7. php访问数据库思维导图

  8. XCode之entitlement

    entitlement是codesign的一个输入,参见:codesign. entitlement的意思是权力,也就是表明应用所具有的权利,可以访问什么,不能访问什么等.这些信息会在codesign ...

  9. unity3d打包和包的使用

    打包: ①Assets下新建文件夹Editor和steamingAssets ②对选定文件打包: using UnityEngine; using UnityEditor; using System. ...

  10. Ubuntu 14.10 下安装navicat

    1 下载navicat,网址http://www.navicat.com.cn/download,我下载的是navicat111_premium_cs.tar.gz 2 解压到合适的位置 3 进入解压 ...