目录

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的个数

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll H[37];
ll a[20];
ll b[20];//0的数目
ll c[20];
ll num;
void Init()
{
for(int i = 0; i <= 31; i++)
{
H[(1ll << i) % 37] = i;
}
}
void solve()
{
c[0] = 0;
for(int i = 1; i <= num; i++)
{
b[i] = H[(a[i] & (-a[i]) )%37];
}
for(int i = 1; i <= num; i++)
{
c[i] = a[i] >> b[i];
}
int maxpos = 0;
for(int i = 1; i <= num; i++)
{
if(c[i] >= c[maxpos])
maxpos = i;
}
for(int i = 1; i <= num; i++)
{
if(i != maxpos)
{
a[i] >>= b[i];
a[maxpos] <<= b[i];
}
}
ll ans = 0;
for(int i = 1; i <= num; i++)
{
ans += a[i];
}
printf("%lld\n", ans);
}
int main()
{
Init();
int T;
cin >> T;
while(T--)
{ scanf("%lld", &num);
for(int i = 1; i <= num; i++)
scanf("%lld", a+i);
solve();
} return 0;
}

B:

注意子序列与子串的区别

#include <bits/stdc++.h>
using namespace std;
char s[100007];
int n, q;
bool sub(int pos)
{
switch (s[pos])
{
case 'a':
if(pos+2 > n)
return false;
if(s[pos+1] == 'b' && s[pos+2] == 'c') return true;
else return false;
break;
case 'b':
if(pos + 1 > n || pos-1 < 1) return false;
if(s[pos-1]=='a' && s[pos+1]=='c') return true;
else return false;
break;
case 'c':
if(pos-2 < 1) return false;
if(s[pos-2]=='a' && s[pos-1]=='b') return true;
else return false; break;
}
return false;
}
int main()
{
int cnt = 0;
scanf("%d%d", &n, &q);
scanf("%s", s+1);
for(int i = 1; i <= n-2; i++) if(s[i]=='a'&&s[i+1]=='b'&&s[i+2]=='c') cnt++;
while(q--)
{
int pos;
char buf[10];
scanf("%d%s",&pos, buf);
if(sub(pos)) cnt--;
s[pos] = buf[0];
if(sub(pos)) cnt++;
printf("%d\n", cnt);
}
}

C:

#include <bits/stdc++.h>
using namespace std;
#define MAX 1000007
typedef long long ll;
bitset<MAX>notprime;
int prime[MAX];
void Init()
{
int k = 0;
notprime[0] = true;
notprime[1] = true;
for(int i = 2; i <= 1000005; i++)
{
if(!notprime.test(i))
prime[++k] = i;
for(int j = 1; j <= k; j++)
{
if(prime[j] * i > 1000005) break;
notprime[prime[j] * i] = true;
if(i % prime[j]==0) break;
}
}
}
int s[MAX];
int n, e;
inline int next(int x)
{
return x+e;
}
inline int before(int x)
{
return x-e;
}
inline int dis(int x, int y)
{
return abs(x-y) / e;
}
/*
int main()
{
Init();
for(int i = 1; i <= 100; i++) printf("%d\t", prime[i]);
return 0;
}
*/
//欧拉筛写错了,导致出了大问题。
int main()
{
Init();
int T;
cin >> T;
while(T--)
{
ll ans = 0;
scanf("%d%d", &n, &e);
for(int i = 1; i <= n; i++)
{
scanf("%d", s+i);
}
for(int i = 1; i <= e; i++)
{
int p = i;
while(p <= n)
{
if(!notprime.test(s[p]))
{
int l = before(p);
int r = next(p);
while(l >= 1 && s[l] == 1) l = before(l);
while(r <= n && s[r] == 1) r = next(r);
ans += (ll)dis(p, l) * dis(r, p) - 1;
}
p = next(p);
}
}
printf("%lld\n", ans);
}
return 0;
}

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. 【hexo博客搭建】将搭建好的hexo博客部署到阿里云服务器上面(下)

    一.部署到阿里云服务器 既然博客也已经成功在本地部署,然后主题也成功安装,接下来就可以部署到服务器上面了,如果你也想要魔改matery主题,可以去各种博客上面找一找大佬的教程,或者联系我,也可以让你少 ...

  2. Spring配置及依赖注入

    入门 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-we ...

  3. 超越OpenCV速度的MorphologyEx函数实现(特别是对于二值图,速度是CV的4倍左右)。

    最近研究了一下opencv的 MorphologyEx这个函数的替代功能, 他主要的特点是支持任意形状的腐蚀膨胀,对于灰度图,速度基本和CV的一致,但是 CV没有针对二值图做特殊处理,因此,这个函数对 ...

  4. [USACO16JAN]Angry Cows G 解题报告

    一图流 参考代码: #include<bits/stdc++.h> #define ll long long #define db double #define filein(a) fre ...

  5. SCSS 简要教程(常用指令与方法)

    Sass是成熟.稳定.强大的CSS预处理器,而SCSS是Sass3版本当中引入的新语法特性,完全兼容CSS3的同时继承了Sass强大的动态功能. 特性概览 CSS书写代码规模较大的Web应用时,容易造 ...

  6. .net core 抛异常对性能影响的求证之路

    一.前言 在.net 社区中曾经听到过很多关于大量抛异常会影响性能这样的结论,心中一直就存在各种疑问.项目中使用自定义异常来处理业务很爽,但是又担心大量抛业务异常存在性能问题. 查阅了各种文档,微软官 ...

  7. SpringBoot2.x整合Prometheus+Grafana【附源码+视频】

    图文并茂,新手入门教程,建议收藏 SpringBoot2.x整合Prometheus+Grafana[附源码+视频] 附源码+视频 目录 工程简介 简介 Prometheus grafana Spri ...

  8. php 正则获取字符串中的汉字(去除字符串中除汉字外的所有字符)

    preg_match_all('/[\x{4e00}-\x{9fff}]+/u', $list[$i]['iparr'], $matches); $list[$i]['iparr'] = join(' ...

  9. 分享一个基于 netty 的 java 开源项目

    1.简介 中微子代理(neutrino-proxy)是一个基于 netty 的.开源的 java 内网穿透项目.遵循 MIT 许可,因此您可以对它进行复制.修改.传播并用于任何个人或商业行为. 2.项 ...

  10. 第1期 考研中有关函数的一些基本性质《zobol考研微积分学习笔记》

    在入门考研微积分中,我们先复习一部分中学学的初等数学的内容.函数是非常有用的数学工具. 1.函数的性质理解: 首先考研数学中的所有函数都是初等函数.而函数的三个关键就是定义域.值域.对应关系f. 其中 ...