Codeforces Beta Round #77 (Div. 2 Only)

时间:2022-09-05 11:59:42

Codeforces Beta Round #77 (Div. 2 Only)

http://codeforces.com/contest/96

A

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 13000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,int> pci;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
string str;
cin>>str;
int co=;
vector<int>ve;
for(int i=;i<str.length();i++){
if(str[i]!=str[i-]){
ve.pb(co);
co=;
}
else{
co++;
}
}
ve.pb(co);
for(int i=;i<ve.size();i++){
if(ve[i]>=) {cout<<"YES"<<endl;return ;}
}
cout<<"NO"<<endl;
}

B

dfs+二分

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 13000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,int> pci;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ ll n; set<ll>se;
map<ll,int>mp; void Check(ll num){
ll tmp=num;
int qi=,si=;
while(num){
if(num%==){
si++;
}
else if(num%==){
qi++;
}
num/=;
}
if(si==qi&&si>){
se.insert(tmp);
}
} void dfs(ll num){
if(num>n*||mp[num]) return;
mp[num]=;
Check(num);
dfs(num*+);
dfs(num*+);
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n;
dfs();
set<ll>::iterator it;
it=lower_bound(se.begin(),se.end(),n);
cout<<*it<<endl;
}

C

模拟

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 13000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,int> pci;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */
const int N = ;
string s[N], ss[N], w, ww;
bool vis[N];
char str;
string change(string x) {
for(int i = ; i < x.length(); i ++) {
if(x[i] >= 'A' && x[i] <= 'Z') x[i] += ;
}
return x;
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n;
cin >> n;
for(int i = ; i < n; i ++) {
cin >> s[i];
ss[i] = change(s[i]);
}
cin >> w >> str;
ww = change(w);
if(str >= 'A' && str <= 'Z') str += ; int l = ww.length();
for(int i = ; i < l; i ++) {
for(int k = ; k < n; k ++) {
if(l-s[k].length() + >= i && ww.substr(i, ss[k].length()) == ss[k]) {
for(int j = i; j < i + ss[k].length(); j ++) vis[j] = ;
}
}
} for(int i = ; i < l; i ++) {
if(vis[i]) {
if(ww[i] == str) {
char tmp = 'a';
if(ww[i] == 'a') tmp = 'b'; if(w[i] >= 'A' && w[i] <= 'Z') w[i] = tmp - ;
else w[i] = tmp;
} else {
if(w[i] >= 'A' && w[i] <= 'Z') w[i] = str - ;
else w[i] = str;
}
}
}
cout << w << endl;
}

D

最短路   两次Dijstra 第一次构建以花费为权值的图,第二次跑最短路

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 13000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<char,int> pci;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int n,m,s,t; vector<pli>G[],ve[];
vector<pli>a; long long dis[],vis[]; void dijstra1(int x){
for(int i=;i<=n;i++) dis[i]=0x3f3f3f3f3f3f3f3f,vis[i]=;
dis[x]=;
priority_queue<pli,vector<pli>,greater<pli>>Q;
Q.push({,x});
while(!Q.empty()){
pli p=Q.top();
Q.pop();
int v=p.second;
if(!vis[v]){
vis[v]=;
for(int i=;i<G[v].size();i++){
int vv=G[v][i].second;
long long dist=G[v][i].first+dis[v];
if(!vis[vv]&&dist<dis[vv]){
dis[vv]=dist;
Q.push({dis[vv],vv});
}
}
}
}
for(int i=;i<a.size();i++){
if(i!=x&&a[x].second>=dis[i]){
ve[x].pb({a[x].first,i});
}
}
} void dijstra2(int x,int t){
for(int i=;i<=n;i++) dis[i]=0x3f3f3f3f3f3f3f3f,vis[i]=;
dis[x]=;
priority_queue<pli,vector<pli>,greater<pli>>Q;
Q.push({,x});
while(!Q.empty()){
pli p=Q.top();
Q.pop();
int v=p.second;
if(!vis[v]){
vis[v]=;
for(int i=;i<ve[v].size();i++){
int vv=ve[v][i].second;
long long dist=ve[v][i].first+dis[v];
if(!vis[vv]&&dist<dis[vv]){
dis[vv]=dist;
Q.push({dis[vv],vv});
}
}
}
}
if(dis[t]==0x3f3f3f3f3f3f3f3f) cout<<-<<endl;
else cout<<dis[t]<<endl;
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n>>m>>s>>t;
int u,v;
long long c;
for(int i=;i<=m;i++){
cin>>u>>v>>c;
G[u].pb({c,v});
G[v].pb({c,u});
}
a.pb({,});
for(int i=;i<=n;i++){
cin>>u>>c;
a.pb({c,u});
}
for(int i=;i<=n;i++){
dijstra1(i);
}
dijstra2(s,t);
}

E

大数+数位DP

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 13000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<char,int> pci;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long mod=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */
const int N=;
int digit[N];
ll dp[N][N][];
char l[N], r[N];
int k;
int dfs(int len, int p, bool flag, bool limit) {
if (len == ) return flag;
if (limit == && dp[len][p][flag] != -) return dp[len][p][flag];
int up = limit ? digit[len] : ;
int res = ;
rep(i, , up + ) {
if (i != && i != )
res = (res + dfs(len - , max(, p - ), flag, limit && i == up)) % mod;
else res = (res + dfs(len - , * k, flag || p, limit && i == up)) % mod;
}
if (!limit) dp[len][p][flag] = res;
return res;
}
void solve() {
int t;
memset(dp, -, sizeof dp);
scanf("%d%d", &t, &k);
while (t--) {
scanf("%s%s", l, r);
int len = strlen(r);
for(int i=len;i>=;i--) digit[i] = r[len - i] - '';
int ans = dfs(len, , , );
len = strlen(l);
for(int i=len;i>=;i--) digit[i] = l[len - i] - '';
digit[]--;
for (int i = ; digit[i] < ; i++) {
digit[i] += ;
digit[i + ]--;
}
if (digit[len] == ) len--;
ans = (ans - dfs(len, , , ) + mod) % mod;
printf("%d\n", ans);
}
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
solve();
}

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

  1. Codeforces Beta Round &num;77 &lpar;Div&period; 1 Only&rpar; C&period; Volleyball &lpar;最短路)

    题目链接:http://codeforces.com/contest/95/problem/C 思路:首先dijkstra预处理出每个顶点到其他顶点的最短距离,然后如果该出租车到某个顶点的距离小于等于 ...

  2. codeforces水题100道 第二十三题 Codeforces Beta Round &num;77 &lpar;Div&period; 2 Only&rpar; A&period; Football &lpar;strings&rpar;

    题目链接:http://www.codeforces.com/problemset/problem/96/A题意:判断一个0-1字符串中出现的最长的0字串或者1字串的长度是否大于等于7.C++代码: ...

  3. Codeforces Beta Round &num;77 &lpar;Div&period; 2 Only&rpar; A&period; Football【字符串&sol;判断是否存在连续7个0或7个1】

    A. Football time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  4. Codeforces Beta Round &num;80 &lpar;Div&period; 2 Only&rpar;【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  5. Codeforces Beta Round &num;83 &lpar;Div&period; 1 Only&rpar;题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  6. Codeforces Beta Round &num;79 &lpar;Div&period; 2 Only&rpar;

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  7. Codeforces Beta Round &num;76 &lpar;Div&period; 2 Only&rpar;

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  8. Codeforces Beta Round &num;75 &lpar;Div&period; 2 Only&rpar;

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  9. Codeforces Beta Round &num;74 &lpar;Div&period; 2 Only&rpar;

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

随机推荐

  1. Excel 同时打开2个或多个独立窗口

    首先win7版本点击[开始]菜单,在输入框里面输入"regedit.exe"打开注册表     然后定位找到该路径HKEY_CLASSES_ROOT \ Excel.Sheet.1 ...

  2. 第一个structs&plus;spring&plus;hibernate的web程序

    1. 数据库: Column Type Comment id int(11) Auto Increment   name varchar(50) NULL   url varchar(255) NUL ...

  3. 移动webapp的那些bug

    bug持续更新中... 测试浏览器 Chrome: 61.0.3163.73 Safari: 10.0(IOS 10.3.3) Github: webapp-bugs 1. IOS overflow: ...

  4. &lpar;转)Cesium教程系列汇总

    https://www.cnblogs.com/fuckgiser/p/5706842.html Cesium系列目录: 演示实例 ExamplesforCesium 最近老实有一些人问我,下载后在本 ...

  5. Spring Security 无法登陆,报错:There is no PasswordEncoder mapped for the id &OpenCurlyDoubleQuote;null”

    编写好继承了WebSecurityConfigurerAdapter类的WebSecurityConfig类后,我们需要在configure(AuthenticationManagerBuilder ...

  6. 解决&period;Net Mvc跨域请求问题

    针对ASP.NET MVC和ASP.NET Web API两种项目类型 1.针对ASP.NET MVC,只需要在web.config中添加如下的内容即可 <system.webServer&gt ...

  7. linux中一些简便的命令之wc

    wc命令是统计文本中的字符数.单词数以及文本行数的,具体参数如下: -l 统计文本中的行数 -w 统计文本中的单词数 -c/m 统计文本中的字符数 -L 统计文本中最长行的字符数 当然使用时也可以不带 ...

  8. rxvt-unicode配置

    我的urxvt配置文件如下 前缀可改为rxvt然后可以使用rxvt命令启动 -/.Xresources ! urxvt color set URxvt.multichar_encoding:utf-8 ...

  9. 定义serialVersionUID的作用与意义整理

    实现java.io.Serializable这个接口是为序列化,serialVersionUID 用来表明实现序列化类的不同版本间的兼容性.如果你修改了此类, 要修改此值.否则以前用老版本的类序列化的 ...

  10. Django - 文件上传、Django组件 - 分页器(paginator)

    一.文件上传准备知识 - Content-Type 1.请求头 - Content-Type Content-Type指的是请求体的编码类型,常见的类型共有3种: 1)application/x-ww ...