Codeforces Round #685 (Div. 2) ABCD

传送门

A. Subtract or Divide

题意:把n变成1,可以整除n或者n减一,问操作数最少是多少
题解:特判1,2,3,然后就会发现最小的倍数是2,就可以分奇偶考虑,偶数除去除2得到的因子后减1,奇数减一1后除去除2得到的因子再减1。

#pragma GCC optimize(2)
#include<bits/stdc++.h> 
using namespace std;
#define AC 0 
#define Please return
#define endl "\n" 
#define ll long long
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	int t;cin>>t;
	while(t--){
		ll n;cin>>n;
		if(n==1)cout<<0;
		else if(n==2)cout<<1;
		else if(n==3)cout<<2; 
		else if(n%2==0)cout<<2;
		else cout<<3;
		cout<<endl;
	}
   Please AC;
} 

B. Non-Substring Subsequence

题意:一个长度为n的字符串,q次询问,问[l,r]的字符串能由该字符串其他不连续的子序列构成吗?
题解:判断s[1]至s[l-1]中是否出现过s[l]和s[r+1]至s[n]中是否出现过s[r]即可

#pragma GCC optimize(2)
#include<bits/stdc++.h> 
using namespace std;
#define AC 0 
#define Please return
#define endl "\n" 
#define ll long long
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	int t;cin>>t;
	while(t--){
		ll n,q;cin>>n>>q;
		string s;cin>>s;
		s="#"+s;
		while(q--){
			ll l,r,f=0;cin>>l>>r;
			for(int i=1;i<l;i++)
				if(s[i]==s[l]){
					f=1;break;
				}
			for(int i=r+1;i<=n;i++)
				if(s[i]==s[r]){
					f=1;break;
				}	
			if(f)cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
		} 
	}
   Please AC;
} 

C. String Equality

题意:两个长度为n的字符串a和b,只包含小写字母,可以任意调换相邻字母的位置,如果a中由连续k个一样的字母,那么就可以把这k个字符串变成下一个字典序的字母(不超过z),问是否可以把字符串a变成b
题解:因为相邻字母可以任意调换,故相当于所有字母都可以任意排序。即可直接判断,同个字母,在字符串a中是否多余字符串b且多余的个数是否满住是k的倍数,如果满足就把多余的字母变成下一个字典序的字母,最后特判字母z

#pragma GCC optimize(2)
#include<bits/stdc++.h> 
using namespace std;
#define AC 0 
#define Please return
#define endl "\n" 
#define ll long long
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	int t;cin>>t;
	while(t--){
		ll n,k,f=1;cin>>n>>k;
		string a,b;cin>>a>>b;
		if(a==b){
			cout<<"Yes"<<endl;continue;
		}
		vector<int>cnta(26,0),cntb(26,0);
		for(int i=0;i<n;i++){
			cnta[a[i]-'a']++;
			cntb[b[i]-'a']++;
		}
		for(int i=0;i<25;i++){
			if(cnta[i]>=cntb[i]&&(cnta[i]-cntb[i])%k==0){
				cnta[i+1]+=cnta[i]-cntb[i];
				cnta[i]=k;
			} 
			else {
				f=0;break;
			}
		}
		if(cnta[25]!=cntb[25])f=0;
		if(f)cout<<"Yes"<<endl;else cout<<"No"<<endl;
	} 
   Please AC;
} 

D. Circle Game

题意:Ashish 和 Utkarsh 玩游戏,Ashish先手,轮流交换,从点(0,0),每人每次都可以对横坐标x或者纵坐标y进行+k操作,且需要保证该次操作后距离点(0,0)的欧几里得距离不超过d,谁先不能移动,谁输
题解:操作次数最多是1e5,故可以暴力模拟。循环,先手的横坐标+k,后手的纵坐标+k,每次都特判是否能走到一步

#pragma GCC optimize(2)
#include<bits/stdc++.h> 
using namespace std;
#define AC 0 
#define Please return
#define endl "\n" 
#define ll long long
struct Point{
	ll x,y;
	Point(ll tx=0,ll ty=0){
		x=tx; y=ty;
	}
};
ll d,k,f;
bool dis(Point a){
	return (a.x*a.x+a.y*a.y)<=d*d;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	int t;cin>>t;
	while(t--){
		cin>>d>>k;
		f=-1;
		Point tmp(0,0);
		while(1){
			tmp.x+=k;
			if(!dis(tmp)){
				f=1; break;
			}
			tmp.y+=k;
			if(!dis(tmp)){
				f=2;break;
			}
		}
		if(f==2)cout<<"Ashish"<<endl;
		else if(f==1)cout<<"Utkarsh"<<endl;
	} 
   Please AC;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值