Educational Codeforces Round 153 (Rated for Div. 2)(VP-11,寒假加训)

VP时间

A.模拟

如果有()就是no

如果没有就2种情况

1.()()()

2.((()))

1.ac

B.贪心

用面值大的花色硬币肯定是最优解

但是如果所需的钱小于k那必须的用1块的花色硬币

分2种情况

1.1块普通硬币>=m%k

那就只要考虑剩下的硬币能不能凑成k面值

因此ak=ak+(a1-m%k)/k

如果ak>=m/k,就不需要

如果ak<m/k,就需要+k块花色硬币

2.1块普通硬币<m%k

因为k面值硬币不能拆开,因此必须要1块花色硬币

因此比较一下ak与m/k再加上m%k-a1即可

1.ac

C.

让自己不能移动就获胜

理解题意

先让Alice放

Bob移动一次,

Alice移动不了就必胜

所以放一个位置上,只留一个点让Bob就必胜

如果留太多点,Bob可以直接跳到倒数第2点,Alice必败

求最长上升子序列长度为2的数量(不会啊,导员没教我)

题解

A.

string(num,char)生成n个char

// Problem: A. Not a Substring
// Contest: Codeforces - Educational Codeforces Round 153 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1860/problem/A
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//へ     /|
//  /\7    ∠_/
//  / │   / /
// │ Z _,< /   /`ヽ
// │     ヽ   /  〉
//  Y     `  /  /
// イ● 、 ●  ⊂⊃〈  /
// ()  へ    | \〈
//  >ー 、_  ィ  │ //
//  / へ   / ノ<| \\
//  ヽ_ノ  (_/  │//
//	  7       |/
//	  >―r ̄ ̄`ー―_
#include <iostream>
#include <cstring>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 55;
int a[N];
struct node{
};
struct Lanthanmum{
	void start(){
		string s;
		cin>>s;
		int n=s.length();
		if(s=="()"){
			cout<<"NO"<<'\n';
			return;
		}
		cout<<"YES"<<'\n';
		bool ok=true;
		for(int i=1;i<n;i++){
			if(s[i]==s[i-1]){
				ok=false;
			}
		}
		if(ok){
			cout<<string(n,'(')+string(n,')')<<'\n';
		}else{
			for(int i=1;i<=n;i++){
				cout<<"()";
			}
			cout<<'\n';
		}
	}
}Genshin;
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int q;
	cin >> q;
	while (q--) {
		Genshin.start();
	}
	return 0;
}

B.

// Problem: B. Fancy Coins
// Contest: Codeforces - Educational Codeforces Round 153 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1860/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//へ     /|
//  /\7    ∠_/
//  / │   / /
// │ Z _,< /   /`ヽ
// │     ヽ   /  〉
//  Y     `  /  /
// イ● 、 ●  ⊂⊃〈  /
// ()  へ    | \〈
//  >ー 、_  ィ  │ //
//  / へ   / ノ<| \\
//  ヽ_ノ  (_/  │//
//	  7       |/
//	  >―r ̄ ̄`ー―_
#include <iostream>
#include <cstring>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
int a[N];
struct node{
};
struct Lanthanmum{
	void start(){
		ll m,k,a,b;
		cin>>m>>k>>a>>b;
		int x=m%k;
		int y=m/k;
		ll ans=0;
		if(a>=x){
			a-=x;
			a/=k;
			b+=a;
			ans=max(ans,y-b);		
		}else{
			ans=max(ans,y-b)+x-a;
		}
		cout<<ans<<'\n';
	}
}Genshin;
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int q;
	cin >> q;
	while (q--) {
		Genshin.start();
	}
	return 0;
}

C.

codeforce官方题解

我觉得通过代码可以理解一下

// Problem: C. Game on Permutation
// Contest: Codeforces - Educational Codeforces Round 153 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1860/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//へ     /|
//  /\7    ∠_/
//  / │   / /
// │ Z _,< /   /`ヽ
// │     ヽ   /  〉
//  Y     `  /  /
// イ● 、 ●  ⊂⊃〈  /
// ()  へ    | \〈
//  >ー 、_  ィ  │ //
//  / へ   / ノ<| \\
//  ヽ_ノ  (_/  │//
//	  7       |/
//	  >―r ̄ ̄`ー―_
#include <iostream>
#include <cstring>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
int a[N];
struct node{
};
struct Lanthanmum{
	void start(){
		int n;
		cin>>n;
		int ans=0;
		int mnlose=n+1,mnwin=n+1;//x最大是n
		while(n--){
			int x;
			cin>>x;
			if(mnlose<x && x<mnwin){//如果这个值大于mnwin,那它下一步必然要到mnwin不能到最小值.
				ans++;
				mnwin=x;//如果满足可以发现,这个点只能到最小值,在最小值之前的格子可以假设比最小值大或者等于那都过不去.
			}
			mnlose=min(mnlose,x);//不断更新最小值,就是在找当前的必胜格(让Bob不得不选择的格子)
		}
		cout<<ans<<'\n';
		
		
	}
}Genshin;
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int q;
	cin >> q;
	while (q--) {
		Genshin.start();
	}
	return 0;
}

求最长上升子序列长度为2

//へ     /|
//  /\7    ∠_/
//  / │   / /
// │ Z _,< /   /`ヽ
// │     ヽ   /  〉
//  Y     `  /  /
// イ● 、 ●  ⊂⊃〈  /
// ()  へ    | \〈
//  >ー 、_  ィ  │ //
//  / へ   / ノ<| \\
//  ヽ_ノ  (_/  │//
//	  7       |/
//	  >―r ̄ ̄`ー―_
#include <iostream>
#include <cstring>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
int a[N],stk[N],f[N],top;
struct node{
};
struct Lanthanmum{
	void start(){
		int n;
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			f[i]=0;
			stk[i]=0;
		}
		int top=0;
		int cnt=0;
		for(int i=1;i<=n;i++){
			f[i]=upper_bound(stk+1,stk+1+top,a[i])-stk;
			stk[f[i]]=a[i];
			top=max(top,f[i]);
			if(f[i]==2){
				cnt++;
			}
		}
		cout<<cnt<<'\n';
	}
}Genshin;
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int q;
	cin>>q;
	while (q--) {
		Genshin.start();
	}
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值