Codeforces Round #734 (Div. 3) (A-C)

A

太简单了,写完就删了

B1

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int ch[33];
		memset(ch, 0, sizeof(ch));
		string str;
		cin >> str;
		for (int i = 0; i < str.length(); i++)
		{
			int u = str[i] - 'a';
			ch[u]++;
		}
		int cou = 0;
		int gan = 0;
		for (int i = 0; i < 26; i++)
		{
			if (ch[i] >= 2) 
				cou++;
			else if (ch[i]==1) gan++;
		}
		cou+=gan/2;
		cout<<cou<<endl;
	}
}

B2
贪心思想

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int>PII;
bool cmp(PII a,PII b)
{
	return a.second<b.second;
}
bool cmp1(PII a,PII b)
{
	return a.first<b.first;
}
signed main()
{
	int t;
	cin>>t;
	while (t--)
	{
		int n,k,num;
		int a[200101];
		// fill(a,a+n+2,0);
		memset(a,0,sizeof(a));
		vector<PII>cun;
		cin>>n>>k;
		int cou = 0;
		for (int i=0;i<n;i++)
		{
			cin>>num;
			a[num]++;
			if (a[num]<=k) cou++;
			cun.push_back({num,i});
		}
		sort(cun.begin(),cun.end(),cmp1);
		cou = cou/k*k;
		memset(a,0,sizeof(a));
		for (int i=0;i<n;i++)
		{
			a[cun[i].first]++;
			if (a[cun[i].first]<=k&&cou!=0)
			{
				cun[i].first = cou%k+1;
				cou--;
			}
			else 
			{
				cun[i].first = 0;
			}
		}
		sort(cun.begin(),cun.end(),cmp);
		for (int i=0;i<n;i++)
		{
			cout<<cun[i].first<<" ";
		}
		cout<<endl;
	}
}

C
记录每个单词中的每个字母对于其他字母多多少(负数代表缺)缺的要存起来,多的加起来。

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		int cou[6], sum[6],ds[6];//sum是队伍数量,ds是多多少
		vector<int> cun[6];
		for (int i=0;i<5;i++)
		{
			sum[i]=0;
			ds[i]=0;
		}
		for (int j = 0; j < n; j++)
		{
			memset(cou, 0, sizeof(cou));
			string str;
			cin >> str;
			for (int i = 0; i < str.length(); ++i)
			{
				int u = str[i] - 'a';
				cou[u]++;
			}
			for (int i=0;i<5;i++)
			{
				if (cou[i]>str.length()/2)
				{
					sum[i]++;
					ds[i]+=2*cou[i]-str.length();
				}
				else
				{
					cun[i].push_back(str.length()-2*cou[i]);
				}
			}
		}
		int HH = 0;
		for (int i=0;i<5;i++)
		{
			sort(cun[i].begin(),cun[i].end());
			int k = sum[i];
			for (int j=0;j<cun[i].size();++j)
			{
				ds[i]-=cun[i][j];
				if (ds[i]>0) 
				{
					++k;
				}
				else break;
			}
			if (k>HH) HH = k;
		}
		cout << HH << endl;
	}
}
上一篇:c – 如何在现有Windows应用程序中获得ATL支持


下一篇:Dynamic Rankings(动态主席树 : 整体二分)