# 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 （签到）

#### 题意

#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)

#### 思路

#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 (模拟 ，题意杀)

#### 题意

#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 (最短路)

#### 思路

#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)

#### 思路

$$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;
}

Codeforces Beta Round 77 (Div. 2 Only)

(0)
(0)

0条