Educational Codeforces Round 58
D. GCD Counting
题意:
给出n个点的树,每个点有一个权值,找出一条最长的路径使得路径上所有的点的gcd>1
题解:
gcd>1的一定不会有很多。所以暴力搞一下就行,不需要点分治。
1 #include <cstdio> 2 #include <algorithm> 3 #include <iostream> 4 #include <cstring> 5 #include <map> 6 7 using namespace std; 8 const int maxn=2e5+10; 9 int head[maxn],Next[2*maxn],to[2*maxn]; 10 int a[maxn]; 11 int n,sz; 12 void init(){ 13 sz=0; 14 memset(head,-1,sizeof(head)); 15 } 16 void add_edge(int a,int b){ 17 ++sz; 18 to[sz]=b;Next[sz]=head[a];head[a]=sz; 19 } 20 int gcd(int a,int b){ 21 if(!b)return a; 22 return gcd(b,a%b); 23 } 24 map<int,int>mp[maxn]; 25 int ans; 26 void dfs(int u,int fa){ 27 for(int i=head[u];i!=-1;i=Next[i]){ 28 int v=to[i]; 29 if(v==fa)continue; 30 dfs(v,u); 31 map<int,int>::iterator it,it2; 32 for(it=mp[v].begin();it!=mp[v].end();it++){ 33 int g=gcd((*it).first,a[u]); 34 if(g<=1)continue; 35 for(it2=mp[u].begin();it2!=mp[u].end();it2++){ 36 int g2=gcd((*it2).first,g); 37 if(g2<=1)continue; 38 ans=max(ans,(*it).second+(*it2).second+1); 39 } 40 mp[u][(*it).first]=max(mp[u][(*it).first],(*it).second); 41 } 42 } 43 // printf("%d %d\n",u,ans); 44 mp[u].clear(); 45 mp[u][a[u]]=1; 46 for(int i=head[u];i!=-1;i=Next[i]){ 47 int v=to[i]; 48 if(v==fa)continue; 49 map<int,int>::iterator it; 50 for(it=mp[v].begin();it!=mp[v].end();it++){ 51 int g=gcd(a[u],(*it).first); 52 if(g<=1)continue; 53 mp[u][g]=max(mp[u][g],(*it).second+1); 54 ans=max(ans,(*it).second+1); 55 } 56 } 57 } 58 59 int main(){ 60 scanf("%d",&n); 61 init(); 62 for(int i=1;i<=n;i++){ 63 scanf("%d",&a[i]); 64 if(a[i]>1)ans=1; 65 } 66 67 for(int i=1;i<n;i++){ 68 int u,v; 69 scanf("%d%d",&u,&v); 70 add_edge(u,v); 71 add_edge(v,u); 72 } 73 dfs(1,0); 74 printf("%d\n",ans); 75 return 0; 76 }
View Code
F. Trucks and Cities
题意:
一条笔直公路上有n个城市,第i个城市在a[i]的位置。有m辆卡车要从一个城市去另一个城市,每一辆卡车有四个属性来描述:s,f,c,r.分别是开始的城市,结束的城市,油耗,可以加油的数量。当卡车到达一个城市的时候就可以加油,每次加油都加满,开始的时候所有的车油都是满的。请你找到最小的V使得所有的卡车都能到达目的地。
题解:
对于一辆从s到t的车,它有k次加油的机会。发现实际上是将s到t的路径以城市为端点最多划分为最大长度最小的k+1段。可以发现这样是最优的。然后就dp+单调队列优化。
代码留坑···
G. (Zero XOR Subset)-less
题意:
给出n个整数a1,a2,...,an。你的任务是将这n个整数分成最多段用下面的方法 1.每个元素都被一段包含 2.每一段都包含至少一个元素 3.每一个非空的段的子集,他们的xor不等于0.
输出最多能分成几段,如果没有合法的分段方法,输出-1.
题解:
当这n个数xor起来如果为0那么肯定是无解的。然后求线性基,线性基的大小r就是答案····
1 #include <cstdio> 2 #include <algorithm> 3 #include <cstring> 4 #include <iostream> 5 6 using namespace std; 7 typedef long long LL; 8 const int maxn=2e5+10; 9 LL a[maxn]; 10 LL x[100]; 11 int n; 12 int main(){ 13 scanf("%d",&n); 14 LL sum=0; 15 for(int i=1;i<=n;i++){ 16 scanf("%I64d",&a[i]); 17 sum^=a[i]; 18 } 19 if(sum==0){ 20 printf("-1\n"); 21 return 0; 22 } 23 int r=0; 24 for(int i=1;i<=n;i++){ 25 for(int j=62;j>=0;j--){ 26 if(!(a[i]>>j))continue; 27 if(!x[j]){ 28 x[j]=a[i]; 29 r++; 30 break; 31 } 32 a[i]^=x[j]; 33 } 34 } 35 printf("%d\n",r); 36 return 0; 37 }
View Code
转载于:https://www.cnblogs.com/LQLlulu/p/10388528.html
Educational Codeforces Round 58相关推荐
- 【CF套题】 Educational Codeforces Round 58
[前言] 组队CF之帮wyl上橙,我和sc打小号上紫. 结果sc成功FST两题,wyl成功skipped. 我的小号幸存了qwq. [题目] 原题地址 A.Minimum Integer 特判一下dd ...
- Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)
Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...
- Educational Codeforces Round 24 E. Card Game Again(双指针)
题目链接:Educational Codeforces Round 24 E. Card Game Again 题意: 给你n个数和一个数k. 现在每次可以拿掉前x个数,后y个数,剩下的数的乘积要能被 ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...
- Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...
- Educational Codeforces Round 32
http://codeforces.com/contest/888 A Local Extrema[水] [题意]:计算极值点个数 [分析]:除了第一个最后一个外,遇到极值点ans++,包括极大和极小 ...
- Educational Codeforces Round 37 (Rated for Div. 2) 1
Educational Codeforces Round 37 (Rated for Div. 2) A.Water The Garden 题意:Max想给花园浇水.花园可被视为长度为n的花园床,花园 ...
- Educational Codeforces Round 89 (Rated for Div. 2)(A, B, C, D)
Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords 思路 题意非常简单,就是得到最多的物品嘛,我们假定a, ...
最新文章
- 提取ESX/ESXI4.0脚本安装文件ks.cfg、ks-first.cfg和ks-first-safe.cfg
- Photoshop剪切板故障修复
- C语言0xc0000142错误,第一次用c++编译器出现奇怪的报错
- c语言循环结成绩统计,学生成绩统计C语言实现
- Python nltk包
- mac os 开启FTP Server
- 聊聊数据中心备份和恢复解决方案厂商和产品(附Gartner报告)
- iOS开发篇——OC之NSNumber数字对象讲解
- .net5项目托管到iis无法访问
- 【计算机网络】网络通信基础
- 分页 在mybatis执行SQL语句之前进行拦击处理实例
- Cortana搜索框怎么在任务栏显示?
- 苹果14pro Max来了,做第一批吃蟹人
- idea 一直不停的updating indices 卡进度条问题
- CV——基于Stitcher类实现图片拼接
- 【OpenGL学习笔记五】 索引缓冲对象EBO
- python计算时间加减,python datetime库使用和时间加减计算
- 我国计算机发展优势,浅析我国计算机应用发展.doc
- Cordova 环境搭建+打包Android APK
- WeChall CTF Writeup(七)
热门文章
- 手机配置网络代理服务器_两张图简说代理服务器和反向代理服务器
- php排序order,#ThinkPHP#视图下order排序
- c语言随机数表,C语言随机数
- “有本事你去学校数据库把期末成绩改了“,“好,你等着。“
- html图片实现左右滑动,jquery实现左右滑动式轮播图
- 算法——动态规划算法
- 利用Auto Deploy 部署ESXi 5
- cocos2d-x学习笔记番外篇05:如何快速屏蔽触摸
- 函数的非固定参数,默认参数,参数组
- 网络丢包诊断与分析的现实与理想