目录

A:

B:

C:


题目链接

A

Divide and Multiply

standard input/output

1 s, 256 MB

正在上传…重新上传取消 x13036
B

William the Vigilant

standard input/output

2 s, 256 MB

正在上传…重新上传取消 x10007
C

Complex Market Analysis

standard input/output

2 s, 256 MB

正在上传…重新上传取消 x7544

A:

这道题目使用了一个数学知识,使得可以更加快速地求出最后一位1后的0的个数

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. ll H[37];
  5. ll a[20];
  6. ll b[20];//0的数目
  7. ll c[20];
  8. ll num;
  9. void Init()
  10. {
  11. for(int i = 0; i <= 31; i++)
  12. {
  13. H[(1ll << i) % 37] = i;
  14. }
  15. }
  16. void solve()
  17. {
  18. c[0] = 0;
  19. for(int i = 1; i <= num; i++)
  20. {
  21. b[i] = H[(a[i] & (-a[i]) )%37];
  22. }
  23. for(int i = 1; i <= num; i++)
  24. {
  25. c[i] = a[i] >> b[i];
  26. }
  27. int maxpos = 0;
  28. for(int i = 1; i <= num; i++)
  29. {
  30. if(c[i] >= c[maxpos])
  31. maxpos = i;
  32. }
  33. for(int i = 1; i <= num; i++)
  34. {
  35. if(i != maxpos)
  36. {
  37. a[i] >>= b[i];
  38. a[maxpos] <<= b[i];
  39. }
  40. }
  41. ll ans = 0;
  42. for(int i = 1; i <= num; i++)
  43. {
  44. ans += a[i];
  45. }
  46. printf("%lld\n", ans);
  47. }
  48. int main()
  49. {
  50. Init();
  51. int T;
  52. cin >> T;
  53. while(T--)
  54. {
  55. scanf("%lld", &num);
  56. for(int i = 1; i <= num; i++)
  57. scanf("%lld", a+i);
  58. solve();
  59. }
  60. return 0;
  61. }

B:

注意子序列与子串的区别

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. char s[100007];
  4. int n, q;
  5. bool sub(int pos)
  6. {
  7. switch (s[pos])
  8. {
  9. case 'a':
  10. if(pos+2 > n)
  11. return false;
  12. if(s[pos+1] == 'b' && s[pos+2] == 'c') return true;
  13. else return false;
  14. break;
  15. case 'b':
  16. if(pos + 1 > n || pos-1 < 1) return false;
  17. if(s[pos-1]=='a' && s[pos+1]=='c') return true;
  18. else return false;
  19. break;
  20. case 'c':
  21. if(pos-2 < 1) return false;
  22. if(s[pos-2]=='a' && s[pos-1]=='b') return true;
  23. else return false;
  24. break;
  25. }
  26. return false;
  27. }
  28. int main()
  29. {
  30. int cnt = 0;
  31. scanf("%d%d", &n, &q);
  32. scanf("%s", s+1);
  33. for(int i = 1; i <= n-2; i++) if(s[i]=='a'&&s[i+1]=='b'&&s[i+2]=='c') cnt++;
  34. while(q--)
  35. {
  36. int pos;
  37. char buf[10];
  38. scanf("%d%s",&pos, buf);
  39. if(sub(pos)) cnt--;
  40. s[pos] = buf[0];
  41. if(sub(pos)) cnt++;
  42. printf("%d\n", cnt);
  43. }
  44. }

C:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define MAX 1000007
  4. typedef long long ll;
  5. bitset<MAX>notprime;
  6. int prime[MAX];
  7. void Init()
  8. {
  9. int k = 0;
  10. notprime[0] = true;
  11. notprime[1] = true;
  12. for(int i = 2; i <= 1000005; i++)
  13. {
  14. if(!notprime.test(i))
  15. prime[++k] = i;
  16. for(int j = 1; j <= k; j++)
  17. {
  18. if(prime[j] * i > 1000005) break;
  19. notprime[prime[j] * i] = true;
  20. if(i % prime[j]==0) break;
  21. }
  22. }
  23. }
  24. int s[MAX];
  25. int n, e;
  26. inline int next(int x)
  27. {
  28. return x+e;
  29. }
  30. inline int before(int x)
  31. {
  32. return x-e;
  33. }
  34. inline int dis(int x, int y)
  35. {
  36. return abs(x-y) / e;
  37. }
  38. /*
  39. int main()
  40. {
  41. Init();
  42. for(int i = 1; i <= 100; i++) printf("%d\t", prime[i]);
  43. return 0;
  44. }
  45. */
  46. //欧拉筛写错了,导致出了大问题。
  47. int main()
  48. {
  49. Init();
  50. int T;
  51. cin >> T;
  52. while(T--)
  53. {
  54. ll ans = 0;
  55. scanf("%d%d", &n, &e);
  56. for(int i = 1; i <= n; i++)
  57. {
  58. scanf("%d", s+i);
  59. }
  60. for(int i = 1; i <= e; i++)
  61. {
  62. int p = i;
  63. while(p <= n)
  64. {
  65. if(!notprime.test(s[p]))
  66. {
  67. int l = before(p);
  68. int r = next(p);
  69. while(l >= 1 && s[l] == 1) l = before(l);
  70. while(r <= n && s[r] == 1) r = next(r);
  71. ans += (ll)dis(p, l) * dis(r, p) - 1;
  72. }
  73. p = next(p);
  74. }
  75. }
  76. printf("%lld\n", ans);
  77. }
  78. return 0;
  79. }

CodeForce——Deltix Round, Autumn 2021 (open for everyone, rated, Div. 1 + Div. 2)前三道题目题解的更多相关文章

  1. CF Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)

    1. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort    暴力枚举,水 1.题意:n*m的数组, ...

  2. Codeforces 1023 A.Single Wildcard Pattern Matching-匹配字符 (Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Fi)

    Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A. Single Wildcard Patter ...

  3. Codeforces Round #438 (Div.1+Div.2) 总结

    本来兴致勃勃的想乘着这一次上紫,于是很早很早的到了机房 但是好像并没有什么用,反而rating-=47 Codeforces Round #438(Div.1+Div.2) 今天就这样匆匆的总结一下, ...

  4. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  5. Educational Codeforces Round 53 (Rated for Div. 2) (前五题题解)

    这场比赛没有打,后来补了一下,第五题数位dp好不容易才搞出来(我太菜啊). 比赛传送门:http://codeforces.com/contest/1073 A. Diverse Substring ...

  6. Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)

    这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...

  7. Codeforces Round #519 by Botan Investments(前五题题解)

    开个新号打打codeforces(以前那号玩废了),结果就遇到了这么难一套.touristD题用了map,被卡掉了(其实是对cf的评测机过分自信),G题没过, 700多行代码,码力惊人.关键是这次to ...

  8. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

  9. Codeforces Round #792 (Div. 1 + Div. 2) A-E

    Codeforces Round #792 (Div. 1 + Div. 2) A-E A 题目 https://codeforces.com/contest/1684/problem/A 题解 思路 ...

随机推荐

  1. Linux-I/O模型详解

    I/O介绍 I/O通常有内存IO.网络I/O.磁盘I/O等,但我们通常说的是网络I/O以及磁盘I/O.网络I/O:本质是socket读取 每次I/O请求,都会有两个阶段组成: 第一步:等待数据,即数据 ...

  2. H5如何实现唤起APP

    前言 写过hybrid的同学,想必都会遇到这样的需求,如果用户安装了自己的APP,就打开APP或跳转到APP内某个页面,如果没安装则引导用户到对应页面或应用商店下载.这里就涉及到了H5与Native之 ...

  3. 大陆出境海缆TPE APCN NCP APG简介

    目前我国的登陆站主要设立在三个城市 山东 山东青岛登陆站(隶属中国联通) EAC-C2C TPE(美国方向) 上海 上海崇明登陆站(隶属中国电信) APCN2(亚太) NCP(长线--美国,新建,亚太 ...

  4. 为什么 Redis 要有哨兵机制?

    作者:小林coding 计算机八股文刷题网站:https://xiaolincoding.com 大家好,我是小林. 这次聊聊,Redis 的哨兵机制. 提纲 为什么要有哨兵机制? 在 Redis 的 ...

  5. 组织:IEEE

    电气和电子工程师协会(IEEE,全称是Institute of Electrical and Electronics Engineers)是一个美国的电子技术与信息科学工程师的协会,是世界上最大的非营 ...

  6. linux篇-Parse error: syntax error, unexpected ‘new’ (T_NEW) in /usr/local/nginx/html/cacti/lib/adodb

    1首先这是基于lnmp模式进行的 2yum安装 yum -y install httpd mysql mysql-server php php-mysql php-json php-pdo 3lib库 ...

  7. 封装axios请求

    import axios from 'axios' import router from '@/router' axios.defaults.baseURL = system.requestBaseU ...

  8. Java ES 实现or查询

    es mapping里有三个字段: A:Integer B:Integer C:TEXT 现在想实现一个查询,来检索  (  (A =1 and B=2)  or (c like "test ...

  9. HYPERMESH-NASTRAN梁的方向与偏置

    Nastran关于梁的定义 我们知道,在定义梁单元时,一般需要定义单元的方向,或者说是单元的局部坐标系.对于Nastran内CBAR单元来说,梁轴向为X方向,我们需要给出向量\(\overrighta ...

  10. sklearn练习1 回归

    from sklearn.svm import SVR from sklearn.pipeline import make_pipeline from sklearn.preprocessing im ...