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. 关于直播学习笔记-004-nginx-rtmp、srs、vlc、obs

    1.采集端:OBS RTMP推流地址:rtmp://192.168.198.21:1935/live 流密钥:livestream(任意-但播放地址与此一致) 2.播放端:nginx-rtmp-win ...

  2. apache+php生产环境错误记录

    报错1: [18-Jul-2016 14:36:31 Asia/Shanghai] PHP Warning:  DOMDocument::load(): I/O warning : failed to ...

  3. Apache Prefork、Worker和Event三種MPM分析

    三種MPM介紹 Apache 2.X  支持插入式並行處理模塊,稱爲多路處理模塊(MPM).在編譯apache時必須選擇也只能選擇一個MPM,對類UNIX系統,有幾個不同的MPM可供選擇,它們會影響到 ...

  4. Unity官网针对IOS开发有比较好的建议

    Unity官网针对IOS开发有比较好的建议,我总结了翻译如下,后面附上原文. 尽量控制定点数量(注意所谓顶点不是建模时的顶点,而是引擎渲染时的顶点.例如,模型一个顶点如果设置了2个法向,那么对引擎来说 ...

  5. NGUI在5.3打包失败问题

    一.NGUI版本 NGUI是很好用的Unity UI插件. 当前使用版本NGUI Next-Gen UI v3.9.7 (Feb 10, 2016)和NGUI Next-Gen UI 3.9.0两个版 ...

  6. Effective C++ —— 设计与声明(四)

    条款18 : 让接口容易被正确使用,不易被误用 欲开发一个“容易被正确使用,不容易被误用”的接口,首先必须考虑客户可能做出什么样的错误操作.  1. 明智而审慎地导入新类型对预防“接口被误用”有神奇疗 ...

  7. Java编程基本概念

    1.标识符 ①用于给变量.类和方法命名(类名首字母大写,变量和方法名首字母小写并遵循驼峰原则)②标识符的命名规范: ■标识符必须以字母.下划线和美元符$开头. ■标识符其他部分可以是字母.下划线.美元 ...

  8. 【PHP】 判断是否微信内置浏览器

    PHP 判断是手机端还是PC端 function isMobile() { // 如果有HTTP_X_WAP_PROFILE则一定是移动设备 if (isset($_SERVER['HTTP_X_WA ...

  9. 简明 Vim 教程

    学习 vim 并且其会成为你最后一个使用的文本编辑器.没有比这个更好的文本编辑器了,非常地难学,但是却不可思议地好用. 我建议下面这四个步骤: 存活 感觉良好 觉得更好,更强,更快 使用VIM的超能力 ...

  10. mysql in查询排序问题

    SQL: select * from table where id IN (3,6,9,1,2,5,8,7); 这样的情况取出来后,其实,id还是按1,2,3,4,5,6,7,8,9,排序的,但如果我 ...