Codeforces Round 855

A.Is it a Cat?

可以把字符串全转换为小写,去重再删除,判断是不是meow

#include <bits/stdc++.h>

using namespace std;

int n,l;
string s;
int main() {
	cin>>n;
	while (n--) {
		cin>>l>>s;
		for (int i = 0; i < l; i++) {
			s[i] = tolower(s[i]);
		}
		
	   s.erase(unique(s.begin(),s.end()) , s.end()) ;
	   
		printf("%s\n", s=="meow"?"YES":"NO");
	}
}

B.Count the number of pairs

#include<bits/stdc++.h>
using namespace std;

int main()
{
	ios :: sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	
	int T;
	cin>>T;
	
	while(T--)
	{
		int cnt = 0;
		int n,k;
		cin>>n>>k;
	    string ch;
	    cin>>ch;
	    
	    unordered_map<char,int> m;
		for(int i = 0 ; i < n; i++)
		{
		
			m[ch[i]]++;
		}
		
		for(int i = 0 ; i < 26 ; i++)
		{
			int h = min(m[i+'a'] , m[i+'A']);
			cnt += h;
		    
		    if(k > 0)
		    {
			cnt += min(k,abs(m[i+'a'] - m[i+'A'])/2);
			k -= min(k,abs(m[i+'a']-m[i+'A'])/2);
		    }	
		}
		
	cout<<cnt<<endl;
		
		
	}
	
	return 0;
}

C1. Powering the Hero (easy version)
题目意思是每次从堆顶拿出一张卡,如果是0则可以从能量堆中得到相应数值的能量,如果非0则放入能量堆中或discard?求获得的最大能量。可以用优先队列来维护。

#include<iostream>
#include<queue>
#include<algorithm>
#define ll long long

using namespace std;
int main()
{
	ios :: sync_with_stdio(false);
	cin.tie(0) , cout.tie(0);
	
	int T;
	cin>>T;
	
	while(T--)
	{
		int n ;
		cin>>n;
		ll ans = 0;
	    priority_queue<ll> q;
		
		for(int i = 0 ; i < n ; i++)
		{
		
			ll x;
			cin>>x;
			
			if(x != 0) q.push(x);
			else if(!q.empty())
			{
				ans += q.top();
				q.pop();			
			} 
		}
		
		cout<<ans<<endl;
		
	}
	return 0;
}

C2. Powering the Hero (hard version)
同上

#include<iostream>
#include<queue>
#include<algorithm>
#define ll long long

using namespace std;
int main()
{
	ios :: sync_with_stdio(false);
	cin.tie(0) , cout.tie(0);
	
	int T;
	cin>>T;
	
	while(T--)
	{
		int n ;
		cin>>n;
		ll ans = 0;
	    priority_queue<ll> q;
		
		for(int i = 0 ; i < n ; i++)
		{
		
			ll x;
			cin>>x;
			
			if(x != 0) q.push(x);
			else if(!q.empty())
			{
				ans += q.top();
				q.pop();			
			} 
		}
		
		cout<<ans<<endl;
		
	}
	return 0;
}

D. Remove Two Letters

一开始用哈希表怎么都不行。纯思维,如果一个字符串每个字符都不同的话那么答案就是字符个数-1.如果当前删除的这两个字符的前一个字符和接下来要删除的后一个字符一样的话,那么对答案的贡献度为0。

#include<bits/stdc++.h>

using namespace std;

void solve()
{
    
    int n;
    string  str;
    cin>>n;
    cin>>str;
    
    int ans = n - 1;
    
    for(int i = 1 ; i + 1 < n ; i++)
    {
        if(str[i-1] == str[i+1]) ans--;
        
    }
    
    cout<<ans<<endl;
}

int main()
{
    
    int T;
    cin>>T;
    
    while(T--)
    {
        solve();
    }
    
    return 0;
    
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值