Codeforces Round 964 (Div. 4)A——E题解

Codeforces Round 964 (Div. 4)A——E题解

A. A+B Again?

题意:给一个两位数,求个位数和十位数的和。

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int num;
		cin>>num;
		cout<<num/10+num%10<<endl ;
	}
	return 0;
 } 

B. Card Game

题意:Suneet和Slavic各有两张写有数字的纸牌,数字大小介于1和10之间,问有几种方案使得Suneet赢得比赛。
题解:如果两张牌都比对方大,则有两种出牌顺序。

#include <iostream>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--)
	{
		int ans=0;
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		if(a>=c&&b>d||a>c&&b>=d)ans++;
		if(a>=d&&b>c||a>d&&b>=c)ans++;
		cout<<ans*2<<endl;	
	}
	return 0; 
} 

C. Showering

题意:给从0到m的时间,给定 l i l_{i} li r i r_{i} ri时间有任务,且Alex洗澡需要s的时间洗澡,问他是否有时间洗澡。
题解: l i + 1 − r i l_{i+1}-r_{i} li+1ri求出每个任务之间的时间间隔,并且求出这一天的最后一个时间段到最后一个任务的时间间隔比大小即可。

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const int N = 2e5+10;
ll l[N],r[N];
void solve()
{
	ll n,s,m;
	cin>>n>>s>>m;
	memset(l,0,sizeof(l));
	memset(l,0,sizeof(r));
	ll maxn = -1;
	for(int i=1;i<=n;i++)
	{
		cin>>l[i]>>r[i];
		maxn = max(maxn,l[i] - r[i-1]);
	}
	maxn = max(m - r[n],maxn);
	if(maxn >= s)
	{
		cout<<"YES"<<endl; 
	}
	else 
	{
		cout<<"NO"<<endl;
	}
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
 } 

D. Slavic’s Exam

题意:给两个字符串s、t,s中有“?”,这个问号可以转换成任意小写字母,问t能否是s的一个子序列(不一定连续)。
题解:从前往后依次寻找即可。

#include <bits/stdc++.h>
using namespace std;
#define ll long long 
const int N = 2e5+10;
void solve()
{
	string s,ss;
	cin>>s>>ss;
	int n = s.length();
	int m = ss.length();
	int i=0,j=0;
	while(j<m)
	{
		bool flag = false;
		while(i<n)
		{
			if(s[i] == '?' || s[i] == ss[j])
			{
				if(s[i] == '?')
				{
					s[i] = ss[j];
				}
				flag = true;
				break;
			}
			else 
			{
				i++;
			}
			
		}
		if(!flag)
		{
			break;
		}
		i++,j++;
	}
	if( j == m)
	{
		cout<<"YES"<<endl;
		for(int i=0;i<n;i++)
		{
			if(s[i] == '?' )
			{
				s[i] = 'a';
			}
		}
		cout<<s<<endl;
	}
	else 
	{
		cout<<"NO"<<endl;
	}
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

E. Triple Operations

题意:给从 l l l r r r的所有整数,每次选两个数 x x x y y y,将 x x x变为 3 x 3x 3x y y y变为 ⌊ y 3 ⌋ \lfloor\frac{y}{3}\rfloor 3y,问经过多少次操作可以将这个数列变为0。
题解:选最小的数 l l l,先将其变为0,则先使 l l l每次除以3,求这个次数,最后求每个数变为0的次数,并且将 l l l变为0的次数加上。

#include <bits/stdc++.h>
using namespace std;
#define ll long long 
const int N = 2e5+10;
ll a[N];
int change(int x)
{
	int ans = 0;
	while(x)
	{
		ans++;
		x /= 3;
	}
	return ans;
}
void solve ()
{
	int l,r;
	cin>>l>>r;
	ll ans = a[r] - a[l-1];
	ans += change(l);
	cout<<ans<<endl;
	return ;
}
int main()
{
	int t;
	cin>>t;
	a[0] = 0;
	for(int i=1;i<=N-10;i++)
	{
		a[i] = change(i) + a[i - 1];
	}
	while(t--)
	{
		solve();
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yi壹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值