cf每日一水(D. Playoff C. Serval and Toxel‘s Arrays C. Maximum Set)

传送门:Problem - D - Codeforces

传送门:Problem - C - Codeforces

传送门:Problem - C - Codeforces

第一个d题,寒假的时候看过,没看懂题目意思,现在回看了一手,发现就是打表找规律题

代码如下:

#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
int n;
string s;
map<int,map<int,int>>dp;
int main() {
    ios::sync_with_stdio(false);
    cin.tie();
    cout.tie();
    cin>>n;
    cin>>s;
    ll ln=0;
    ll rn=0;
    ll l=0,r=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='1'){
            if(l==0)l=1;
            else l<<=1;
            ln+=l;
        }
        else {
            if(r==0)r=1;
            else r<<=1;
            rn+=r;
        }
    }
    ll m=pow(2,s.size());
    for(int i=ln+1;i<=m-rn;i++){
        printf("%d ",i);
    }
}

第二题c,是个很妙的题,运用了比较特殊的倒着加减的原理,最开始t了几发,后来看了jiangly大神的代码,直呼妙。

#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
int n,m,t;
int main() {
    ios::sync_with_stdio(false);
    cin.tie();
    cout.tie();
    cin>>t;
    while(t--){
        cin>>n>>m;
        vector<int>b(n+m+5);
        vector<int>hh(n+m+5);
        for(int i=1;i<=n;i++){
            cin>>b[i];
            hh[b[i]]=m+1;
        }
        for(int i=1;i<=m;i++){
            int l,r;
            cin>>l>>r;
            hh[b[l]]-=m-i+1;
            b[l]=r;
            hh[b[l]]+=m-i+1;
        }
        ll ans=1ll*m*(m+1)*n;                     //化简前:ans=m*(m+1)/2*2n; 
        for(int i=1;i<=n+m;i++){
            ans-=1ll*(hh[i]-1)*hh[i]/2;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

最后一个是个数学题,就是探究倍数之间的范围一般都是2倍,但是有可能会出现其中一位数是3倍的情况:

#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
ll t;
ll lx,rx,an;
ll N=998244353;
int main(){
    ios::sync_with_stdio(false);
    cin.tie();
    cout.tie();
    cin>>t;
    while(t--){
        cin>>lx>>rx;
        
        an=0;
        ll l1=lx;
        while(l1<=rx){
            an++;
            l1<<=1;
        }
        if(an==1){
            printf("1 %lld\n",rx-lx+1);
            continue;
        }
        l1>>=1;
        ll ans=0;
        ll x=l1/lx;
        ans=(rx/x-lx+1)%N;
        x=x/2*3;
        ans=(ans+max((rx/x-lx+1)*(an-1),0ll)%N)%N;
        printf("%lld %lld\n",an,ans);
        
        
    }
    
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值