Gym - 102056C(2018EC final) -Heretical … Möbius ——CRT
题意
给出一个长为200的01序列,判断是否在前1e9个莫比乌斯*值中。(这里的莫比乌斯值加了绝对值)
分析
意到因为4的倍数一定是0,9的倍数一定是0……169的倍数一定是0。那么我们可以对4,9,25,49,121,169这6个200以内这质数平方进行考虑。
我们可以枚举起点位置 $x$ 对这6个数的模数,然后用CRT求出 $x$。对每个起点位置,暴力对比即可。不可能存在所有的mu值,只能单个求。
由于0的个数介于65~95,所以符合条件的起点位置并不多,因此不会超时。
#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll up = 1e9;
const int N = 5e4 + ; int prime[N];
bool notprime[N];
void getprime()
{
for (int i = ; i < N; i++) {
if(!notprime[i]) prime[++prime[]] = i;
for (int j = ; j <= prime[] && i * prime[j] < N; j++)
{
notprime[i * prime[j]] = ;
if(i%prime[j]==) break;
}
}
} int mu(int x) { //求单个mu值
for (int i = ; i <= prime[] && prime[i] * prime[i] <= x; i++) {
if(x%(prime[i]*prime[i]) == ) return ;
if(x%prime[i] == ) x/=prime[i];
}
return ;
} ll exgcd(ll a,ll b,ll &x, ll &y) {
ll g = a;
if(b==) x=,y=; else g=exgcd(b,a%b,y,x),y-=x*(a/b);
return g;
} ll inv(ll a,ll m) {
ll x, y;
ll d = exgcd(a, m, x, y);
return (d == ) ? (x % m + m) % m : -;
} int ti[], m[] = {, , , , , }, a[];
int M; void CRT() {
M = ;
for(int i = ; i < ; i ++) M = M*m[i];
for(int i = ; i < ; i++) {
int Mi = M/m[i];
ti[i] = 1LL*inv(Mi, m[i])*Mi%M;
}
} string s,t; int check(int v, int r) {
while(v < ) {
if(s[v] == '') return ;
v += r;
}
return ;
} int ok(int x) {
for (int i = ; i < ; i++)
if(mu(i+x) != s[i]-'') return ;
return ;
} int ans = inf; void dfs(int x) {
if(x == ) {
int v = ;
for(int i = ; i < ; i++) v = (v + 1LL*ti[i]*a[i]%M)%M; //v为CRT的值
if(v == ) v = M;
while(v+ <= up && v < ans) {
if(ok(v)) ans = v;
v = v + M;
}
return;
}
for(int i = ; i < m[x]; i++) { //枚举余数a[i]
if(check(i, m[x])) {
a[x] = ( m[x] - i );
dfs(x+);
}
}
} int main(){
getprime();
CRT();
for(int i = ; i < ; i++) {cin >> t, s = s + t;}
int num = ;
for(int i = ; i < s.size(); i++)
if(s[i] == '') num++;
if(num < || num > ) //0的个数在一个范围内
cout << - << endl;
else {
dfs();
if(ans == inf)
cout << - << endl;
else
cout << ans << endl;
}
return ;
}
参考链接:
1. https://blog.csdn.net/BUAA_Alchemist/article/details/86652706
2. https://blog.csdn.net/a1214034447/article/details/86373308
3. https://ac.nowcoder.com/acm/contest/view-submission?submissionId=40622831
Gym - 102056C(2018EC final) -Heretical … Möbius ——CRT的更多相关文章
- CF388C&&2018EC Final D题——博弈&&水题
一下两个题目都是按堆取石子,轮流取,每个人都贪心的取即可,感觉都不像博弈. CF388C 有n排石子,每排有若干堆.Ciel可以选择一排,拿走这一排的第一堆石子.Jiro可以选择一排,拿走这一排的最后 ...
- 我又造了个轮子:GrpcGateway
我个人对GRPC是比较感兴趣的,最近在玩通过前端调用GRPC.通过前端调用GRPC业界有两种方式:GRPC Web和GRPC JSON转码. GRPC Web 通过JS或者Blazor WASM调用G ...
- Gym 102056I - Misunderstood … Missing - [DP][The 2018 ICPC Asia-East Continent Final Problem I]
题目链接:https://codeforces.com/gym/102056/problem/I Warm sunshine, cool wind and a fine day, while the ...
- Gym 102056L - Eventual … Journey - [分类讨论][The 2018 ICPC Asia-East Continent Final Problem L]
题目链接:https://codeforces.com/gym/102056/problem/L LCR is really an incredible being. Thinking so, sit ...
- 2016-2017 National Taiwan University World Final Team Selection Contest (Codeforces Gym) 部分题解
D 考虑每个点被删除时其他点对它的贡献,然后发现要求出距离为1~k的点对有多少个. 树分治+FFT.分治时把所有点放一起做一遍FFT,然后减去把每棵子树单独做FFT求出来的值. 复杂度$nlog^ ...
- Codeforces Gym 101775D Mr. Panda and Geometric Sequence(2017-2018 ACM-ICPC Asia East Continent League Final,D题,枚举剪枝)
题目链接 ECL-Final 2017 Problem D 题意 给定$2*10^{5}$组询问,每个询问求$l$到$r$之间有多少个符合条件的数 如果一个数小于等于$10^{15}$, 并且能被 ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
- Codeforces gym 100685 F. Flood bfs
F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Desc ...
- Gym 100952I&&2015 HIAST Collegiate Programming Contest I. Mancala【模拟】
I. Mancala time limit per test:3 seconds memory limit per test:256 megabytes input:standard input ou ...
随机推荐
- linux 修改oracle的字符集
select userenv('language') from dual; 命令可以查看服务端的使用的字符集. ssh登录,切换到oracle用户 切换用户命令:su -oracle 之后 ...
- 【MySQL】MariaDB10.3新特性--闪回查询
MariaDB10.3新特性--闪回查询 System-Versioned表特性的引入,可以对表进行闪回.完成类似于Oracle的闪回查询. 修改已有表为System-Versioned MariaD ...
- Hbase Filter之PrefixFilter
PrefixFilter PrefixFilter是将rowkey前缀为指定字符串的数据全部过滤出来并返回给用户.例如: Scan scan = new Scan(); scan.setFilter( ...
- Vagrant 安装Oracle19c RAC测试环境的简单学习
1. 学习自网站: https://xiaoyu.blog.csdn.net/article/details/103135158 简单学习了下 能够将oracle RAC开起来了 但是 对后期的维护和 ...
- [转帖]超能课堂(210) 笔记本中常说的PL1、PL2到底如何影响CPU性能?
超能课堂(210)笔记本中常说的PL1.PL2到底如何影响CPU性能? https://www.expreview.com/71943.html 本文约 4070 字,需 7 分钟阅读 (切换至标准版 ...
- Python 3 的 int 类型详解(为什么 int 不存在溢出问题?)
在以前的Python2中,整型分为int和long,也就是整型和长整型, 长整型不存在溢出问题, 即可以存放任意大小的数值,理论支持无限大数字. 因此在Python3 中,统一使用长整型,用int表示 ...
- .NET[C#]使用LINQ从List<T>集合中获取最后N条数据记录的方法有哪些?
https://codedefault.com/2018/using-linq-to-get-the-last-n-elements-of-a-collection-in-csharp-applica ...
- Notes:Unit Testing
UnitTesting shanzm 右键-->在新标签页中打开图片,即可查看原图,图片超乎你想像的大!
- MySQL UNION 操作符
本教程为大家介绍 MySQL UNION 操作符的语法和实例. 描述 MySQL UNION 操作符用于连接两个以上的 SELECT 语句的结果组合到一个结果集合中.多个 SELECT 语句会删除重复 ...
- sedlauncher.exe 磁盘爆满
打开应用和功能,搜KB4023057,然后卸载. 快捷键WIN+R打开运行,输入services.msc回车打开系统服务,找到Windows Remediation Service (sedsvc)和 ...