Hello 2024

A. Wallet Exchange

image
image

#include<bits/stdc++.h>
using namespace std;
void solve(){
	int a,b;
	cin>>a>>b;
	int k=a+b;
	if(!(k&1)){
		cout<<"Bob\n";
	}else{
		cout<<"Alice\n";
	}
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 

B. Plus-Minus Split

image
image
image

前缀和

#include<bits/stdc++.h>
using namespace std;
int pre[100000];
void solve(){
	int n;
	string s;
	cin>>n>>s;
	for(int i=1;i<=n;i++){
		int x;
		if(s[i-1]=='-')x=-1;
		else x=1;
		pre[i]=pre[i-1]+x;
	}
	cout<<abs(pre[n])<<"\n";
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 

C. Grouping Increases

image
image
image

贪心

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N];
void solve(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	vector<int>s;
	vector<int>t;
	int ans=0;
	s.push_back(a[1]);
	for(int i=2;i<=n;i++){
		if(t.empty()){
			if(s.back()>=a[i]){
				s.push_back(a[i]);
			}else{
				t.push_back(a[i]);
			}
		}else{
			if(s.back()>=a[i]&&t.back()>=a[i]&&s.back()>t.back()){
				t.push_back(a[i]);
			}else if(s.back()>=a[i]&&t.back()>=a[i]&&s.back()<=t.back()){
				s.push_back(a[i]);
			}else if(s.back()>=a[i]&&t.back()<a[i]){
				s.push_back(a[i]);
			}else if(s.back()<a[i]&&t.back()>=a[i]){
				t.push_back(a[i]);
			}else if(s.back()<a[i]&&t.back()<a[i]){
				ans++;
		if(t.back()>s.back()){
			s.push_back(a[i]);
		}else{
			t.push_back(a[i]);
		}
			}
		}
	}
	cout<<ans<<"\n";
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 
posted @ 2024-01-08 14:20  yufan1102  阅读(20)  评论(0编辑  收藏  举报