A. Minimum Integer

签到。

 #include <bits/stdc++.h>
using namespace std; #define ll long long
ll l, r, d; int main()
{
int t; scanf("%d", &t);
while (t--)
{
scanf("%lld%lld%lld", &l, &r, &d);
if (d < l) printf("%lld\n", d);
else printf("%lld\n", ((r / d) + ) * d);
}
return ;
}

B. Accordion

签到。

 #include <bits/stdc++.h>
using namespace std; #define N 5000010
char s[N]; int work()
{
int l = -, r = -, flag, len = strlen(s + );
flag = false;
for (int i = ; i <= len; ++i)
{
if (s[i] == '[') flag = true;
else if (s[i] == ':' && flag)
{
l = i;
break;
}
}
if (l == -) return -;
flag = false;
for (int i = len; i >= ; --i)
{
if (s[i] == ']') flag = true;
else if (s[i] == ':' && flag)
{
r = i;
break;
}
}
if (r == -) return -;
if (r <= l) return -;
int res = ;
for (int i = l + ; i < r; ++i) if (s[i] == '|')
++res;
return res;
} int main()
{
while (scanf("%s", s + ) != EOF)
printf("%d\n", work());
return ;
}

C. Division and Union

Solved.

题意:

有n个区间,将它分成两个集合,使得每个集合任意出一个区间组成的一对,这对没有交

思路:

按左端点排序,如果存在这样的划分,那么必定一个界限使得当前区间与之前的那个区间没有交,这样的话,后面的区间和之前的区间都不会有交

 #include <bits/stdc++.h>
using namespace std; #define N 100010
int t, n, ans[N];
struct node
{
int l, r, id;
void scan(int id) { scanf("%d%d", &l, &r); this->id = id; }
bool operator < (const node &other) const { return l < other.l || (l == other.l && r < other.r); }
}a[N]; int main()
{
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
for (int i = ; i <= n; ++i) a[i].scan(i);
sort(a + , a + + n);
int pos = -; int maxr = a[].r;
for (int i = ; i <= n; ++i)
{
if (a[i].l > maxr)
{
pos = i;
break;
}
maxr = max(maxr, a[i].r);
}
if (pos == -) puts("-1");
else
{
for (int i = ; i <= n; ++i) ans[a[i].id] = i < pos ? : ;
for (int i = ; i <= n; ++i) printf("%d%c", ans[i], " \n"[i == n]);
}
}
return ;
}

D. GCD Counting

Upsolved.

题意:

一棵树中,每个点有权值,找出一条最长的简单路径,使得这个路劲上所有点的点权的gcd > 1

思路:

枚举质因子,再在虚树上dp

质因子很多,有1w多个,但是我们考虑每个质因子对应的集合的总和不会太多,

因为一个数的质因子个数不会太多,2e5一下也就十几个,那么一个数的贡献也就十几个

最后的总和就是O(nlogn)级别的

其实不用建虚树,直接在dfs序上dp就可以了

 #include <bits/stdc++.h>
using namespace std; #define N 200010
int n, a[N], res;
vector <int> G[N];
vector <int> fac[N]; int fa[N], p[N], pos[N], cnt; int f[][N];
void pre(int u)
{
p[u] = ++cnt;
for (auto v : G[u]) if (v != fa[u])
{
fa[v] = u;
pre(v);
}
} void init()
{
for (int i = ; i <= n; ++i) G[i].clear();
for (int i = ; i < N; ++i) fac[i].clear();
memset(pos, -, sizeof pos);
res = ; cnt = ;
} int main()
{
while (scanf("%d", &n) != EOF)
{
init();
for (int i = ; i <= n; ++i) scanf("%d", a + i);
for (int i = , u, v; i < n; ++i)
{
scanf("%d%d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
pre();
for (int i = ; i <= n; ++i)
{
int tmp = a[i];
int limit = sqrt(tmp);
for (int j = ; j <= limit; ++j)
{
if (tmp % j == )
{
fac[j].push_back(i);
while (tmp % j == ) tmp /= j;
}
}
if (tmp != ) fac[tmp].push_back(i);
}
for (int i = ; i < N; ++i) if (fac[i].size() >= )
{
sort(fac[i].begin(), fac[i].end(), [](int x, int y) { return p[x] > p[y]; });
int len = fac[i].size();
for (int j = ; j < len; ++j) for (int o = ; o < ; ++o) f[o][j] = ;
for (int j = ; j < len; ++j) pos[fac[i][j]] = j;
for (int j = , u, v; j < len; ++j)
{
v = fac[i][j];
res = max(res, f[][j] + f[][j] + );
if (pos[fa[v]] != -)
{
int id = pos[fa[v]];
if (f[][j] + >= f[][id])
{
f[][id] = f[][id];
f[][id] = f[][j] + ;
}
else if (f[][j] + >= f[][id])
{
f[][id] = f[][j] + ;
}
}
}
for (int j = ; j < len; ++j) pos[fac[i][j]] = -;
}
printf("%d\n", res);
}
return ;
}

E. Polycarp's New Job

签到.

 #include <bits/stdc++.h>
using namespace std; #define N 500010
int n, x, y, l, r; char op[]; int main()
{
l = , r = ;
scanf("%d", &n);
while (n--)
{
scanf("%s%d%d", op, &x, &y);
if (x > y) swap(x, y);
if (op[] == '+')
{
l = max(l, x);
r = max(r, y);
}
else
{
puts(l <= x && r <= y ? "YES" : "NO");
}
}
return ;
}

F. Trucks and Cities

Upsolved.

题意:

$有n个城市,有m辆卡车需要从s_i -> f_i 每公里耗油c_i升,最多加油r_i次$

$求最小的油箱体积,使得所有卡车都能在加油次数内到达目的地$

思路:

本来考虑二分$但是复杂度是O(n \cdot m \cdot log(10^{18}))$

考虑$dp$

$dp[i][j][k] 表示从i -> j 最多加油k次的最少油箱容量$

$dp[i][j][k] = \min_{w = i}^{j} max(dp[i][w][k - 1], a[j] - a[w])$

我们发现 $dp[i][w][k - 1] 随着w递增而增加,a[j] - a[w] 随着w递增而减少$

$但是,max(dp[i][w][k - 1], a[j] -a[w]) 是先减后增的$

并且随着$j的右移动,决策点肯定只会向右移动,而不会回到左边$

 #include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 401
int n, m, a[N];
int f[N][N][N]; int main()
{
while (scanf("%d%d", &n, &m) != EOF)
{
for (int i = ; i <= n; ++i) scanf("%d", a + i);
memset(f, , sizeof f);
for (int i = ; i <= n; ++i)
for (int j = ; j <= n; ++j)
f[i][j][] = a[j] - a[i];
for (int k = ; k <= n; ++k)
for (int i = , w; i <= n; ++i)
{
w = i;
for (int j = i + ; j <= n; ++j)
{
while (w < j && max(f[i][w + ][k - ], a[j] - a[w + ]) <= max(f[i][w][k - ], a[j] - a[w])) ++w;
f[i][j][k] = max(f[i][w][k - ], a[j] - a[w]);
}
}
ll res = ;
for (int i = , s, e, c, r; i <= m; ++i)
{
scanf("%d%d%d%d", &s, &e, &c, &r);
res = max(res, 1ll * c * f[s][e][r]);
}
printf("%lld\n", res);
}
return ;
}

G. (Zero XOR Subset)-less

Upsolved.

题意:

将一些数分组,使得没有任意一个这些组的子集的异或和等于0

思路:

如果所有数异或起来等于$0$就是无解的情况

否则就是线性基中基的个数,因为每个基的最高位的$1所在位置不同$

$所以这些基不管怎么异或都不会是0$

 #include <bits/stdc++.h>
using namespace std; #define N 200010
int n, a[N], p[]; int main()
{
while (scanf("%d", &n) != EOF)
{
int t = ;
for (int i = ; i <= n; ++i) scanf("%d", a + i), t ^= a[i];
if (!t) puts("-1");
else
{
memset(p, , sizeof p);
for (int i = ; i <= n; ++i)
for (int j = ; j >= ; --j)
if ((a[i] >> j) & )
{
if (!p[j])
{
p[j] = a[i];
break;
}
else a[i] ^= p[j];
}
int res = ;
for (int i = ; i < ; ++i) if (p[i]) ++res;
printf("%d\n", res);
}
}
return ;
}

Educational Codeforces Round 58 Solution的更多相关文章

  1. Educational Codeforces Round 58 (Rated for Div. 2) 题解

    Educational Codeforces Round 58 (Rated for Div. 2)  题目总链接:https://codeforces.com/contest/1101 A. Min ...

  2. 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\),可加 ...

  3. Educational Codeforces Round 58 (Rated for Div. 2) D 树形dp + 数学

    https://codeforces.com/contest/1101/problem/D 题意 一颗n个点的树,找出一条gcd>1的最长链,输出长度 题解 容易想到从自底向长转移 因为只需要g ...

  4. Educational Codeforces Round 58 (Rated for Div. 2) G 线性基

    https://codeforces.com/contest/1101/problem/G 题意 一个有n个数字的数组a[],将区间分成尽可能多段,使得段之间的相互组合异或和不等于零 题解 根据线性基 ...

  5. Educational Codeforces Round 58 A,B,C,D,E,G

    A. Minimum Integer 链接:http://codeforces.com/contest/1101/problem/A 代码: #include<bits/stdc++.h> ...

  6. Educational Codeforces Round 58 Div. 2 自闭记

    明明多个几秒就能场上AK了.自闭. A:签到. #include<iostream> #include<cstdio> #include<cmath> #inclu ...

  7. Educational Codeforces Round 58

    D. GCD Counting 题意: 给出n个点的树,每个点有一个权值,找出一条最长的路径使得路径上所有的点的gcd>1 题解: gcd>1的一定不会有很多.所以暴力搞一下就行,不需要点 ...

  8. Educational Codeforces Round 56 Solution

    A. Dice Rolling 签到. #include <bits/stdc++.h> using namespace std; int t, n; int main() { scanf ...

  9. Educational Codeforces Round 57 Solution

    A. Find Divisible 签到. #include <bits/stdc++.h> using namespace std; int t, l, r; int main() { ...

随机推荐

  1. python2.0_day20_bbs系统开发

    BBS是一个最简单的项目.在我们把本节课程的代码手敲一遍后,算是实战项目有一个入门.首先一个项目的第一步是完成表设计,在没有完成表结构设计之前,千万不要动手开发(这是老司机的忠告!)废话不多说,现在我 ...

  2. python2.0_day18_django_admin

    Django admin的个性化定制首先我们看下,前面章节中定义的models在admin后台管理界面的样子: 然后我们看下老男孩教育点名平台的admin管理表的后台界面样子: admin管理后台常用 ...

  3. cocos2dx-3.x物理引擎Box2D介绍

    理引擎 Cocos2d-x引擎内置了两种物理引擎,它们分别是Box2D和Chipmunk,都是非常优秀的2D物理引擎,而且x引擎将它们都内置在SDK中.Box2D使用较为广泛,在这里选择Box2D来进 ...

  4. Android Intent实现页面之间跳转

    什么是IntentIntent可以理解为信使(意图)由Intent来协助完成Android各个组件之间的通讯Intent实现页面逐渐的跳转1.startActivity(inetnt)2.startA ...

  5. linux mysql添加用户,删除用户,以及用户权限

    一些主要的命令: 登录: mysql -u username -p 显示全部的数据库: show databases; 使用某一个数据库: use databasename; 显示一个数据库的全部表: ...

  6. Postgresql 创建主键并设置自动递增的三种方法

    Postgresql 有以下三种方法设置主键递增的方式,下面来看下相同点和不同点. --方法一create table test_a (  id serial,  name character var ...

  7. JS-运动基础——案例应用:淡入淡出效果

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. sencha touch 扩展篇之使用sass自定义主题样式 (上)使用官方的api修改主题样式

    大家知道,sencha touch是通过我们写的js代码来动态渲染单页面生成一个个div+css的html页面来模拟app应用,那么既然是div+css结构的,我们就可以通过修改css样式来自定义我们 ...

  9. sql语句查询条件的不同表达方式对查询性能的影响

    今天操作数据库遇到一个问题 目标表RA_AD_DAILY_DATA的数据量大概有5千万左右,其中的BUSINESS_DATE字段为日期类型 我要查询8月20号导入的三条记录,刚开始用这种方式去查: S ...

  10. SignalR实现在线聊天室功能

    一.在线聊天室 1.新建解决方案 SignalROnlineChatDemo 2.新建MVC项目 SignalROnlineChatDemo.Web (无身份验证) 3.安装SignalR PM> ...