Codeforces Round #497 (Div. 2)

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;
}


未来可期。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值