【2020牛客NOIP赛前集训营-提高组(第二场)】题解(GCD,包含,前缀,移动)

文章目录

  • T1:GCD
    • title
    • solution
    • code
  • T2:包含
    • title
    • solution
    • code(正解code补充在上面了)
  • T3:前缀
    • title
    • solution
    • code
  • T4:移动
    • title
    • solution
    • code

在这里插入图片描述

T1:GCD

title

solution

非常水,看一眼就知道了
首先我们知道每一个数都有唯一的标准整数分解,即拆成若干个质数的幂的乘积
而我们又知道质数彼此互质,gcd()=1gcd()=1gcd()=1
所以就可以迅速反应到,如果一个数有≥2\ge 22个质数因子,那么gcdgcdgcd一定等于111
否则gcdgcdgcd就是唯一的质数因子
这样的话,需要寻找的特殊数一定是幂级递增

欧拉筛出nnn以内的所有质数,然后进行幂级累乘,时间复杂度就是O(nlogn)O(nlogn)O(nlogn)
最后加上没有被计算的数的个数即可,因为这些数每个都只会贡献111

然后直接干掉这道水题
在这里插入图片描述

code

#include <cstdio>
#define ll long long
#define MAXN 10000000
int a, b, cnt;
int prime[MAXN + 5];
bool vis[MAXN + 5];
ll ans[MAXN + 5];void sieve() {for( int i = 2;i <= MAXN;i ++ ) {if( ! vis[i] )vis[i] = 1, prime[++ cnt] = i;for( int j = 1;i * prime[j] <= MAXN && j <= cnt;j ++ ) {vis[i * prime[j]] = 1;if( i % prime[j] == 0 ) break;}}
}int main() {sieve();for( int i = 1;i <= MAXN;i ++ )ans[i] = 1;for( int i = 1;i <= cnt;i ++ ) {int j = 1;while( 1ll * j * prime[i] <= MAXN ) {j *= prime[i];ans[j] = prime[i];}}for( int i = 1;i <= MAXN;i ++ )ans[i] += ans[i - 1];scanf( "%d %d", &a, &b );printf( "%lld\n", ans[b] - ans[a - 1] );return 0;
}

T2:包含

title

solution

这道题只要了解一点点枚举子集就能ACACAC
在这里插入图片描述直接暴力一个数枚举子集
自测大数据跑了1.3s以为会T,但是没想到交上去能跑过诶
在这里插入图片描述好了——数据加强了,终于,我被卡掉了5分
正解就是每次随便丢掉任何一个111O(nlogn)O(nlogn)O(nlogn)

#include <cstdio>
#define MAXN 1000005
int n, m;
bool vis[MAXN];int main() {scanf( "%d %d", &n, &m );for( int i = 1, x;i <= n;i ++ ) {scanf( "%d", &x );vis[x] = 1;}for( int i = 1e6;i;i -- ) {if( ! vis[i] ) continue;for( int j = 0;j < 20;j ++ )if( i >> j & 1 )vis[i ^ ( 1 << j )] = 1;}for( int i = 1, x;i <= m;i ++ ) {scanf( "%d", &x );if( vis[x] ) printf( "yes\n" );else printf( "no\n" );}return 0;
}

code(正解code补充在上面了)

#include <cstdio>
#include <iostream>
using namespace std;
#define MAXN 100005
#define MAXM 1000000
int n, m, cnt, maxx;
int a[MAXN];
bool vis[MAXM + 5];int main() {scanf( "%d %d", &n, &m );for( int i = 1;i <= n;i ++ ) {scanf( "%d", &a[i] );maxx = max( maxx, a[i] );}for( int i = 1;i <= n;i ++ ) {int x = a[i];if( vis[x] ) continue;vis[x] = 1, cnt ++;if( cnt == maxx ) continue;for( int j = x;j;j = ( ( j - 1 ) & x ) )if( ! vis[j] ) {vis[j] = 1;cnt ++;if( cnt == maxx ) break;}}for( int i = 1, x;i <= m;i ++ ) {scanf( "%d", &x );if( vis[x] ) printf( "yes\n" );else printf( "no\n" );}return 0;
}

T3:前缀

title

solution

大模拟!!无需多说慢慢敲,高精直接上
在这里插入图片描述

code

#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define int long long
#define mod 998244353
#define MAXN 100005
vector < int > pos[30];
char s[MAXN], t[MAXN];
int pi[MAXN][2], num[MAXN];
int n, ans;int calc( int l, int r, int siz, int len ) {int cnt = 0, ip;for( int i = l;i <= r;i ++ )num[i - l + 1] = t[i] ^ 48;for( ip = r - l + 1;! num[ip];ip -- );num[ip] --;for( int i = ip + 1;i <= r - l + 1;i ++ )num[i] = 9;int g = 0, R = 0;for( int i = 1;i <= r - l + 1;i ++ )g = R * 10 + num[i], num[++ cnt] = g / siz, R = g % siz;g = 0;for( int i = cnt;i;i -- )g += len * num[i], num[i] = g % 10, g /= 10;for( int i = 1;i <= cnt;i ++ )g = ( g * 10 + num[i] ) % mod;ans = ( ans + g ) % mod;return R;
}signed main() {scanf( "%s", s );int lens = strlen( s );for( int i = 0;i < lens;i ++ )pos[s[i] ^ 96].push_back( i ), pi[i][0] = pos[s[i] ^ 96].size() - 1;for( int i = 0;i < lens;i ++ )pos[0].push_back( i ), pi[i][1] = i;scanf( "%lld", &n );while( n -- ) {ans = 0;scanf( "%s", t );int lent = strlen( t );int l = 0, r = 0, now = lens - 1, nxt, flag = 1, f;for( ;l < lent;l = ++ r ) {if( t[l] == '*' ) t[l] = 96, f = 1;else f = 0;int id = t[l] ^ 96, siz = pos[id].size();if( ! siz ) { flag = 0; break; }if( pos[id][siz - 1] <= now ) nxt = pos[id][0];else nxt = *upper_bound( pos[id].begin(), pos[id].end(), now );if( now < nxt ) ans = ( ans + nxt - now ) % mod, now = nxt;else ans = ( ans + lens + nxt - now ) % mod, now = nxt;if( l + 1 < lent && isdigit( t[l + 1] ) )for( ;r + 1 < lent && isdigit( t[r + 1] );r ++ );if( l < r ) {int R = calc( l + 1, r, siz, lens );if( R ) {nxt = pos[id][( pi[now][f] + R ) % siz];if( now < nxt ) ans = ( ans + nxt - now ) % mod, now = nxt;else ans = ( ans + lens + nxt - now ) % mod, now = nxt;}}}if( ! flag ) printf( "-1\n" );else printf( "%lld\n", ans );}return 0;
}

T4:移动

title

solution

用心出题,用脚造数据
有的代码不考虑后退错误贪心都能AC,还有暴力过去的
在这里插入图片描述
考虑将时间离散化,变成每个门在哪些时间段会打开,用vector+pairvector+pairvector+pair存储
大概是n+mn+mn+m个时间段

dp[i]dp[i]dp[i]表示最早到达 第iii个时间段对应的门 的时间
然后用类似最短路的方法去dpdpdp转移,每次可以向两边转移(前提是这个门和转移到达的门都打开)
在这里插入图片描述

code

#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
#define Pair pair < int, int >
#define inf 0x3f3f3f3f
#define MAXN 100005
struct node {int id, x, t;node() {}node( int Id, int X, int T ) {id = Id, x = X, t = T;}
};
priority_queue < node, vector < node >, greater < node > > q;
vector < Pair > G[MAXN], tmp;
int n, m;
int id[MAXN << 1], dp[MAXN << 1];bool cmp( Pair x, Pair y ) {return x.first < y.first;
}bool operator > ( node x, node y ) {return x.t > y.t;
}void calc( node p, int x ) {int r = G[p.x][p.id - id[p.x]].second;int i = lower_bound( G[x].begin(), G[x].end(), make_pair( p.t + 1, 0 ) ) - G[x].begin() - 1;if( G[x][i].second >= p.t + 1 ) {if( dp[id[x] + i] > p.t + 1 ) {dp[id[x] + i] = p.t + 1;q.push( node( id[x] + i, x, p.t + 1 ) );}}i ++;while( i < G[x].size() && G[x][i].first <= r + 1 ) {if( dp[id[x] + i] > G[x][i].first ) {dp[id[x] + i] = G[x][i].first;q.push( node( id[x] + i, x, G[x][i].first ) );}i ++;}
}void solve() {memset( dp, 0x3f, sizeof( dp ) );q.push( node( 0, 0, 0 ) );dp[0] = 0;while( ! q.empty() ) {node now = q.top(); q.pop();if( now.t > dp[now.id] ) continue;if( now.x > 0 ) calc( now, now.x - 1 );if( now.x <= n ) calc( now, now.x + 1 );}
}int main() {scanf( "%d %d", &n, &m );for( int i = 1, a, b, c;i <= m;i ++ ) {scanf( "%d %d %d", &a, &b, &c );G[a].push_back( make_pair( b, c ) );}G[0].push_back( make_pair( 0, inf ) );G[n + 1].push_back( make_pair( 0, inf ) );id[1] = 1;for( int i = 1;i <= n;i ++ ) {tmp.clear();sort( G[i].begin(), G[i].end(), cmp );int r = -1;for( int j = 0;j < G[i].size();j ++ ) {if( G[i][j].first > r + 1 ) tmp.push_back( make_pair( r + 1, G[i][j].first - 1 ) );r = max( r, G[i][j].second );}tmp.push_back( make_pair( r + 1, inf ) );G[i] = tmp;id[i + 1] = id[i] + G[i].size();}solve();printf( "%d\n", dp[id[n + 1]] );return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/317809.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

.NET Core实战项目之CMS 第十五章 各层联动工作实现增删改查业务

连着两天更新叙述性的文章大家可别以为我转行了&#xff01;哈哈&#xff01;今天就继续讲讲我们的.NET Core实战项目之CMS系统的教程吧&#xff01;这个系列教程拖得太久了&#xff0c;所以今天我就以菜单部分的增删改查为例来讲述下我的项目分层之间的协同工作吧&#xff01;…

[2020-11-23 contest]图(dfs剪枝),劫富济贫(字典树),小A的树(树形DP),游戏(贪心/斜率优化)

文章目录T1&#xff1a;图solutioncodeT2&#xff1a;劫富济贫solutioncodeT3&#xff1a;小A的树solutioncodeT4&#xff1a;游戏solutioncodeT1&#xff1a;图 【问题描述】 给你一个n个点&#xff0c;m条边的无向图&#xff0c;每个点有一个非负的权值ci&#xff0c;现在你…

P1742 最小圆覆盖

P1742 最小圆覆盖 题意&#xff1a; 给出N个点&#xff0c;让你画一个最小的包含所有点的圆。 题解&#xff1a; 先说结论&#xff1a; 最优解的圆一定是在以某两个点连线为直径的圆 或者 某三个点组成的三角形的外接圆 初始化将某个圆心定为第一个点&#xff0c;R0 枚举第…

Java实现非对称加密【详解】

Java实现非对称加密 1. 简介2. 非对称加密算法--DH&#xff08;密钥交换&#xff09;3. 非对称加密算法--RSA非对称加密算法--EIGamal5. 总结6 案例6.1 案例16.2 案例26.3 案例3 1. 简介 公开密钥密码学&#xff08;英语&#xff1a;Public-key cryptography&#xff09;也称非…

轻量级.Net Core服务注册工具CodeDi发布啦

为什么做这么一个工具因为我们的系统往往时面向接口编程的,所以在开发Asp .net core项目的时候,一定会有大量大接口及其对应的实现要在ConfigureService注册到ServiceCollection中,传统的做法是加了一个服务,我们就要注册一次(service.AddService()),又比如,当一个接口有多个实…

2020 CSP-S 游记

迟到的游记总述T1&#xff1a;儒略日T2&#xff1a;动物园T3&#xff1a;函数调用T4&#xff1a;贪吃蛇总结总述 可能是有了去年第一次的狂炸经历&#xff0c;很明显的就是在考试策略上的提升 头不铁了&#xff0c;手不残了&#xff0c;心态稳了&#xff0c;分也多了 T1&…

P7516-[省选联考2021A/B卷]图函数【bfs】

正题 题目链接:https://www.luogu.com.cn/problem/P7516 题目大意 懒了&#xff0c;直接抄题意了 对于一张 nnn 个点 mmm 条边的有向图 GGG&#xff08;顶点从 1∼n1 \sim n1∼n 编号&#xff09;&#xff0c;定义函数 f(u,G)f(u, G)f(u,G)&#xff1a; 初始化返回值 cnt0cn…

【.NET Core项目实战-统一认证平台】第十三章 授权篇-如何强制有效令牌过期

上一篇我介绍了JWT的生成验证及流程内容&#xff0c;相信大家也对JWT非常熟悉了&#xff0c;今天将从一个小众的需求出发&#xff0c;介绍如何强制令牌过期的思路和实现过程。.netcore项目实战交流群&#xff08;637326624&#xff09;&#xff0c;有兴趣的朋友可以在群里交流讨…

[2020-11-24 contest]糖果机器(二维偏序),手套(状压dp),甲虫(区间dp),选举(线段树 最大子段和)

文章目录T1&#xff1a;糖果机器solutioncodeT2&#xff1a;手套solutioncodeT3&#xff1a;甲虫solutioncodeT4&#xff1a;选举solutioncodeT1&#xff1a;糖果机器 solution 考虑从第iii个糖果出发能到达第jjj个&#xff0c;则有Tj−Ti≥∣Sj−Si∣T_j-T_i≥|S_j-S_i|Tj​…

ASP.NET Core 数据加解密的一些坑

点击蓝字关注我ASP.NET Core 给我们提供了自带的Data Protection机制&#xff0c;用于敏感数据加解密&#xff0c;带来方便的同时也有一些限制可能引发问题&#xff0c;这几天我就被狠狠爆了一把我的场景我的博客系统有个发送邮件通知的功能&#xff0c;因此需要配置一个邮箱账…

[2020-11-28 contest]素数(数学),精灵(区间dp),农夫约的假期(结论),观察(树链剖分lca+set)

文章目录素数solutioncode精灵solutioncode农夫约的假期solutioncode观察solutionsolutioncode素数 solution 通过观察可得一个结论 对于两个相邻的质数p1,p2(p1<p2)p_1,p_2\ (p_1<p_2)p1​,p2​ (p1​<p2​) 对于x∈[p1,p2)x∈[p_1,p_2)x∈[p1​,p2​)&#xff0c;都…

B. Box Fitting

B. Box Fitting 题意&#xff1a; 现在有n个长方形&#xff0c;宽均为1&#xff0c;现在有一个底为m的容器&#xff0c;问将长方形放入其中&#xff0c;所用容器的最小宽度是多少 &#xff08;长方形必须长朝下放置详细如图&#xff09; 题解&#xff1a; 比赛时脑子抽了。…

人工智能第六课:如何做研究

这是我学习 Data Science Research Methods 这门课程的笔记。这门课程的讲师是一名教授和数据科学家&#xff0c;可能因为他既有理论背景&#xff0c;又有实践经验&#xff0c;所以整个课程听下来还比较舒服&#xff0c;学到了一些不错的理论知识。这门课比较系统地介绍了什么…

[2020-11-30 contest]数列(矩阵加速),秘密通道(dijkstra最短路)小X游世界树(换根dp),划分(数学)

文章目录数列solutioncode秘密通道solutioncode小X游世界树solutioncode划分solutioncode数列 a[1]a[2]a[3]1 a[x]a[x-3]a[x-1] (x>3) 求 a 数列的第 n 项对 1000000007&#xff08;10^97&#xff09;取余的值。 输入格式 第一行一个整数 T&#xff0c;表示询问个数。 以下…

Docker最全教程——数据库容器化之持久保存数据(十二)

上一节我们讲述了SQL Server容器化实践&#xff08;注意&#xff0c;SQL Server现在也支持跨平台&#xff09;&#xff0c;本节将讲述如何持久保存数据&#xff0c;并且接下来将逐步讲解其他数据库&#xff08;MySql、Redis、Mongodb等等&#xff09;的容器化实践&#xff0c;中…

【李超树】李超线段树维护凸包(凸壳) (例题:blue mary开公司+线段游戏+ZZH的旅行)

文章目录前言李超树引入(斜率优化)什么是李超树&#xff1f;李超树活着能干点什么&#xff1f;算法思想(使用手册&#xff1f;)插入查询模板判断是否覆盖(优不优)插入查询例题板题&#xff1a;BlueMary开公司分析code线段游戏分析code拓展——(动态开点李超树维护凸包)ZZH的旅行…

老牌开源Office操作组件NPOI现已支持.NET Core

昨天在微信群里听到老牌Excel开发利器NPOI的作者瞿总说4.6.1版本的NPOI已经支持.NET Standard 2.0了&#xff0c;这也就意味着你可以在.NET Core中使用NPOI了。作者&#xff1a;依乐祝原文地址 &#xff1a;https://www.cnblogs.com/yilezhu/p/10269281.html写在前面曾经的.NET…

.NET西安社区 [拥抱开源,又见 .NET] 第二次活动简报

「拥抱开源, 又见 .NET」随着 .NET Core的发布和开源&#xff0c;.NET又重新回到人们的视野。 .NET Core的下个3.0即将release&#xff0c;加入非常多的新功能&#xff0c;越来越拥抱变化&#xff0c;DevOps和Microservice的最佳实践已经在 .NET Core落地&#xff0c;比如 Ocel…

[dsu on tree]树上启发式合并总结(算法思想及模板附例题练习)

文章目录前言树上启发式合并引入算法思想时间复杂度模板练习例题&#xff1a;CF600E Lomsat gelralsolutioncodeCF208E Blood CousinssolutioncodeCF570D Tree RequestssolutioncodeCF1009F Dominant Indicessolutioncode前言 最近不是在⛏李超树嘛&#xff0c;然后就去玩了下…

领域驱动设计,让程序员心中有码(七)

领域驱动设计- 让程序员心中有码&#xff08;七&#xff09;-设计原则和设计模式&#xff0c;互联网开发者们共同的追求前言多年来&#xff0c;笔者一直从事传统软件企业的软件开发和项目管理工作。笔者发现在众多的传统软件企业中&#xff0c;评判优秀开发者的标准往往是技能的…