A
https://codeforces.com/contest/1008/problem/A
思路:
两种方法。
第一种是判断 i 位是否为consonant,然后判断 i + 1 位是否为Vowel。
第二种是判断 i 位是否为consonant,然后判断 i - 1 位是否为consonant。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vll;
const int MAXN = 1e6 + 10;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;
const double eps = 1e-8;
int n, m, k;
const string vowel = "aouie";
string str;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
cin >> str;
bool vaild = true;
for(int i = 1; i < (int)str.length(); i++){
bool exist = false;
for(int j = 0; j < (int)vowel.length(); j++)
if(str[i] == vowel[j]){
exist = true;
break;
}
if(exist)
continue;
else{
exist = false;
for(int j = 0; j < (int)vowel.length(); j++)
if(str[i - 1] == vowel[j]){
exist = true;
break;
}
if(exist || str[i - 1] == 'n')
continue;
vaild = false;
break;
}
}
if(vaild){
vaild = false;
for(int j = 0; j < (int)vowel.length(); j++)
if(str.back() == vowel[j]){
vaild = true;
break;
}
if(str.back() == 'n')
vaild = true;
}
if(vaild)
cout << "YES" << endl;
else
cout << "NO" << endl;
cerr << "execute time : " << (double)clock() / CLOCKS_PER_SEC << endl;
return 0;
}
B
https://codeforces.com/contest/1008/problem/B
思路:
每次选比上一次的小的最大。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vll;
const int MAXN = 1e6 + 10;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;
const double eps = 1e-8;
int n, m, k;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
cin >> n;
int last = INF;
for(int i = 0; i < n; i++){
int a, b;
cin >> a >> b;
if(a < b)
swap(a, b);
if(last >= a)
last = a;
else if(last >= b)
last = b;
else{
last = 0;
break;
}
}
if(last)
cout << "YES" << endl;
else
cout << "NO" << endl;
cerr << "execute time : " << (double)clock() / CLOCKS_PER_SEC << endl;
return 0;
}
C
https://codeforces.com/contest/1008/problem/C
思路:
从大到小,每次把比较大的和比较小的互换位置,然后再把比较小的和更小的互换位置。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vll;
const int MAXN = 1e6 + 10;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;
const double eps = 1e-8;
int n, m, k;
vi p, level;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
cin >> n;
p.resize(n);
for(int i = 0; i < n; i++)
cin >> p[i];
sort(p.begin(), p.end());
level.push_back(1);
for(int i = n - 2; i >= 0; i--){
if(p[i] != p[i + 1])
level.push_back(1);
else
level[level.size() - 1]++;
}
int res = 0, last = 0;
for(int i = 0; i < (int)level.size(); i++){
res += min(last, level[i]);
last += max(0, level[i] - last);
}
cout << res << endl;
cerr << "execute time : " << (double)clock() / CLOCKS_PER_SEC << endl;
return 0;
}
未来可期。