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 上分
1 /****************************** 2 code by drizzle 3 blog: www.cnblogs.com/hsd-/ 4 ^ ^ ^ ^ 5 O O 6 ******************************/ 7 #include<bits/stdc++.h> 8 #include<iostream> 9 #include<cstring> 10 #include<cmath> 11 #include<cstdio> 12 #define ll long long 13 #define mod 1000000007 14 #define PI acos(-1.0) 15 using namespace std; 16 int n; 17 int ans[105]; 18 int main() 19 { 20 scanf("%d",&n); 21 for(int i=1;i<=n;i++) 22 { 23 scanf("%d",&ans[i]); 24 } 25 if(n==1&&ans[1]==0){ 26 cout<<"UP"<<endl; 27 return 0; 28 } 29 if(n==1&&ans[1]==15){ 30 cout<<"DOWN"<<endl; 31 return 0; 32 } 33 if(n==1) 34 { 35 cout<<"-1"<<endl; 36 return 0; 37 } 38 if(ans[n]==0) 39 { 40 cout<<"UP"<<endl; 41 return 0; 42 } 43 if(ans[n]==15) 44 { 45 cout<<"DOWN"<<endl; 46 return 0; 47 } 48 if(ans[n-1]>ans[n]) 49 cout<<"DOWN"<<endl; 50 else 51 cout<<"UP"<<endl; 52 53 return 0; 54 }
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’交替的字符串只有两种 暴力跑两遍
另外有一点 一次交换两个位置的字符相当于更改了两个位置的字符 所以优先交换
1 /****************************** 2 code by drizzle 3 blog: www.cnblogs.com/hsd-/ 4 ^ ^ ^ ^ 5 O O 6 ******************************/ 7 #include<bits/stdc++.h> 8 #include<iostream> 9 #include<cstring> 10 #include<cmath> 11 #include<cstdio> 12 #define ll long long 13 #define mod 1000000007 14 #define PI acos(-1.0) 15 using namespace std; 16 int n; 17 char a[100005]; 18 char visr[100005]; 19 char visb[100005]; 20 int main() 21 { 22 scanf("%d",&n); 23 getchar(); 24 int flag=1; 25 for(int i=1;i<=n;i++) 26 { 27 scanf("%c",&a[i]); 28 if(flag){ 29 visr[i]='r'; 30 visb[i]='b'; 31 flag=0; 32 } 33 else 34 { 35 visr[i]='b'; 36 visb[i]='r'; 37 flag=1; 38 } 39 } 40 int ans=100005; 41 int jishu1=0,jishu2=0; 42 for(int i=1;i<=n;i++) 43 { 44 if(visb[i]=='b'&&a[i]=='r') 45 jishu1++; 46 if(visb[i]=='r'&&a[i]=='b') 47 jishu2++; 48 } 49 int maxn=max(jishu1,jishu2); 50 ans=min(ans,maxn); 51 jishu1=0; 52 jishu2=0; 53 for(int i=1;i<=n;i++) 54 { 55 if(visr[i]=='r'&&a[i]=='b') 56 jishu1++; 57 if(visr[i]=='b'&&a[i]=='r') 58 jishu2++; 59 } 60 maxn=max(jishu1,jishu2); 61 ans=min(ans,maxn); 62 cout<<ans<<endl; 63 return 0; 64 }
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的一直进位算一次) 恶心模拟 去掉前导零 后导零 注意小数点
1 /*/****************************** 2 code by drizzle 3 blog: www.cnblogs.com/hsd-/ 4 ^ ^ ^ ^ 5 O O 6 ******************************/ 7 #include<bits/stdc++.h> 8 #include<map> 9 #include<set> 10 #include<cmath> 11 #include<queue> 12 #include<bitset> 13 #include<math.h> 14 #include<vector> 15 #include<string> 16 #include<stdio.h> 17 #include<cstring> 18 #include<iostream> 19 #include<algorithm> 20 #pragma comment(linker, "/STACK:102400000,102400000") 21 using namespace std; 22 #define A first 23 #define B second 24 const int N=50010; 25 const int mod=1000000007; 26 const int MOD1=1000000007; 27 const int MOD2=1000000009; 28 const double EPS=0.00000001; 29 //typedef long long ll; 30 typedef __int64 ll; 31 const ll MOD=1000000007; 32 const int INF=1000000010; 33 const ll MAX=1ll<<55; 34 const double eps=1e-5; 35 const double inf=~0u>>1; 36 const double pi=acos(-1.0); 37 typedef double db; 38 typedef unsigned int uint; 39 typedef unsigned long long ull; 40 int n,t; 41 char a[200005]; 42 int main() 43 { 44 scanf("%d %d",&n,&t); 45 //getchar(); 46 scanf("%s",a+1); 47 int be; 48 a[0]='0'; 49 for(int i=1; i<=n; i++) 50 { 51 if(a[i]=='.')//找到小数点 52 { 53 be=i; 54 break; 55 } 56 } 57 int flag=-1; 58 for(int i=be+1; i<=n; i++) 59 { 60 if(a[i]>='5'&&a[i]<='9') 61 { 62 flag=i;//从左向右找到第一个能进位的地方 63 break; 64 } 65 } 66 int last=n; 67 while(t--) 68 { 69 if(flag==-1) 70 break; 71 if(flag<=be) 72 break; 73 if(a[flag]>='5'&&a[flag]<='9') 74 { 75 a[flag]='0'; 76 flag--; 77 last=flag; 78 while(1) 79 { 80 if(a[flag]=='9')//逢9一直进位 81 { 82 a[flag]='0'; 83 flag--; 84 } 85 else 86 { 87 if(flag==be){//对于小数点的处理 88 flag--; 89 continue;} 90 a[flag]=a[flag]+'0'+1-'0'; 91 break; 92 } 93 } 94 } 95 else 96 break;//若已经不存在可进位 则高位更不会有 跳出 97 } 98 for(int i=last; i>=0; i--) 99 { 100 if(a[i]=='0')//去掉后导零 101 continue; 102 else 103 { 104 last=i; 105 break; 106 } 107 } 108 if(last==be) 109 last=be-1; 110 be=0; 111 if(a[0]=='0') 112 be=1; 113 for(int i=be; i<=last; i++) 114 printf("%c",a[i]); 115 return 0; 116 } 117 /* 118 12 5 119 872.04488525 120 121 */