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. swift开发之--UISearchBar的使用/UISearchController的使用

    记录下UISearchBar的基本用法,补充:ios 8.0以后,原来的UISearchDisplayController被官方废弃,建议使用UISearchController,下面就简单的记录下这 ...

  2. Linux netstat 命令

    1. netstat命令用于显示系统的网络信息,包括网络连接 .路由表 .接口状态2. 一般我们使用 netstat 来查看本机开启了哪些端口,查看有哪些客户端连接 常见用法如下: [root@loc ...

  3. Python 流程控制:for

    for 循环用于对一个序列进行遍历,用法如下: In [4]: for i in 'abcd': ...: print(i) ...: a b c d In [13]: for i in range( ...

  4. Maven 环境变量设置

    下载Maven 官方下载地址:http://maven.apache.org/download.html 选择你所希望下载的版本,并保存到常用安装目录.这里以Maven 3.2.2 (Binary z ...

  5. 【ecshop】使用sql 清除测试数据

    操作方式:后台->数据库->sql查询   输入以下你想进行的操作 -- -- 清空会员有关数据: -- TRUNCATE TABLE `ecs_users` ; TRUNCATE TAB ...

  6. 网络虚拟化技术(一): Linux网络虚拟化

    创建虚拟网络环境 使用命令 $ ip netns add net0 可以创建一个完全隔离的新网络环境,这个环境包括一个独立的网卡空间,路由表,ARP表,ip地址表,iptables,ebtables, ...

  7. 【BZOJ1713】[Usaco2007 China]The Bovine Accordion and Banjo Orchestra 音乐会 斜率优化

    [BZOJ1713][Usaco2007 China]The Bovine Accordion and Banjo Orchestra 音乐会 Description Input 第1行输入N,之后N ...

  8. 求全局最小割(SW算法)

    hdu3002 King of Destruction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

  9. 'Settings' object has no attribute 'TEMPLATE_DEBUG' 的解决方法

    找到该Django项目下的settings文件,把 DEBUG = True 改为 DEBUG = False 就可以正常浏览显示了 参考:https://stackoverflow.com/ques ...

  10. SQL Server经典函数之数字去零

    需求: 针对带有小数点的数字信息,去除小数点后多余的零 可能存在的情况: 1.精度范围内,出现多余的零    eg:1234.3400     想要的结果为1234.34 2.精度变大出现的多余的零, ...