CodeForce——Deltix Round, Autumn 2021 (open for everyone, rated, Div. 1 + Div. 2)前三道题目题解
目录
题目链接
| A |
standard input/output 1 s, 256 MB |
正在上传…重新上传取消 x13036 | |
| B |
standard input/output 2 s, 256 MB |
正在上传…重新上传取消 x10007 | |
| C |
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)前三道题目题解的更多相关文章
- 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的数组, ...
- 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 ...
- Codeforces Round #438 (Div.1+Div.2) 总结
本来兴致勃勃的想乘着这一次上紫,于是很早很早的到了机房 但是好像并没有什么用,反而rating-=47 Codeforces Round #438(Div.1+Div.2) 今天就这样匆匆的总结一下, ...
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- Educational Codeforces Round 53 (Rated for Div. 2) (前五题题解)
这场比赛没有打,后来补了一下,第五题数位dp好不容易才搞出来(我太菜啊). 比赛传送门:http://codeforces.com/contest/1073 A. Diverse Substring ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)
这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...
- Codeforces Round #519 by Botan Investments(前五题题解)
开个新号打打codeforces(以前那号玩废了),结果就遇到了这么难一套.touristD题用了map,被卡掉了(其实是对cf的评测机过分自信),G题没过, 700多行代码,码力惊人.关键是这次to ...
- Codeforces Round #609 (Div. 2)前五题题解
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...
- 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 题解 思路 ...
随机推荐
- 用 Docker 构建 MySQL 主从环境
开源Linux 一个执着于技术的公众号 前言 本篇文章记录使用 docker-compose 以及 dockerfile 来构建基于 binlog 的 MySQL 主从环境.如果你严格按照文中的步骤进 ...
- 【位运算】剑指offer 56. 数组中数字出现的次数
这是一系列位运算的题目,本文将由浅入深,先从最简单的问题开始: 问题1: 一个数组中只有一个数字出现过1次,其余数字都出现过两次,请找到那个只出现1次的数字.要求时间复杂度是 \(O(n)\),空间复 ...
- 【Python情感分析】用python情感分析李子柒频道视频热门评论
一.事件背景 今天是2021.12.2日,距离李子柒断更已经4个多月了,这是我在YouTube李子柒油管频道上,观看李子柒2021年7月14日上传的最后一条视频,我录制了视频下方的来自全世界各国网友的 ...
- 渗透:dSploit
dSploit--开源的专业的Android平台安全管理工具包 只能在横屏模式下工作,即使你旋转你的设备也将继续保持横屏,如果你有一个应用程序,如旋转控制器,迫使每一个应用程序旋转,将导致dSploi ...
- Java高并发-多线程基础
一.什么是线程 线程是进程内的执行单元. 二.线程的基本操作 2.1 状态与操作 2.2 新建线程 Thread t1 = new Thread(new CreateThread()); t1.sta ...
- linux篇-新建svn仓库
1昨天需要在服务器上新建一个仓库,解决方法是把已有的仓库拷贝出来,库删除在放进去 2然后今天想看看有没有命令的方法 find / -name project 首先查看一下项目的位置 3创建仓库 svn ...
- 【产品】如何写好APP描述
你有没有想过越是需要花钱购买的 App,用户会更认真阅读你的 App描述?本文列举了15个 app 描述,看看哪些是我们以前忽略了的,哪些是我们也犯过的错误.图中有红色背景的文字是需要强调的地方,这些 ...
- Redis快速度特性及为什么支持多线程及应用场景
转载请注明出处: 目录 1.Redis 访问速度快特性 2.Redis 6.0 为什么支持多线程? 3.Redis可以做什么 3.1.缓存 3.2.排行榜系统 3.3.计数器应用 3.4.社交网络 3 ...
- MySQL之事务隔离级别和MVCC
事务隔离级别 事务并发可能出现的问题 脏写 事务之间对增删改互相影响 脏读 事务之间读取其他未提交事务的数据 不可重复读 一个事务在多次执行一个select读到的数据前后不相同.因为被别的未提交事务修 ...
- linux在线安装和配置JDK1.8
首先在服务器ping www.baidu.com查看是否可以连网 然后就可以在线下载 一.下载安装JDK1.8 1.在下载安装的同时做一些准备工作 我们在usr目录下再创建一个Java文件夹准备放置我 ...