Codeforces Round 849(Div.4)

Codeforces Round 849 (Div. 4)

蒟蒻的CODEFORCES补题
(能力不够,写不完)

A - Codeforces Checking

#include <bits/stdc++.h>

using namespace std;

string str = "codeforces";

int main(){
	int n;
	cin >> n;
	while(n -- ){
		char c;
		cin >> c;
		int res = str.find(c);
		if(res == -1)cout << "NO" << endl;
		else cout << "YES" << endl;
		
	}
	return 0;
} 

B - Following Directions

#include <bits/stdc++.h>

using namespace std;

int main(){
	
	int t;
	cin >> t;
	
	while(t -- ){
		int x = 0, y = 0,n;
		string move;
		bool flag = false;
		cin >> n >> move;
		for(int i = 0;i < move.length() && !flag;i ++ ){
			if(move[i] == 'U')y ++ ;
			else if(move[i] == 'D')y -- ;
			else if(move[i] == 'L')x -- ;
			else x ++ ;
			
			if(x == 1 && y == 1){
				flag = true;
			}
		}
		if(flag)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
} 

C - Prepend and Append

#include <bits/stdc++.h>

using namespace std;

int main(){
	
	int t;
	cin >> t;
	
	while(t -- ){
		string str;
		int n,cnt = 0;
		cin >> n >> str;
		if(str[0] != str[n - 1]){
			cnt += 2;
			for(int i = 1,j = n - 2;i < j && str[i] != str[j];i ++ ,j -- ){
				cnt += 2 ;
				
			}
			cout << n - cnt << endl;
		}else {
			cout << n << endl;
		}
	}
	return 0;
} 

D - Distinct Split

#include <bits/stdc++.h>

using namespace std;

int h1[30] = {0},h2[30] = {0};

int main(){
	
	int t;
	cin >> t;
	
	while(t -- ){
		memset(h1,0,sizeof h1); 
		memset(h2,0,sizeof h2); 
		int n,num_a = 0,num_b = 0,sum = -1;
		string str;
		cin >> n >> str;
		for(int i = 0;i < n;i ++ ){
			h1[str[i] - 'a'] ++ ;
			if(h1[str[i] -'a'] == 1)num_a ++ ;
		}
		
		for(int i = n - 1;i >= 0;i -- ){
			h1[str[i] -'a'] -- ;
			h2[str[i] -'a'] ++ ;
			if(h1[str[i] -'a'] == 0)num_a -- ;
			if(h2[str[i] -'a'] == 1)num_b ++ ;
			sum = max(sum,num_a + num_b);
		}
		cout << sum << endl;
	}
	return 0;
} 

E - Negatives and Positives

#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 1e5 + 10;
 
int a[N];
 
int main(){
	
	int t;
	cin >> t;
	
	while(t -- ){
		int n;
		long long sum = 0;
		cin >> n;
		long long a[n];
		for(int i = 0;i < n;i ++ ){
			cin >> a[i];
			sum += a[i];
		}
		sort(a,a + n);
		for(int i = 0;i < n - 1;i += 2 ){
			if(a[i] < 0){
				sum -= min(2 * (a[i] + a[i + 1]),(long long)0);
			}else break;
		}
		cout << sum << endl;
	}
	return 0;
} 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值