「THP3考前信心赛」解题报告
写在前面&总结:
\(LuckyBlock\) 良心出题人!暴力分给了 \(120pts\)
\(T1\) 貌似是个结论题,最后知道怎么算了,用前缀和搞了两下,写挂了就很草,最后只能靠暴力拿了 \(30pts\)
\(T2\) 显然数论题,但是我不会化简/kk,不过用前缀和优化了一下暴力 \(40pts\);
\(T3\) 依旧暴力,\(O(n^2)\) 可拿 \(40pts\)
\(T4\) 部分分 \(5pts\) \(+\) \(lps\) 随机输出 \('7'\) \(5pts\);
不会打暴力的 \(OIer\) 不是好 \(OIer\) ,不打暴力的都是**(没错说的就是CSP2020上的我
感觉 \(LuckyBlock\) 这次考察的芝士点比较详细,先粘个题解网址咕着,以后再补
T1
改自 CF1422C
发现可以当做取出一段序列,把剩下的拼接起来
在拼接过程中发现有许多部分是重复计算的,可以用后缀和和开个 \(10^i\) 的数组预处理
算了我也说不清楚直接放代码吧嘻嘻
/*
Work by: Suzt_ilymics
Knowledge: ??
Time: O(??)
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
const int MAXN = 2e6+6;
const int INF = 1;
const int mod = 1e9+7;
LL hsum[MAXN], jc[MAXN];
char ch[MAXN];
LL ans;
int read(){
int s = 0, w = 1;
char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') w = -1; ch = getchar(); }
while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + ch - '0' , ch = getchar();
return s * w;
}
LL quick(LL x, LL p, LL mod){
LL res = 1;
for( ; p; p >>= 1){
if(p & 1) res = res * x % mod;
x = x * x % mod;
}
return res;
}
signed main()
{
cin>>ch;
LL len = strlen(ch);
int cnt = 0;
cnt = 1; jc[0] = 1;
for(int i = 1; i <= len; ++i){
jc[i] = jc[i - 1] * 10 % mod;
}
cnt = 0;
for(int i = len - 1; i >= 0; --i){//求后缀数
cnt = (cnt + (ch[i] - '0') * jc[len - 1 - i] % mod) % mod;
hsum[i] = cnt;
// cout<<hsum[i]<<' ';
}
LL val = 0, sum = 0;
for(int i = 0; i < len; ++i){
ans += sum * jc[len - 1 - i] % mod;
ans += i * hsum[i] % mod;
ans %= mod;
val = (10 * val % mod + ch[i] - '0') % mod;
sum = (sum + val) % mod;
}
printf("%lld", ans % mod);
return 0;
}
暴力部分核心代码:
for(int l = 0; l < len; ++l){
LL cnt = 0;
for(int r = l; r < len; ++r){
for(int i = 0; i < len; ++i){
if(i < l || i > r){
cnt = (cnt * 10 % mod + ch[i] - '0') % mod;
}
}
ans = (ans + cnt) % mod;
}
}
T2
\(40pts\) 暴力:
求 \(gcd(i, n)\) 是有多次求的,可以用前缀和预处理 \(2000\) 个点然后 \(O(n)\) 出结果
/*
Work by: Suzt_ilymics
Knowledge: ??
Time: O(??)
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 1e6+6;;
const int INF = 1;
const int mod = 998244353;
int T, l, r;
int gcd[2010][2010];
int sum[2020];
int read(){
int s = 0, w = 1;
char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') w = -1; ch = getchar(); }
while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + ch - '0' , ch = getchar();
return s * w;
}
int Gcd(int x, int y){
return x % y == 0 ? y : Gcd(y, x % y);
}
void init(){
for(int i = 1; i <= 2000; ++i){
for(int j = 1; j <= i; ++j){
// a[i][j] = Gcd(j, i);
sum[i] = (sum[i] + Gcd(j, i)) % mod ;
}
}
}
int main()
{
init();
T = read();
while(T--){
l = read(), r = read();
int ans = 0;
for(int i = l; i <= r; ++i){
ans = (ans + sum[i]) % mod;
}
printf("%d\n", ans);
}
return 0;
}
\(100pts\) 正解
考虑化一下 \(f\) 。
\]
考虑对于每一个 \(1 \sim n\) 的值,能作为多少数对的 \(gcd\) ,于是有:
\]
发现 \(gcd(i, n) = d\) 的必要条件是 \(d \mid n\) ,原式可以改为:
\]
考虑什么样的 \(i\) ,满足 \(\gcd(i, n) = d\) ,显然当且仅当 \(i = kd(k \in \mathbb{N^*})\) ,且 \(\gcd(k, \frac{n}{d}) = 1\) 是满足条件。为保证 \(i \le n\) ,有 \(k \le \left\lfloor\frac{n}{d}\right\rfloor\) 。
于是考虑把 \(d\) 提出来,改为枚举上述的 \(k\) ,原式等于:
\]
考虑后面一个 \(\sum\) 的实际意义,表示 \(1 \sim \frac{n}{d}\) 中与 \(\frac{n}{d}\) 互质的个数,符合欧拉函数的定义,于是原式等于:
\]
线性筛预处理 \(\varphi\) 后,有埃氏筛即可筛出 \(1 \sim 10^{6}\) 的所有的 \(f\) 。
做个前缀和即可回答区间询问
复杂度 \(O(n\ \log \ n + m)\)
(Solution来自LuckyBlock的题解)
/*
Work by: Suzt_ilymics
Knowledge: ??
Time: O(??)
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 1e6+5;
const int kMax = 1e6;
const int INF = 1;
const int mod = 998244353;
int p_cnt, p[MAXN], phi[MAXN];
int f[MAXN], sum[MAXN];
bool vis[MAXN];
int read(){
int s = 0, w = 1;
char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') w = -1; ch = getchar(); }
while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + ch - '0' , ch = getchar();
return s * w;
}
void init(){
phi[1] = 1;
for(int i = 2; i <= kMax; ++i){
if(!vis[i]){
p[++p_cnt] = i;
phi[i] = i - 1;
}
for(int j = 1; j <= p_cnt && i * p[j] <= kMax; ++j){
vis[i * p[j]] = true;
if(i % p[j] == 0){
phi[i * p[j]] = phi[i] * p[j];
break;
}
phi[i * p[j]] = phi[i] * (p[j] - 1);
}
}
for(int i = 1; i <= kMax; ++i){
for(int j = i; j <= kMax; j += i){
f[j] = (f[j] + 1ll * phi[i] * (j / i) % mod) % mod;
}
}
for(int i = 1; i <= kMax; ++i){
sum[i] = (sum[i - 1] + f[i]) % mod;
}
}
int main()
{
init();
int m = read();
while(m--){
int l = read(), r = read();
printf("%d\n", (sum[r] - sum[l - 1] + mod) % mod);
}
}
T3
\(40pts\) 暴力:
暴力更改区间起点暴力求所有情况的最大值即可
/*
Work by: Suzt_ilymics
Knowledge: ??
Time: O(??)
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 1;
const int INF = 1;
const int mod = 1;
int n;
char a[50100], b[50010];
int read(){
int s = 0, w = 1;
char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') w = -1; ch = getchar(); }
while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + ch - '0' , ch = getchar();
return s * w;
}
int main()
{
n = read();
cin>>a>>b;
int ans = -1;
for(int i = 0; i < n; ++i){
int cnt = 0;
for(int j = 0; j < n; ++j){
int x = i + j;
x = (x >= n ? x - n : x);
if(a[j] == '1' && b[x] == '1'){
cnt++;
}
}
ans = max(ans, cnt);
}
printf("%d", ans);
return 0;
}
\(100pts\) 正解:
利用 bitset
容器,详细介绍请看 Oi-Wiki
/*
Work by: Suzt_ilymics
Knowledge: ??
Time: O(??)
*/
#include<iostream>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
using namespace std;
const int MAXN = 1e5+10;
const int INF = 1;
const int mod = 1;
int n, ans;
char s1[MAXN], s2[MAXN];
bitset <MAXN> a, b, c;
int read(){
int s = 0, w = 1;
char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') w = -1; ch = getchar(); }
while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + ch - '0' , ch = getchar();
return s * w;
}
void max(int &x, int y){if(x < y) x = y; }
int main()
{
n = read();
scanf("%s", s1 + 1);
scanf("%s", s2 + 1);
for(int i = 1; i <= n; ++i){
a[i] = (s1[i] == '1');
b[i] = (s2[i] == '1');
}
for(int i = 1; i <= n; ++i){
b[n + 1] = b[1];
b >>= 1;
max(ans, (a & b).count());
}
printf("%d", ans);
return 0;
}
T4
改自 CF1422C
只拿了部分分就不粘码了嘻嘻
「THP3考前信心赛」解题报告的更多相关文章
- 「THP3考前信心赛」题解
目录 写在前面 A 未来宇宙 B 空海澄澈 C 旧约酒馆 算法一 算法二 D 博物之志 算法一 算法二 算法三 写在前面 比赛地址:THP3 考前信心赛. 感谢原出题人的贡献:第一题 CF1422C, ...
- 「ZJOI2016」解题报告
「ZJOI2016」解题报告 我大浙的省选题真是超级神仙--这套已经算是比较可做的了. 「ZJOI2016」旅行者 神仙分治题. 对于一个矩形,每次我们从最长边切开,最短边不会超过 \(\sqrt{n ...
- #10471. 「2020-10-02 提高模拟赛」灌溉 (water)
题面:#10471. 「2020-10-02 提高模拟赛」灌溉 (water) 假设只有一组询问,我们可以用二分求解:二分最大距离是多少,然后找到深度最大的结点,并且把它的\(k\)倍祖先的一整子树删 ...
- #10470. 「2020-10-02 提高模拟赛」流水线 (line)
题面:#10470. 「2020-10-02 提高模拟赛」流水线 (line) 题目中的那么多区间的条件让人感觉极其难以维护,而且贪心的做法感觉大多都能 hack 掉,因此考虑寻找一些性质,然后再设计 ...
- nowcoder(牛客网)OI测试赛2 解题报告
qwq听说是一场普及组难度的比赛,所以我就兴高采烈地过来了qwq 然后发现题目确实不难qwq.....但是因为蒟蒻我太蒻了,考的还是很差啦qwq orz那些AK的dalao们qwq 赛后闲来无事,弄一 ...
- 冲刺Noip2017模拟赛1 解题报告——五十岚芒果酱
题1 国际象棋(chess) [问题描述] 有N个人要参加国际象棋比赛,该比赛要进行K场对弈.每个人最多参加2场对弈,最少参加0场对弈.每个人都有一个与其他人都不相同的等级(用一个正整数来表示).在对 ...
- 20161005 NOIP 模拟赛 T2 解题报告
beautiful 2.1 题目描述 一个长度为 n 的序列,对于每个位置 i 的数 ai 都有一个优美值,其定义是:找到序列中最 长的一段 [l, r],满足 l ≤ i ≤ r,且 [l, r] ...
- 冲刺Noip2017模拟赛5 解题报告——五十岚芒果酱
1. 公约数(gcd) [问题描述] 给定一个正整数,在[,n]的范围内,求出有多少个无序数对(a,b)满足 gcd(a,b)=a xor b. [输入格式] 输入共一行,一个正整数n. [输出格式] ...
- 冲刺Noip2017模拟赛3 解题报告——五十岚芒果酱
题1 素数 [问题描述] 给定一个正整数N,询问1到N中有多少个素数. [输入格式]primenum.in 一个正整数N. [输出格式]primenum.out 一个数Ans,表示1到N中有多少个素 ...
随机推荐
- ExecutionListener,TaskListener流程监听 和任务监听
1.ExecutionListener 流程实例的启动和结束. 选中一条连线. 节点的开始和结束. 网关的开始和结束. 中间事件的开始和结束. 开始时间结束或结束事件开始. 2.TaskListene ...
- 阿里巴巴java开发手册-嵩山版 下载
引言 今天阿里巴巴开发手册嵩山版又发布了,距离上次泰山版发布才仅仅几个月.是不是有的同学又要感叹下这速度也太快了点吧.我泰山版还没看完,嵩山版直接来了.没看完不要紧,我们直接看嵩山版本就好了.一次性把 ...
- JAVA数据结构(十一)—— 堆及堆排序
堆 堆基本介绍 堆排序是利用堆这种数据结构而设计的一种排序算法,堆排序是一种选择排序,最坏,最好,平均时间复杂度都是O(nlogn),不稳定的排序 堆是具有以下性质的完全二叉树:每个节点的值都大于或等 ...
- Layui关闭弹出层对话框--刷新父界面
在毕设的开发中,添加用户.添加权限等等一些地方需要类似于bootstrap中的模态框.然而开发用的却是layui 在layui中有弹出层可以实现其中的效果. 但是,一般用的时候都是提交后关闭窗口,刷新 ...
- java混淆工具 字符串加密 程序加密 代码逻辑混淆 防止反编译
混淆工具使用文档 ht-confusion-project1.0.0 目 录 1.功能介绍... 1 2.安装说明... 3 2.1Window查询jdk版本(点击开始菜单,输入cmd, 输入java ...
- [强制]IDE使用UTF-8和LF
Java 程序开发常用的集成开发环境(IDE)有Eclipse和IntelliJ IDEA.Eclipse是免费开源的,很多早期程序员使用它的比较多.IntelliJ IDEA有社区版和企业版,社区版 ...
- netty核心组件之EventLoopGroup和EventLoop
这节我们着重介绍netty最为核心的组件EventLoopGroup和EventLoop EventLoopGroup:顾名思义就是EventLoop的组,下面来看它们的继承结构 在netty中我们可 ...
- Ubuntu_Gedit配置
Ubuntu_Gedit配置 为了换Ubuntu的时候能够更加方便,不用再用手重新打一遍代码,丢几个Gedit配置-- External Tools gdb compile (F2) #!/bin/s ...
- 关联实现上-jsonpath取值
举例子: demo01.py import jsonimport requestsimport jsonpathsession = requests.session()get_param_dict={ ...
- linux系统图形化管理工具
webmin是一个非常好的图形化管理工具,提供了系统管理员对于linux系统的运维效率.对于那些记不住命令,新入门的新手真的是一个很好的工具呀,上图吧. 这是系统管理的首页,可以看到,CPU,内存.虚 ...