CF535

CF535A

一道恶心人的题。遂贺了一份题解代码。

点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inl inline
#define endl '\n'
#define int ll
#define gc cin.get
#define pc cout.put
const int N=4e2+5;
const int M=4e3+5;
const int inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
inl int read(){
    int x=0,f=1;char c=gc();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=gc();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=gc();}
    return x*f;
}
inl void write(int x){
    if(x<0){pc('-');x=-x;}
    if(x>9)write(x/10);
    pc(x%10+'0');
}
inl void writei(int x){write(x);pc(' ');}
inl void writel(int x){write(x);pc('\n');}
int n,m;
string s[105]={"zero","one","two","three","four","five","six","seven","eight","nine",
"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen",
"nineteen","twenty","twenty-one","twenty-two","twenty-three","twenty-four","twenty-five",
"twenty-six","twenty-seven","twenty-eight","twenty-nine","thirty","thirty-one","thirty-two",
"thirty-three","thirty-four","thirty-five","thirty-six","thirty-seven","thirty-eight",
"thirty-nine","forty","forty-one","forty-two","forty-three","forty-four","forty-five",
"forty-six","forty-seven","forty-eight","forty-nine","fifty","fifty-one","fifty-two",
"fifty-three","fifty-four","fifty-five","fifty-six","fifty-seven","fifty-eight",
"fifty-nine","sixty","sixty-one","sixty-two","sixty-three","sixty-four","sixty-five",
"sixty-six","sixty-seven","sixty-eight","sixty-nine","seventy","seventy-one","seventy-two",
"seventy-three","seventy-four","seventy-five","seventy-six","seventy-seven","seventy-eight",
"seventy-nine","eighty","eighty-one","eighty-two","eighty-three","eighty-four",
"eighty-five","eighty-six","eighty-seven","eighty-eight","eighty-nine","ninety",
"ninety-one","ninety-two","ninety-three","ninety-four","ninety-five","ninety-six",
"ninety-seven","ninety-eight","ninety-nine"};
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    n=read();cout<<s[n]<<endl;
    return 0;
}

CF535B

第一眼特别像数位dp,但随后发只要找4和7,而且数据范围只有1e9
那么直接 \(2^9\) 爆搜即可

点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inl inline
#define endl '\n'
#define int ll
#define gc cin.get
#define pc cout.put
const int N=4e2+5;
const int M=4e3+5;
const int inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
inl int read(){
    int x=0,f=1;char c=gc();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=gc();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=gc();}
    return x*f;
}
inl void write(int x){
    if(x<0){pc('-');x=-x;}
    if(x>9)write(x/10);
    pc(x%10+'0');
}
inl void writei(int x){write(x);pc(' ');}
inl void writel(int x){write(x);pc('\n');}
int n,m,ans;
inl void dfs(int x){
    if(x>n)return;
    ans++;
    dfs(x*10+4);
    dfs(x*10+7);
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    n=read();
    dfs(4);dfs(7);
    cout<<ans<<endl;
    return 0;
}

CF535C

让你找 \(m\) 个东西,耐久-1,最多操作 \(t\) 次。
显然可以发现:如果一个东西耐久大于 \(t\) ,无论如何也消不掉。等差序列上可以二分。
而对于m 如果这个区间耐久和超出 \(m\times t\) 那么也一定不满足。也可以二分。
二者右区间取min即可

点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inl inline
#define endl '\n'
#define int __int128
#define gc cin.get
#define pc cout.put
const int N=4e2+5;
const int M=4e3+5;
const int inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
inl int read(){
    int x=0,f=1;char c=gc();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=gc();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=gc();}
    return x*f;
}
inl void write(int x){
    if(x<0){pc('-');x=-x;}
    if(x>9)write(x/10);
    pc(x%10+'0');
}
inl void writei(int x){write(x);pc(' ');}
inl void writel(int x){write(x);pc('\n');}
int a,b,n,m,ans,res;
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    a=read();b=read();n=read();
    while(n--){
        int lp=read(),t=read(),m=read();res=inf;
        int l=lp,r=1e12,ans=-1;
        while(l<=r){
            int mid=l+r>>1;
            if(a+(mid-1)*b<=t)ans=mid,l=mid+1;
            else r=mid-1;
        }
        res=min(res,ans);
        l=lp,r=1e12,ans=-1;
        while(l<=r){
            int mid=l+r>>1;
            if((mid-lp+1)*a+(mid+lp-2)*(mid-lp+1)/2*b<=t*m)ans=mid,l=mid+1;
            else r=mid-1;
        }
        res=min(res,ans);
        writel(res);
    }
    return 0;
}

CF535D

发现难的不是计数:显然为\(26^{空白部分数量}\)
那么考虑判定无解 可以发现只有可能是相邻的两个模式串重合区间不匹配。
而且发现 这个很像kmp的自我匹配 那么预处理出nxt数组和该前缀是否可行即可
不过不能用s.size()吗(?) 把这个换成 len 就过了。。。可能写出神秘ub了吧

点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inl inline
#define int ll
#define endl '\n'
#define gc cin.get
#define pc cout.put
const int N=2e6+5;
const int M=4e3+5;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
inl int read(){
    int x=0,f=1;char c=gc();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=gc();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=gc();}
    return x*f;
}
inl void write(int x){
    if(x<0){pc('-');x=-x;}
    if(x>9)write(x/10);
    pc(x%10+'0');
}
inl void writei(int x){write(x);pc(' ');}
inl void writel(int x){write(x);pc('\n');}
int n,m,nxt[N],ok[N],ans,a[N];
string s;
inl int qpow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    n=read();m=read();
    if(!m){
        cout<<qpow(26,n)<<endl;
        return 0;
    }
    cin>>s;
    int len=s.size();
    for(int i=1;i<=m;i++)a[i]=read();
    for(int i=1,j=0;i<len;i++){
        while(j&&(s[i]!=s[j]))j=nxt[j];
        if(s[i]==s[j])nxt[i+1]=++j;
    }
    for(int i=len;i;i=nxt[i])ok[i]=1;
    for(int i=2;i<=m;i++){
        if(a[i-1]+len-a[i]>0&&!ok[a[i-1]+len-a[i]]){
            cout<<0<<endl;
            return 0;
        }
    }
    ans=a[1]-1;
    for(int i=2;i<=m;i++)
        if(a[i]>a[i-1]+len)
            ans+=a[i]-a[i-1]-len;
    ans+=n+1-a[m]-len;
    cout<<qpow(26,ans)<<endl;
    return 0;
}

posted @ 2023-12-02 14:35  xiang_xiang  阅读(10)  评论(0编辑  收藏  举报