Educational Codeforces Round 58
D. GCD Counting
题意:
给出n个点的树,每个点有一个权值,找出一条最长的路径使得路径上所有的点的gcd>1
题解:
gcd>1的一定不会有很多。所以暴力搞一下就行,不需要点分治。
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map> using namespace std;
const int maxn=2e5+;
int head[maxn],Next[*maxn],to[*maxn];
int a[maxn];
int n,sz;
void init(){
sz=;
memset(head,-,sizeof(head));
}
void add_edge(int a,int b){
++sz;
to[sz]=b;Next[sz]=head[a];head[a]=sz;
}
int gcd(int a,int b){
if(!b)return a;
return gcd(b,a%b);
}
map<int,int>mp[maxn];
int ans;
void dfs(int u,int fa){
for(int i=head[u];i!=-;i=Next[i]){
int v=to[i];
if(v==fa)continue;
dfs(v,u);
map<int,int>::iterator it,it2;
for(it=mp[v].begin();it!=mp[v].end();it++){
int g=gcd((*it).first,a[u]);
if(g<=)continue;
for(it2=mp[u].begin();it2!=mp[u].end();it2++){
int g2=gcd((*it2).first,g);
if(g2<=)continue;
ans=max(ans,(*it).second+(*it2).second+);
}
mp[u][(*it).first]=max(mp[u][(*it).first],(*it).second);
}
}
// printf("%d %d\n",u,ans);
mp[u].clear();
mp[u][a[u]]=;
for(int i=head[u];i!=-;i=Next[i]){
int v=to[i];
if(v==fa)continue;
map<int,int>::iterator it;
for(it=mp[v].begin();it!=mp[v].end();it++){
int g=gcd(a[u],(*it).first);
if(g<=)continue;
mp[u][g]=max(mp[u][g],(*it).second+);
ans=max(ans,(*it).second+);
}
}
} int main(){
scanf("%d",&n);
init();
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]>)ans=;
} for(int i=;i<n;i++){
int u,v;
scanf("%d%d",&u,&v);
add_edge(u,v);
add_edge(v,u);
}
dfs(,);
printf("%d\n",ans);
return ;
}
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就是答案····
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream> using namespace std;
typedef long long LL;
const int maxn=2e5+;
LL a[maxn];
LL x[];
int n;
int main(){
scanf("%d",&n);
LL sum=;
for(int i=;i<=n;i++){
scanf("%I64d",&a[i]);
sum^=a[i];
}
if(sum==){
printf("-1\n");
return ;
}
int r=;
for(int i=;i<=n;i++){
for(int j=;j>=;j--){
if(!(a[i]>>j))continue;
if(!x[j]){
x[j]=a[i];
r++;
break;
}
a[i]^=x[j];
}
}
printf("%d\n",r);
return ;
}
Educational Codeforces Round 58的更多相关文章
- Educational Codeforces Round 58 (Rated for Div. 2) 题解
Educational Codeforces Round 58 (Rated for Div. 2) 题目总链接:https://codeforces.com/contest/1101 A. Min ...
- Educational Codeforces Round 58 (Rated for Div. 2) F dp + 优化(新坑) + 离线处理
https://codeforces.com/contest/1101/problem/F 题意 有n个城市,m辆卡车,每辆卡车有起点\(s_i\),终点\(f_i\),每公里油耗\(c_i\),可加 ...
- Educational Codeforces Round 58 (Rated for Div. 2) D 树形dp + 数学
https://codeforces.com/contest/1101/problem/D 题意 一颗n个点的树,找出一条gcd>1的最长链,输出长度 题解 容易想到从自底向长转移 因为只需要g ...
- Educational Codeforces Round 58 (Rated for Div. 2) G 线性基
https://codeforces.com/contest/1101/problem/G 题意 一个有n个数字的数组a[],将区间分成尽可能多段,使得段之间的相互组合异或和不等于零 题解 根据线性基 ...
- Educational Codeforces Round 58 A,B,C,D,E,G
A. Minimum Integer 链接:http://codeforces.com/contest/1101/problem/A 代码: #include<bits/stdc++.h> ...
- Educational Codeforces Round 58 Div. 2 自闭记
明明多个几秒就能场上AK了.自闭. A:签到. #include<iostream> #include<cstdio> #include<cmath> #inclu ...
- Educational Codeforces Round 58 Solution
A. Minimum Integer 签到. #include <bits/stdc++.h> using namespace std; #define ll long long ll l ...
- Educational Codeforces Round 58 (Rated for Div. 2)
A. Minimum Integer 水 #include<bits/stdc++.h> #define clr(a,b) memset(a,b,sizeof(a)) using name ...
- Educational Codeforces Round 58 (Rated for Div. 2) (前两题题解)
感慨 这次比较昏迷最近算法有点飘,都在玩pygame...做出第一题让人hack了,第二题还昏迷想错了 A Minimum Integer(数学) 水题,上来就能做出来但是让人hack成了tle,所以 ...
随机推荐
- Apache JMeter配置、安装
一. 工具描述 apache jmeter是100%的java桌面应用程序,它被设计用来加载被测试软件功能特性.度量被测试软件的性能.设计jmeter的初衷是测试web应用,后来又扩充了其它的功能.j ...
- ROS-RouterOS hAP ac2+usb 4G上网卡+小米新推的无线上网卡是绝配
月租9元.每日缴1元.上网不限量 Model Tested RouterOS version Format Passthrough support TechnologiesZTE MF823 v6.8 ...
- Web 项目遇到的乱码问题
问题代码: jsp: <%@ page language="java" contentType="text/html; charset=UTF-8" pa ...
- 第6章 进程控制(3)_wait、exec和system函数
5. 等待函数 (1)wait和waitpid 头文件 #include <sys/types.h> #include <sys/wait.h> 函数 pid_t wait(i ...
- asp.net webapi 自托管插件式服务(转)
asp.net webapi 自托管插件式服务 webapi问世已久,稀里糊涂的人哪它都当mvc来使,毕竟已mvc使用级别的经验就可以应对webapi. webapi和mvc在asp.net5时代 ...
- spring-mvc注解配置小记
Controller中注解Service时,Service的实现类需加@Service,dao的实现类需加@Repository. 另:配置文件中对应的包也需要扫描到!!! <context:a ...
- Linux常用命令的命名来源
很多人在学习Linux的时候会疑惑:这么多的Linux名,他们都是怎么被定义的?林纳斯是怎么制定如此花样繁多且数量庞大的命令?今天这篇文章可能会帮你解开疑惑. ## 1. 目录缩写 缩写 | 全称 | ...
- Eclipse配置Tomcat,访问404错误
我从官网上面下载的tomcat6,直接启动发现正常使用,但是在Eclipse绑定后启动,访问localhost:8080,本来应该是tomcat的主页,但是却报了404错误. 百度搜索了一下,原来是t ...
- 0_Simple__simpleZeroCopy
两种方法使用零拷贝内存做简单的向量加和,并评估 GPU 计算结果与 CPU 计算结果的差. ▶ 源代码 #include <stdio.h> #include <cuda.h> ...
- bootstrapValidator针对设置赋值进行验证
bootstrapValidator在提交的时候可以进行验证,但是对于点击输入框进行赋值的时候验证失效. 解决方法: 然后在设置change方法方可解决.