Codeforces Round 964 (Div. 4)

Codeforces Round 964 (Div. 4)

B. Card Game

原题链接
题意:

每个玩家两张牌,每轮游戏有两回合,每回合数字大的玩家获胜,请找出玩家1获胜的游戏的最大次数

解题思路:

注意:当游戏其中一回合平局,另一回合获胜,此轮也为获胜。

玩家一获胜有两种情况:**1.两回合都胜 **

2.一回合平局,另一回合获胜

因此,我们逐一例举即可。

代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl "\n"

void solve()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a<b)
	swap(a,b);
	if(c<d)
	swap(c,d);
	//cout<<a<<b<<c<<d<<endl; 
	if(a==b&&a==c&&a==d)
	{
		cout<<"0"<<endl;
	}
	else if(b==d)
	{
		if(a>c)
		{
			if(b>=c) 
			cout<<"4"<<endl;
			else
			cout<<"2"<<endl;
		}
		
		else
		cout<<"0"<<endl;
	 } 
	 else if(a==b&&a==c&&a>d)
	 cout<<"4"<<endl;
	 else if(b==c&&a>d)
	  cout<<"4"<<endl;
	 else if(a==d)
	 {
	 	cout<<"0"<<endl;
	 }
	else if(a<d)
	cout<<"0"<<endl;
	else if(a>d)
	{
		if(a<c)
		{
			cout<<"0"<<endl;
		}
		else
		{
			if(b>c)
			{
				cout<<"4"<<endl;
			}
			else
			{
				if(b>d)
				cout<<"2"<<endl;
				else
				cout<<"0"<<endl;
			}
		}
	}
}

signed main()
{
    IOS      
    int t;
    cin>>t; 
    while(t--)
    solve();
    return 0;
}

D. Slavic’s Exam

原题链接:
题意:

输入两个字符串s,t,我们需要检查一下s是否能转换使得t称为它的子序列(无需连续),s中的转换规则为s中“?”可以任意转换为任意小写字母。如果存在就输出“YES",然后输出转换后的s,否则输出”NO“.

解题思路:

1.我们可以将t与s倒序来比较,进行转换

2.将t倒序存入队列p

3.倒着遍历s,用字符串r进行记录结果

4.每次将s当前字符与队首元素比较,如果相等或者此时s的字符为‘?’,则将此时的队首加到记录结果的字符串r上,并且将队首弹出,如果都不符合,则将s当前字符加到记录结果的字符串r上

5.由于子串需要顺序一致,因此倒着遍历时有‘?’时,可以放心的转换。

6.最后检查队列是否为空,如果为空,则证明转换成功,输出YES和结果r(记得将r翻转),不为空则输出NO.

代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl "\n"

void solve()
{
	queue<char>p;
	string s,t,r;
	cin>>s>>t;
	for(int i=t.size()-1;i>=0;i--)
	{
		p.push(t[i]);
	}
	for(int i=s.size()-1;i>=0;i--)
	{
		if(!p.empty()&&(s[i]==p.front()||s[i]=='?'))
		{
			r+=p.front();
			p.pop();
		}
		else
		{
			if(s[i]!='?')
			r+=s[i];
			else
			r+='a';
		}
	}
	reverse(r.begin(),r.end());
	if(!p.empty())
	cout<<"NO"<<endl;
	else
	cout<<"YES"<<endl<<r<<endl;
}

signed main()
{
    IOS
    int t;
    cin>>t; 
    while(t--)
    solve();
    return 0;
}

E. Triple Operations

原题链接
题意:

给出两个数字l,r,求出此区间所有的数均变为0需要的操作的数,操作方法:任选两个数字x,y,变换为 3x和y/3向下舍入到最接近的整数(例如:x=3,y=7->x=12,y=2)

解题思路:

1.将每个数/3向下取整变为0需要几步用数组a记录

2.最好的方式就是将最小的先化为0,与之同时会有一个数字变换同等次数*3,为了不修改后面的数字我们可以将sum最初赋值为a[l]

3.依次将a[l]到a[r]的值加到sum上,输出结果即可

代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl "\n"
int a[200005];

void solve()
{
	int l,r,sum=0;
	cin>>l>>r;
	sum+=a[l];
	for(int i=l;i<=r;i++)
	{
		sum+=a[i];
	}
	cout<<sum<<endl;
}

signed main()
{
	int p=1;
	int q;
	for(int i=1;i<=200005;i++)
	{
		if(i>=pow(3,p))
		p++;
	   	a[i]=p;
	   	

	   	
	}
    IOS
    int t;
    cin>>t; 
    while(t--)
    solve();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值