Codeforces Round #744 (Div. 3) A-F

Posted 行码棋

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #744 (Div. 3) A-F相关的知识,希望对你有一定的参考价值。

  • 博客主页: https://blog.csdn.net/qq_50285142
  • 欢迎点赞👍收藏✨关注❤留言 📝 如有错误,敬请指正
  • 🎈虽然生活很难,但我们也要一直走下去🎈

题目链接

A

#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;

typedef long long ll;
typedef vector<int> vi;
const int N = 1e5+5;

int n,m,k; 

void solve()
{
	string s;
	int a=0,b=0,c=0;
	cin>>s;
	for(auto i : s)
	{
		if(i=='A') a ++;
		else if (i=='B') b++;
		else c++;
	 } 
	if(a+c==b) cout<<"YES\\n";
	else cout<<"NO\\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int _;
	cin>>_;
	while(_--)
	{
		solve();
	}
	return 0;
 } 

B

模拟即可,类似冒泡排序,一位一位的比较

#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;

typedef long long ll;
typedef vector<int> vi;
const int N = 1e5+5;

ll n,m,k; 
ll a[55],b[55];
pair<int,int>res[55];
void solve()
{
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i] = a[i];
	} 
	if(is_sorted(a+1,a+1+n))
	{
		cout<<0<<'\\n';
		return ;
	}
	sort(b+1,b+1+n);
	int cnt = 0;
	for(int i=n;i>=1;i--)
	{
		for(int j=i;j>=1;j--)
		{
			if(a[j]==b[i] and i==j) break;
			if(b[i]==a[j])
			{
				cnt++;
				res[cnt] = {i,j};
				for(int k=j;k<=i;k++)
					a[k] = a[k+1];
				break;
			}
		}
	}
	cout<<cnt<<'\\n';
	for(int i=1;i<=cnt;i++)
		cout<<res[i].se<<" "<<res[i].fi<<" "<<1<<'\\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int _;
	cin>>_;
	while(_--)
	{
		solve();
	}
	return 0;
 } 

C

同样是模拟,我们找到中心点,然后看是否长度满足大于等于k,如果是的话就把能访问到的*标记为true
最后看是否所有的 * 都访问过了

#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9+7;
const int N = 2e5+5,M = 2e5+5;

int n,m,k;
char g[20][20]; 
bool vis[20][20];

void solve()
{
	memset(vis,false,sizeof vis);
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
		cin>>g[i]+1;
	for(int i=k+1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(g[i][j]=='*')
			{
				int cnt = 0;
				for(int x = 1;x <= n;x++)
				{
					if(i-x<1 or j-x<1 or j+x>m) break;
					if(g[i-x][j-x]=='*' and g[i-x][j+x]=='*')
						cnt++;
					else break;
				}
				if(cnt>=k)
				{
					vis[i][j] = true;
					for(int x = 1;x<=cnt;x++)
					{
						vis[i-x][j-x] = true;
						vis[i-x][j+x] = true;
					}
				}
			}
		}
	}
	bool is = true;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(g[i][j]=='*' and !vis[i][j])
			{
				is = false;
				break;
			}
		}
	}
	cout<<(is ? "YES\\n" : "NO\\n");
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int _;
	cin>>_;
//	_ = 1;
	while(_--)
	{
		solve();
	}
	return 0;
}

D

优先队列,每次取最大和次大的两个数,然后两个同时减一,注意不要一次性减完,这并不是完美的做法。
每次剪完1后再把他们放回去,一直记录次数就行。

#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef vector<int> vi;
const int N = 2e5+5;

ll n,m,k; 
ll a[N],b[55];
//pair<int,int>res[N];


void solve()
{
	priority_queue<pair<int,int> >q;
	map<pii,int> mp;
	cin>>n;
	for(int i=1;i<=n;i++) 
	{
		cin>>a[i];
		if(a[i]) q.push({a[i],i});
	}
	ll ret = 0;
	while(q.size()>1)
	{
		pair<int,int> a = q.top();
		q.pop();
		pair<int,int> b = q.top();
		q.pop();
		ret += 1;
		mp[{a.se,b.se}] += 1;
		if(a.fi>1)
			q.push({a.fi-1,a.se});
		if(b.fi>1)
			q.push({b.fi-1,b.se});
	}
	cout<<ret<<'\\n';
	for(auto i : mp)
	{
		for(int t = 1;t<=i.se;t++)
			cout<<i.fi.fi<<" "<<i.fi.se<<'\\n';
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int _;
	cin>>_;
	while(_--)
	{
		solve();
	}
	return 0;
 } 

E1

简单的双端队列模拟,争取每次都把小的值放在前面

#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;

typedef long long ll;
typedef vector<int> vi;
const int N = 2e5+5;

ll n,m,k; 
ll a[N],b[55];

void solve()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	deque<ll>q;
	q.push_front(a[1]);
	for(int i=2;i<=n;i++)
	{
		if(a[i]<=q.front()) q.push_front(a[i]);
		else q.push_back(a[i]);
	}
	for(auto i : q) cout<<i<<" ";
	cout<<'\\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int _;
	cin>>_;
	while(_--)
	{
		solve();
	}
	return 0;
 } 

E2

涉及到离散化树状数组的知识。
因为数据范围太大,没法开太大的数组,所以需要离散化。
访问到一个数时,我们需要统计比这个数小的数的个数和比这个数大的数的个数。
如果比访问到的数小的个数小于比它大的个数,我们把这个数放在最前面,会产生逆序对的数目为比这个数小的数的个数
反之也是取两者中最小的数

#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9+7;
const int N = 2e5+5,M = 2e5+5;

int n,m,k;
ll a[N],b[N];
ll tr[N];

void add(int x,int y)
{
	while(x<N)
	{
		tr[x] += y;
		x += x&-x;
	}
 } 

ll ask(int x)
{
	ll res = 0;
	while(x>=1)
	{
		res += tr[x];
		x -= x&-x;
	}
	return res;
}
void solve()
{
	memset(tr,0,sizeof tr);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		b[i] = a[i];
	}
	sort(b+1,b+1+n);
	unique(b+1,b+1+n);
	for(int i=1;i<=n;i++)
	{
		int pos = lower_bound(b+1,b+1+n,a[i])-b;
		a[i] = pos;
	}

	ll ret = 0;
	for(int i=1;i<=n;i++)
	{
		int x = ask(以上是关于Codeforces Round #744 (Div. 3) A-F的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #744 (Div. 3) A-F 题解

Codeforces Round #744 (Div. 3) A-F 题解

Codeforces Round #744 (Div. 3)ABCDE1E2FG题解

Codeforces Round #744 (Div. 3)ABCDE1E2FG题解

Codeforces Round #744 (Div. 3)ABCDE1E2FG题解

Codeforces Round #436 E. Fire(背包dp+输出路径)