Educational Codeforces Round 144 (Rated for Div. 2)

A. Typical Interview Problem

找规律,循环节为8,长度最长为10,所以模板串得乘以3防止长度不够

s = "FBFFBFFB";
s = s*3
t = int(input())
for i in range(t):
    n = int(input())
    a = input()
    if a in s:
        print("YES")
    else:
        print("NO")
        

B. Asterisk-Minor Template

void solve()
{
	string a,b;
	cin>>a>>b;
	int lena = a.length();
	int lenb = b.length();
	for(int i=0;i<lena-1;i++){
		for(int j=0;j<lenb-1;j++){
			if(a[i]==b[j] && a[i+1]==b[j+1]){
				cout<<"YES"<<endl;
				cout<<"*"<<a[i]<<a[i+1]<<"*"<<endl;
				return ;
			}
		}
	}
	if(a[0]==b[0]){
		cout<<"YES"<<endl;
		cout<<a[0]<<"*"<<endl;
	}else if(a[lena-1]==b[lenb-1]){
		cout<<"YES"<<endl;
		cout<<"*"<<a[lena-1]<<endl;
	}else{
		cout<<"NO"<<endl;
	}
 
	
}

C. Maximum Set

标签写有dp和二分,觉得这是个数学推导的题目

 首先先说第一个,保证容器内的数字相互整除,只需要从l开始,不断的乘以2,当结果大于r时停止,此时得到的就是容器内最多能装的数字

接着第二个问题的考虑

void solve()
{
	int t;
	cin>>t;
	while(t--){
        int l,r;
        cin>>l>>r;
        int a = 0,b = 0;
        int tmp = 1;
        while(l*tmp<=r){
            tmp=tmp*2;
            a++;
        }
        tmp/=2;
        if(a==1){
            b = r-l+1;
        }else{
            b += ((r/tmp)-l+1)%mod;
            //(r/tmp)-l+1:找除了第一个数从l开始的其他数,在【l+1,r】里面找
            tmp = tmp*3/2;
            b = b + max(0ll,(r/tmp)-l+1)*(a-1)%mod;
            //(a-1):除了一个数不能变成3,其余位置可以选一个2变成3

        }
        cout<<a<<" "<<b<<endl;
    }

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值