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 ...
随机推荐
- Object.setPrototypeOf() 与Object.getPrototypeOf() 方法的使用
Object.setPrototypeOf 方法的使用 [1] 将一个指定的对象的原型设置为另一个对象或者null(既对象的[[Prototype]]内部属性). 语法 Object.setProto ...
- Unity Shader 序列帧动画
shader中的序列帧动画属于纹理动画中的一种,主要原理是将给定的纹理进行等分,再根据时间的变化循环播放等分中的一部分. Unity Shader 内置时间变量 名称 类型 描述 _Time floa ...
- sqlyog管理关系型数据库mysql数据库之sqlyog的安装管理
.关系型数据库 有库有表,有关系 非关系型数据库 存储对象.集 下面的所有演示截图都是基不超过SQLyog 11进行的. 1. 2.点击上图中的应用程序,进行安装. 安装sqlyog , 账户dd0 ...
- CentOS7 SUDO 笔记--没配置sudoer,为什么有的账号能用sudo命令,有的不能用
原来: 一.安装linux 创建的用户(管理员打钩)默认在 wheel组里. 1. 使用 cat /etc/passwd 查看用户所在组.中间那个数字是 groupid 不太好看 2.使用 cat / ...
- [转帖]微服务框架Spring Cloud介绍 Part1: 使用事件和消息队列实现分布式事务
微服务框架Spring Cloud介绍 Part1: 使用事件和消息队列实现分布式事务 http://skaka.me/blog/2016/04/21/springcloud1/ APR 21ST, ...
- 虚拟机Ubuntu18.04 root下 连接 windows 中 winScp
先查看自己虚拟机中是否有 ssh服务 如果没有的话先安装 apt-get install openssh-server 安装完之后 先手动开启一下服务 /etc/init.d/ssh restart ...
- NPOI Excel同一个单元格 多种字体
public static void CreateFont() { IWorkbook workbook = new HSSFWorkbook(); workbook.CreateSheet(&quo ...
- C# LDAP认证登录类参考
public class LDAPHelper { private DirectoryEntry _objDirectoryEntry; /// <sum ...
- Vue开发日志
一 搭建环境 mac 安装node brew install node 安装vue 全家桶 npm install -g vue-cli 选择一个目录做初始化 vue init webpack myp ...
- Generate a document using docxtemplater
生成word文档,更新word内容 http://javascript-ninja.fr/docxtemplater/v1/examples/demo.html https://docxtempl ...