Codeforces Beta Round #77 (Div. 2 Only)

http://codeforces.com/contest/96

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 eb emplace_back
  8. #define maxn 13000005
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef pair<int,int> pii;
  14. typedef pair<char,int> pci;
  15. typedef pair<pair<int,string>,pii> ppp;
  16. typedef unsigned long long ull;
  17. const long long MOD=1e9+;
  18. /*#ifndef ONLINE_JUDGE
  19. freopen("1.txt","r",stdin);
  20. #endif */
  21.  
  22. int main(){
  23. #ifndef ONLINE_JUDGE
  24. // freopen("1.txt","r",stdin);
  25. #endif
  26. std::ios::sync_with_stdio(false);
  27. string str;
  28. cin>>str;
  29. int co=;
  30. vector<int>ve;
  31. for(int i=;i<str.length();i++){
  32. if(str[i]!=str[i-]){
  33. ve.pb(co);
  34. co=;
  35. }
  36. else{
  37. co++;
  38. }
  39. }
  40. ve.pb(co);
  41. for(int i=;i<ve.size();i++){
  42. if(ve[i]>=) {cout<<"YES"<<endl;return ;}
  43. }
  44. cout<<"NO"<<endl;
  45. }

B

dfs+二分

  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 eb emplace_back
  8. #define maxn 13000005
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef pair<int,int> pii;
  14. typedef pair<char,int> pci;
  15. typedef pair<pair<int,string>,pii> ppp;
  16. typedef unsigned long long ull;
  17. const long long MOD=1e9+;
  18. /*#ifndef ONLINE_JUDGE
  19. freopen("1.txt","r",stdin);
  20. #endif */
  21.  
  22. ll n;
  23.  
  24. set<ll>se;
  25. map<ll,int>mp;
  26.  
  27. void Check(ll num){
  28. ll tmp=num;
  29. int qi=,si=;
  30. while(num){
  31. if(num%==){
  32. si++;
  33. }
  34. else if(num%==){
  35. qi++;
  36. }
  37. num/=;
  38. }
  39. if(si==qi&&si>){
  40. se.insert(tmp);
  41. }
  42. }
  43.  
  44. void dfs(ll num){
  45. if(num>n*||mp[num]) return;
  46. mp[num]=;
  47. Check(num);
  48. dfs(num*+);
  49. dfs(num*+);
  50. }
  51.  
  52. int main(){
  53. #ifndef ONLINE_JUDGE
  54. // freopen("1.txt","r",stdin);
  55. #endif
  56. std::ios::sync_with_stdio(false);
  57. cin>>n;
  58. dfs();
  59. set<ll>::iterator it;
  60. it=lower_bound(se.begin(),se.end(),n);
  61. cout<<*it<<endl;
  62. }

C

模拟

  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 eb emplace_back
  8. #define maxn 13000005
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef pair<int,int> pii;
  14. typedef pair<char,int> pci;
  15. typedef pair<pair<int,string>,pii> ppp;
  16. typedef unsigned long long ull;
  17. const long long MOD=1e9+;
  18. /*#ifndef ONLINE_JUDGE
  19. freopen("1.txt","r",stdin);
  20. #endif */
  21. const int N = ;
  22. string s[N], ss[N], w, ww;
  23. bool vis[N];
  24. char str;
  25. string change(string x) {
  26. for(int i = ; i < x.length(); i ++) {
  27. if(x[i] >= 'A' && x[i] <= 'Z') x[i] += ;
  28. }
  29. return x;
  30. }
  31.  
  32. int main(){
  33. #ifndef ONLINE_JUDGE
  34. // freopen("1.txt","r",stdin);
  35. #endif
  36. std::ios::sync_with_stdio(false);
  37. int n;
  38. cin >> n;
  39. for(int i = ; i < n; i ++) {
  40. cin >> s[i];
  41. ss[i] = change(s[i]);
  42. }
  43. cin >> w >> str;
  44. ww = change(w);
  45. if(str >= 'A' && str <= 'Z') str += ;
  46.  
  47. int l = ww.length();
  48. for(int i = ; i < l; i ++) {
  49. for(int k = ; k < n; k ++) {
  50. if(l-s[k].length() + >= i && ww.substr(i, ss[k].length()) == ss[k]) {
  51. for(int j = i; j < i + ss[k].length(); j ++) vis[j] = ;
  52. }
  53. }
  54. }
  55.  
  56. for(int i = ; i < l; i ++) {
  57. if(vis[i]) {
  58. if(ww[i] == str) {
  59. char tmp = 'a';
  60. if(ww[i] == 'a') tmp = 'b';
  61.  
  62. if(w[i] >= 'A' && w[i] <= 'Z') w[i] = tmp - ;
  63. else w[i] = tmp;
  64. } else {
  65. if(w[i] >= 'A' && w[i] <= 'Z') w[i] = str - ;
  66. else w[i] = str;
  67. }
  68. }
  69. }
  70. cout << w << endl;
  71. }

D

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

  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 eb emplace_back
  8. #define maxn 13000005
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef pair<int,int> pii;
  14. typedef pair<long long,int>pli;
  15. typedef pair<char,int> pci;
  16. typedef pair<pair<int,string>,pii> ppp;
  17. typedef unsigned long long ull;
  18. const long long MOD=1e9+;
  19. /*#ifndef ONLINE_JUDGE
  20. freopen("1.txt","r",stdin);
  21. #endif */
  22.  
  23. int n,m,s,t;
  24.  
  25. vector<pli>G[],ve[];
  26. vector<pli>a;
  27.  
  28. long long dis[],vis[];
  29.  
  30. void dijstra1(int x){
  31. for(int i=;i<=n;i++) dis[i]=0x3f3f3f3f3f3f3f3f,vis[i]=;
  32. dis[x]=;
  33. priority_queue<pli,vector<pli>,greater<pli>>Q;
  34. Q.push({,x});
  35. while(!Q.empty()){
  36. pli p=Q.top();
  37. Q.pop();
  38. int v=p.second;
  39. if(!vis[v]){
  40. vis[v]=;
  41. for(int i=;i<G[v].size();i++){
  42. int vv=G[v][i].second;
  43. long long dist=G[v][i].first+dis[v];
  44. if(!vis[vv]&&dist<dis[vv]){
  45. dis[vv]=dist;
  46. Q.push({dis[vv],vv});
  47. }
  48. }
  49. }
  50. }
  51. for(int i=;i<a.size();i++){
  52. if(i!=x&&a[x].second>=dis[i]){
  53. ve[x].pb({a[x].first,i});
  54. }
  55. }
  56. }
  57.  
  58. void dijstra2(int x,int t){
  59. for(int i=;i<=n;i++) dis[i]=0x3f3f3f3f3f3f3f3f,vis[i]=;
  60. dis[x]=;
  61. priority_queue<pli,vector<pli>,greater<pli>>Q;
  62. Q.push({,x});
  63. while(!Q.empty()){
  64. pli p=Q.top();
  65. Q.pop();
  66. int v=p.second;
  67. if(!vis[v]){
  68. vis[v]=;
  69. for(int i=;i<ve[v].size();i++){
  70. int vv=ve[v][i].second;
  71. long long dist=ve[v][i].first+dis[v];
  72. if(!vis[vv]&&dist<dis[vv]){
  73. dis[vv]=dist;
  74. Q.push({dis[vv],vv});
  75. }
  76. }
  77. }
  78. }
  79. if(dis[t]==0x3f3f3f3f3f3f3f3f) cout<<-<<endl;
  80. else cout<<dis[t]<<endl;
  81. }
  82.  
  83. int main(){
  84. #ifndef ONLINE_JUDGE
  85. // freopen("1.txt","r",stdin);
  86. #endif
  87. std::ios::sync_with_stdio(false);
  88. cin>>n>>m>>s>>t;
  89. int u,v;
  90. long long c;
  91. for(int i=;i<=m;i++){
  92. cin>>u>>v>>c;
  93. G[u].pb({c,v});
  94. G[v].pb({c,u});
  95. }
  96. a.pb({,});
  97. for(int i=;i<=n;i++){
  98. cin>>u>>c;
  99. a.pb({c,u});
  100. }
  101. for(int i=;i<=n;i++){
  102. dijstra1(i);
  103. }
  104. dijstra2(s,t);
  105. }

E

大数+数位DP

  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 eb emplace_back
  8. #define maxn 13000005
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef pair<int,int> pii;
  14. typedef pair<long long,int>pli;
  15. typedef pair<char,int> pci;
  16. typedef pair<pair<int,string>,pii> ppp;
  17. typedef unsigned long long ull;
  18. const long long mod=1e9+;
  19. /*#ifndef ONLINE_JUDGE
  20. freopen("1.txt","r",stdin);
  21. #endif */
  22. const int N=;
  23. int digit[N];
  24. ll dp[N][N][];
  25. char l[N], r[N];
  26. int k;
  27. int dfs(int len, int p, bool flag, bool limit) {
  28. if (len == ) return flag;
  29. if (limit == && dp[len][p][flag] != -) return dp[len][p][flag];
  30. int up = limit ? digit[len] : ;
  31. int res = ;
  32. rep(i, , up + ) {
  33. if (i != && i != )
  34. res = (res + dfs(len - , max(, p - ), flag, limit && i == up)) % mod;
  35. else res = (res + dfs(len - , * k, flag || p, limit && i == up)) % mod;
  36. }
  37. if (!limit) dp[len][p][flag] = res;
  38. return res;
  39. }
  40. void solve() {
  41. int t;
  42. memset(dp, -, sizeof dp);
  43. scanf("%d%d", &t, &k);
  44. while (t--) {
  45. scanf("%s%s", l, r);
  46. int len = strlen(r);
  47. for(int i=len;i>=;i--) digit[i] = r[len - i] - '';
  48. int ans = dfs(len, , , );
  49. len = strlen(l);
  50. for(int i=len;i>=;i--) digit[i] = l[len - i] - '';
  51. digit[]--;
  52. for (int i = ; digit[i] < ; i++) {
  53. digit[i] += ;
  54. digit[i + ]--;
  55. }
  56. if (digit[len] == ) len--;
  57. ans = (ans - dfs(len, , , ) + mod) % mod;
  58. printf("%d\n", ans);
  59. }
  60. }
  61.  
  62. int main(){
  63. #ifndef ONLINE_JUDGE
  64. // freopen("1.txt","r",stdin);
  65. #endif
  66. std::ios::sync_with_stdio(false);
  67. solve();
  68. }

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

  1. Codeforces Beta Round #77 (Div. 1 Only) C. Volleyball (最短路)

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

  2. 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++代码: ...

  3. 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 ...

  4. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

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

  5. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

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

  6. Codeforces Beta Round #79 (Div. 2 Only)

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

  7. Codeforces Beta Round #76 (Div. 2 Only)

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

  8. Codeforces Beta Round #75 (Div. 2 Only)

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

  9. Codeforces Beta Round #74 (Div. 2 Only)

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

随机推荐

  1. ubuntu16.04搭建geodjango+postgresql+postgis的WebGIS框架(一)安装第三方空间库

    postgis是postgresql的空间扩展对象,它需要一些第三方库的支持.包括GEOS, PROJ.4 和 GDAL.我们首先安装这几个空间库. 在ubuntu系统终端执行:(预先装一些依赖的库) ...

  2. Office2019都有哪些强大功能

    前阵子是微软一年一度的Ignite大会.而其中最引人注目.也是与我们一般人最息息相关的消息,当然是Office 2019的正式发布. 尽管Office 2019所更新的功能,对于Office 365的 ...

  3. 开发webapp手机返回键 退出问题 摘录

    mui进行手机物理键的监听 确保引入mui 调用以下函数 // android 返回按键处理 androidBack(store, data) { try { mui.init({ keyEventB ...

  4. ACM__并查集

    并查集是树型的数据结构,处理不想交集合 主要解决查找和合并的问题 步骤: 初始化 把每个点所在的集合初始化为自身 复杂度为O(N) 查找 查找元素所在的集合,即根节点 合并 将两个元素所在的集合合并在 ...

  5. 腾讯助理PHP开发工程师外包岗面经

    校招错过腾讯了,在社招上看到腾讯有招外包岗,要求比正式岗低,于是抱着试一试的心态投了简历,没一会就收到了笔试题,还算简单. 第二天收到面试官的面试邀请,然后去面试了…… 腾讯里面真是漂亮,光是看装潢就 ...

  6. unity 获取网络时间

    http://cgi.im.qq.com/cgi-bin/cgi_svrtime public int year, mouth, day, hour, min, sec; public string ...

  7. php压力测试工具简单实用方法

    命令 ab -h 指令帮助 ab -n100 -c10 http://www.baidu.com 发起100个请求 并发数为10 设置测试地址是百度,注意测试测试时候请求数和并发数尽量设置低一点 Re ...

  8. Cookie-base 认证实现(学习笔记)

    第一步 新建一个ASP.NET core 默认项目 新建 AdminController public class AdminController : Controller { [Authorize] ...

  9. python实现查找算法:二分查找法

    二分查找算法也称折半查找,基本思想就是折半,和平时猜数字游戏一样,比如猜的数字时67,猜测范围是0-100,则会先猜测中间值50,结果小了,所以就会从50-100猜测,中间值为75,结果大了,又从50 ...

  10. Android EditText 操作。。。

    EditText请求焦点三连击... editText.setFocusable(true); editText.setFocusableInTouchMode(true); editText.req ...