Codeforces Round #497 (Div. 2)
A. Romaji
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not.
Help Vitya find out if a word ss is Berlanese.
Input
The first line of the input contains the string ss consisting of |s||s| (1≤|s|≤1001≤|s|≤100) lowercase Latin letters.
Output
Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".
You can print each letter in any case (upper or lower).
Examples
input
Copy
sumimasen
output
Copy
YES
input
Copy
ninja
output
Copy
YES
input
Copy
codeforces
output
Copy
NO
Note
In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.
In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.
就是问你他给你的这个字符串是否满足以下条件:
(1).a.o.u.i.e是元音,其他是辅音
(2).每个辅音后面必须有一个元音
(3).特殊的,n字符后面可以是任何字符,后面没有字符(作为结尾)也行
满足就输出YES,否则NO
就是正常的挨个字符判断咯
#include
bool yuanyin[26]; //yuanyin[i]为真的意义是字符'a'+i为元音
char s[101];
void solve(){
for(int i=0;i<26;i++) yuanyin[i]=false;
yuanyin['a']=true;
yuanyin['o']=true;
yuanyin['u']=true;
yuanyin['i']=true;
yuanyin['e']=true;
scanf("%s",&s);
bool ans=true;
for(int i=0;s[i];i++){
if(s[i]=='n') continue;
else if(!yuanyin[s[i]]){
if(!yuanyin[s[i+1]]) ans=false;
}
}
if(ans) printf("YES\n");
else printf("NO\n");
}
int main(){
solve();
return 0;
}
B. Turn the Rectangles
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
There are nn rectangles in a row. You can either turn each rectangle by 9090 degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles.
Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such).
Input
The first line contains a single integer nn (1≤n≤1051≤n≤105) — the number of rectangles.
Each of the next nn lines contains two integers wiwi and hihi (1≤wi,hi≤1091≤wi,hi≤109) — the width and the height of the ii-th rectangle.
Output
Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO".
You can print each letter in any case (upper or lower).
Examples
input
Copy
3
3 4
4 6
3 5
output
Copy
YES
input
Copy
2
3 4
5 5
output
Copy
NO
Note
In the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3].
In the second test, there is no way the second rectangle will be not higher than the first one.
抛开这些无用的东西,题就是给你n对数字,然后问你可不可以完成这么一个操作:从每对数字中选出其中一个,使按选的顺序排列的这一串数列是非递增数列,其实就是后面的数字都要小于等于前面的数字。可以的话输出YES,否则NO.
贪心法则咯,选取第i个的时候选ai和bi两个数字中既满足小于等于前面所选数字又较大的那个数字就好,哪里选不出来了就证明该输出NO了.
#include
void solve(){
int n,a,b;
scanf("%d",&n);
bool ans=true;
int nowhight=1000000009;
for(int i=0;ib?a:b;
continue;
}
else if(a<=nowhight){
nowhight=a;
continue;
}else if(b<=nowhight){
nowhight=b;
continue;
}
ans=false;
}
if(ans) printf("YES\n");
else printf("NO\n");
}
int main(){
solve();
return 0;
}
C. Reorder the Array
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.
For instance, if we are given an array [10,20,30,40][10,20,30,40], we can permute it so that it becomes [20,40,10,30][20,40,10,30]. Then on the first and the second positions the integers became larger (20>1020>10, 40>2040>20) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals 22. Read the note for the first example, there is one more demonstrative test case.
Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.
Input
The first line contains a single integer nn (1≤n≤1051≤n≤105) — the length of the array.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the elements of the array.
Output
Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.
Examples
input
Copy
7
10 1 1 1 5 5 3
output
Copy
4
input
Copy
5
1 1 1 1 1
output
Copy
0
Note
In the first sample, one of the best permutations is [1,5,5,3,10,1,1][1,5,5,3,10,1,1]. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.
In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
抛开无用的描述,其实就是给你n个数字,让你任意把数字的位置对换,让你输出最多能使得多少个位置的数字比原来这个位置的数字大.
因为我们只用输出多少个位置不用输出具体是哪些位置,故而我们先把n个数字升序排序一下,然后全部压进小根堆,从最小的数字开始在堆中找大于这个数字的最小的数,就这么贪心下去,小根堆被出空了就结束,输出找到了几个。
#include
#include
#include
#include
using namespace std;
int a[100006];
void solve(){
int n;
scanf("%d",&n);
for(int i=0;i,greater > que;
for(int i=0;ia[i]){
que.pop();
ans++;
break;
}
que.pop();
}
}
printf("%d\n",ans);
}
int main(){
solve();
return 0;
}