Codeforces Beta Round 77 (Div. 2 Only)



layout: post
title: Codeforces Beta Round 77 (Div. 2 Only)
author: "luowentaoaa"
catalog: true
tags:
mathjax: true
- codeforces



传送门

A - Football (签到)

题意

问有没有连续的七个1或者七个0

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod=1e9+7;
const int maxn=5e5+50;
const int inf=1e8;
char s[150];
int zero[150],one[150];
int main()
{
    cin>>s+1;
    int len=strlen(s+1);
    for(int i=1;i<=len;i++){
        if(s[i]=='1'){
            one[i]=one[i-1]+1;
            zero[i]=0;
        }
        else
            zero[i]=zero[i-1]+1,one[i]=0;
        if(zero[i]>=7||one[i]>=7)puts("YES"),exit(0);
    }
    puts("NO");
    return 0;
}

B - Lucky Numbers (easy) (dfs)

题意

问你大于等于N的最小的只有4和7组成的最小的相同4/7个数的数是多少

思路

直接爆搜

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod=1e9+7;
const int maxn=5e5+50;
const ll inf=1e17;
ll ans=inf;
ll n;
void dfs(ll num,ll a,ll b){
    if(a==b&&num>=n)ans=min(ans,num);
    if(num>n*100)return;
    dfs(num*10+4,a+1,b);
    dfs(num*10+7,a,b+1);
}
int main()
{
    cin>>n;
    dfs(0,0,0);
    cout<<ans<<endl;
    return 0;
}

C - Hockey (模拟 ,题意杀)

题意

给你n个禁用子串w1,w2……wn,在主串w中找出与禁用相同的的子串用字母letter替换。若要替换的子串中有字母与letter相同,

那么就按字典序(PS:如果letter是a,那是b啦,不然就用a好了)去替换。输出时大小写保持不变。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod=1e9+7;
const int maxn=1e3+50;
const ll inf=1e17;
string s[maxn],sa[maxn],w,wa;
bool m[maxn];
char ned;
string to(string s){
    for(int i=0;s[i];i++)
        if(s[i]>='A'&&s[i]<='Z')s[i]=tolower(s[i]);
    return s;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>s[i],sa[i]=to(s[i]);
    cin>>w;
    wa=to(w);
    cin>>ned;ned=tolower(ned);
    for(int i=0;i<wa.size();i++){
        for(int j=0;j<n;j++){
            if(wa.substr(i,sa[j].size())==sa[j]){
                for(int k=i;k<i+sa[j].size();k++)m[k]=1;
            }
        }
    }
    for(int i=0;i<wa.size();i++){
        if(m[i]){
            if(wa[i]==ned){
                char tm;
                if(wa[i]=='a')tm='b';
                else tm='a';
                if(w[i]>='A'&&w[i]<='Z')w[i]=tm-32;
                else w[i]=tm;
            }
            else if(w[i]>='A'&&w[i]<='Z')w[i]=ned-32;
            else w[i]=ned;
        }
    }
    cout<<w<<endl;
    return 0;
}

D - Volleyball (最短路)

题意

有n个地方,m条路,一个人要从x到y,他要打车走,每条路上都有出租车,出租车走的距离为t,收c元,求从x到y最小花费

思路

重建图算出每个点能去哪些点 然后跑bfs或者dij

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod=1e9+7;
const int maxn=1e3+50;
const ll inf=1e17;

int n,m;
struct node{
    int to;
    ll w;
    bool operator <(const node &a)const{
        return w>a.w;
    }
};
vector<node>G[maxn],G2[maxn];
int x,y;
ll t[maxn],c[maxn];
ll val[maxn];
priority_queue<node>Q;
void dij(int st){
    for(int i=1;i<=n;i++)val[i]=inf;
    val[st]=0;
    while(!Q.empty())Q.pop();
    Q.push(node{st,0});
    while(!Q.empty()){
        node now=Q.top();
        Q.pop();
        int u=now.to;
        ll w=now.w;
        if(val[u]>t[st])break;
        if(u!=st&&val[u]<=t[st])G2[st].push_back({u,0});
        for(int i=0;i<G[u].size();i++){
            int to=G[u][i].to;
            if(val[to]>val[u]+G[u][i].w){
                val[to]=val[u]+G[u][i].w;
                Q.push(node{to,val[to]});
            }
        }
    }
}
void dij2(){
    for(int i=1;i<=n;i++)val[i]=inf;
    val[x]=c[x];
    while(!Q.empty())Q.pop();
    Q.push(node{x,val[x]});
    while(!Q.empty()){
        node now=Q.top();Q.pop();
        int u=now.to;
        for(int i=0;i<G2[u].size();i++){
            int v=G2[u][i].to;
            ll tmp=0;
            if(v==y)tmp=c[v];
            if(val[v]>val[u]+c[v]-tmp){
                val[v]=val[u]+c[v]-tmp;
                Q.push(node{v,val[v]});
            }
        }
    }
}
int main()
{
    cin>>n>>m;
    cin>>x>>y;
    for(int i=1;i<=m;i++){
        int u,v,w;
        cin>>u>>v>>w;
        G[u].push_back({v,w});
        G[v].push_back({u,w});
    }
    for(int i=1;i<=n;i++){
        cin>>t[i]>>c[i];
        dij(i);
    }
    if(x==y)puts("0"),exit(0);
    dij2();
    if(val[y]==inf)val[y]=-1;
    cout<<val[y]<<endl;
    return 0;
}

E - Horse Races (数位DP)

题意

求区间内幸运数字(4/7)间隔不超过K的数字的个数 区间大小为\(10^{1000}\)

思路

一眼数位DP

\(dp[pos][dis][yes]\) 表示位置在pos +上一个幸运数字和现在隔多少位置+是否已经有间隔不超过K的幸运数字

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod=1e9+7;
const int maxn=5e5+50;
const ll inf=1e16;
int k;
char st[2000],ed[2000];
ll dp[2000][3000][2];

int num[2000];

ll dfs(int pos,int ok,bool limit,int yes){
    if(pos==-1)return yes;
    if(!limit&&dp[pos][ok][yes]!=-1)return dp[pos][ok][yes];
    int up=limit?num[pos]:9;
    ll ans=0;
    for(int i=0;i<=up;i++){
        int dis=ok+1;
        if(i==4||i==7){
            if(ok<=k)dis=0;
            else dis=1;
        }
        ans+=dfs(pos-1,dis,limit&&i==up,dis==0||yes);
        ans%=mod;
    }
    if(!limit)dp[pos][ok][yes]=ans;
    return ans;
}

ll acc(char x[]){
    int len=strlen(x);
    for(int i=0;i<len;i++)num[i]=x[len-1-i]-'0';
    return dfs(len-1,k+5,true,false);
}
int main()
{
    int t;
    memset(dp,-1,sizeof(dp));
    ios::sync_with_stdio(false);
    cin>>t>>k;
    while(t--){
        cin>>st>>ed;
        int lena=strlen(st),p=lena-1;
        while(st[p]=='0')st[p--]='9';
        st[p]=st[p]-1;
        cout<<(acc(ed)-acc(st)+mod)%mod<<endl;
    }
    return 0;
}

原文地址:https://www.cnblogs.com/luowentao/p/10540464.html

时间: 2024-10-04 13:26:44

Codeforces Beta Round 77 (Div. 2 Only)的相关文章

Codeforces Beta Round #91 (Div. 1 Only) E. Lucky Array

E. Lucky Array Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467are not. Petya has an arra

Codeforces Beta Round #9 (Div. 2 Only)

Codeforces Beta Round #9 (Div. 2 Only) http://codeforces.com/contest/9 A gcd水题 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define maxn 1000010 7

Codeforces Beta Round #12 (Div 2 Only)

Codeforces Beta Round #12 (Div 2 Only) http://codeforces.com/contest/12 A 水题 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define maxn 1000010 7 t

Codeforces Beta Round #29 (Div. 2, Codeforces format)

Codeforces Beta Round #29 (Div. 2, Codeforces format) http://codeforces.com/contest/29 A 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb p

Codeforces Beta Round #31 (Div. 2, Codeforces format)

Codeforces Beta Round #31 (Div. 2, Codeforces format) http://codeforces.com/contest/31 A 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb p

Codeforces Beta Round #49 (Div. 2)

Codeforces Beta Round #49 (Div. 2) http://codeforces.com/contest/53 A 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define

Codeforces Beta Round #59 (Div. 2)

Codeforces Beta Round #59 (Div. 2) http://codeforces.com/contest/63 A 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define

Codeforces Beta Round #72 (Div. 2 Only)

Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #de

Codeforces Beta Round #85 (Div. 1 Only) C (状态压缩或是数学?)

C. Petya and Spiders Little Petya loves training spiders. Petya has a board n × m in size. Each cell of the board initially has a spider sitting on it. After one second Petya chooses a certain action for each spider, and all of them humbly perform it