Codeforces Beta Round #77 (Div. 2 Only)
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)的更多相关文章
- Codeforces Beta Round #77 (Div. 1 Only) C. Volleyball (最短路)
题目链接:http://codeforces.com/contest/95/problem/C 思路:首先dijkstra预处理出每个顶点到其他顶点的最短距离,然后如果该出租车到某个顶点的距离小于等于 ...
- codeforces水题100道 第二十三题 Codeforces Beta Round #77 (Div. 2 Only) A. Football (strings)
题目链接:http://www.codeforces.com/problemset/problem/96/A题意:判断一个0-1字符串中出现的最长的0字串或者1字串的长度是否大于等于7.C++代码: ...
- Codeforces Beta Round #77 (Div. 2 Only) A. Football【字符串/判断是否存在连续7个0或7个1】
A. Football time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
随机推荐
- ubuntu16.04搭建geodjango+postgresql+postgis的WebGIS框架(一)安装第三方空间库
postgis是postgresql的空间扩展对象,它需要一些第三方库的支持.包括GEOS, PROJ.4 和 GDAL.我们首先安装这几个空间库. 在ubuntu系统终端执行:(预先装一些依赖的库) ...
- Office2019都有哪些强大功能
前阵子是微软一年一度的Ignite大会.而其中最引人注目.也是与我们一般人最息息相关的消息,当然是Office 2019的正式发布. 尽管Office 2019所更新的功能,对于Office 365的 ...
- 开发webapp手机返回键 退出问题 摘录
mui进行手机物理键的监听 确保引入mui 调用以下函数 // android 返回按键处理 androidBack(store, data) { try { mui.init({ keyEventB ...
- ACM__并查集
并查集是树型的数据结构,处理不想交集合 主要解决查找和合并的问题 步骤: 初始化 把每个点所在的集合初始化为自身 复杂度为O(N) 查找 查找元素所在的集合,即根节点 合并 将两个元素所在的集合合并在 ...
- 腾讯助理PHP开发工程师外包岗面经
校招错过腾讯了,在社招上看到腾讯有招外包岗,要求比正式岗低,于是抱着试一试的心态投了简历,没一会就收到了笔试题,还算简单. 第二天收到面试官的面试邀请,然后去面试了…… 腾讯里面真是漂亮,光是看装潢就 ...
- unity 获取网络时间
http://cgi.im.qq.com/cgi-bin/cgi_svrtime public int year, mouth, day, hour, min, sec; public string ...
- php压力测试工具简单实用方法
命令 ab -h 指令帮助 ab -n100 -c10 http://www.baidu.com 发起100个请求 并发数为10 设置测试地址是百度,注意测试测试时候请求数和并发数尽量设置低一点 Re ...
- Cookie-base 认证实现(学习笔记)
第一步 新建一个ASP.NET core 默认项目 新建 AdminController public class AdminController : Controller { [Authorize] ...
- python实现查找算法:二分查找法
二分查找算法也称折半查找,基本思想就是折半,和平时猜数字游戏一样,比如猜的数字时67,猜测范围是0-100,则会先猜测中间值50,结果小了,所以就会从50-100猜测,中间值为75,结果大了,又从50 ...
- Android EditText 操作。。。
EditText请求焦点三连击... editText.setFocusable(true); editText.setFocusableInTouchMode(true); editText.req ...