https://vjudge.net/contest/325913#overview

A.Threehouses

题意:一直二维平面上的$n$个点中,前$e$个点落在小岛周围,并且有$p$条边已经连接,问最少花费使得所有点都可以通过一些边到达小岛,两点之间建边的花费为两点间的欧式距离。

思路:根据$kruskal$求最小生成树的方法将前$e$个点合并起来,再将已有$p$条边的两点合并,之后做一次$kruskal$把所有点合并即可。

#include<bits/stdc++.h>

using namespace std;
const int maxn = 1000 + 10; int fa[maxn];
double x[maxn], y[maxn], dist[maxn][maxn];
int tot;
struct node {
int u, v;
double val;
bool operator < (const node &rhs) const {
return val < rhs.val;
}
}edge[maxn * maxn]; int fr(int x) {
if(fa[x] == x) return x;
return fa[x] = fr(fa[x]);
}
void uni(int x, int y) {
x = fr(x), y = fr(y);
if(x != y) fa[x] = y;
}
void init(int n) {
tot = 0;
for(int i = 0; i <= n; i++) {
fa[i] = i;
}
}
double cal(int i, int j) {
double ret = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
return ret;
}
int main() {
int n, e, p;
scanf("%d%d%d", &n, &e, &p);
init(n + 1);
for(int i = 1; i <= n; i++) {
scanf("%lf%lf", &x[i], &y[i]);
}
for(int i = 1; i <= n; i++) {
for(int j = i + 1; j <= n; j++) {
dist[i][j] = dist[j][i] = cal(i, j);
node now;
now.u = i, now.v = j, now.val = dist[i][j];
edge[tot++] = now;
}
}
sort(edge, edge + tot);
for(int i = 1; i <= e; i++) {
uni(0, i);
}
double ans = 0.0;
for(int i = 0; i < p; i++) {
int u, v;
scanf("%d%d", &u, &v);
uni(u, v);
}
for(int i = 0; i < tot; i++) {
node now = edge[i];
int fu = fr(now.u), fv = fr(now.v);
if(fu != fv) {
ans += now.val;
fa[fu] = fv;
}
}
printf("%.6f\n", ans);
return 0;
}

C.Cops ans Robbers

题意:给定图中只有字母点可以设立障碍,问让小偷所在的位置$B$无法达到边界所需设立障碍的最小花费。

思路:先说做法。考虑最小割,对每个点拆点,让$u$到$u^{'}$的流量为该点对应的值,如果该点不能设立障碍则为$inf$,然后对一个点$u$的相邻点连一条$u^{'}$到$v$流量为$inf$的边,如果越界那么就连向汇点$T$,流量依旧为$inf$。这样做使得每个格点所在的路径流向$T$的最小割只会被其上的价值最小的点所限制,由于建图时所有相邻格点都有连边,所以从源点出发时不会漏边。

#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
const int N = 1000 + 5;
const int inf = 0x3f3f3f3f;
const LL linf = 0x3f3f3f3f3f3f3f3f; int n, m, c, T;
LL val[26];
char mp[N][N];
struct Dinic {
static const int maxn = 1e6 + 5;
static const int maxm = 4e6 + 5; struct Edge {
int u, v, next;
LL flow, cap;
} edge[maxm]; int head[maxn], level[maxn], cur[maxn], eg; void addedge(int u, int v, LL cap) {
edge[eg] = {u, v, head[u], 0, cap}, head[u] = eg++;
edge[eg] = {v, u, head[v], 0, 0}, head[v] = eg++;
} void init() {
eg = 0;
memset(head, -1, sizeof head);
} bool makeLevel(int s, int t, int n) {
for(int i = 0; i < n; i++) level[i] = 0, cur[i] = head[i];
queue<int> q; q.push(s);
level[s] = 1;
while(!q.empty()) {
int u = q.front();
q.pop();
for(int i = head[u]; ~i; i = edge[i].next) {
Edge &e = edge[i];
if(e.flow < e.cap && level[e.v] == 0) {
level[e.v] = level[u] + 1;
if(e.v == t) return 1;
q.push(e.v);
}
}
}
return 0;
} LL findpath(int s, int t, LL limit = linf) {
if(s == t || limit == 0) return limit;
for(int i = cur[s]; ~i; i = edge[i].next) {
cur[edge[i].u] = i;
Edge &e = edge[i], &rev = edge[i^1];
if(e.flow < e.cap && level[e.v] == level[s] + 1) {
LL flow = findpath(e.v, t, min(limit, e.cap - e.flow));
if(flow > 0) {
e.flow += flow;
rev.flow -= flow;
return flow;
}
}
}
return 0;
} LL max_flow(int s, int t, int n) {
LL res = 0;
while(makeLevel(s, t, n)) {
LL flow;
while((flow = findpath(s, t)) > 0) {
if(res >= linf) return res;
res += flow;
}
}
return res;
}
} di; int id(int r, int c) {
if(r < 1 || r > n || c < 1 || c > m) return T;
return (r - 1) * m + c;
} LL getVal(int r, int c) {
if(r < 1 || r > n || c < 1 || c > m) return linf;
if(mp[r][c] == '.' || mp[r][c] == 'B') return linf;
else return val[mp[r][c] - 'a'];
} int main() {
scanf("%d%d%d", &m, &n, &c);
for(int i = 1; i <= n; i++) scanf("%s", mp[i] + 1);
for(int i = 0; i < c; i++) scanf("%lld", &val[i]);
T = 2*n*m + 5;
di.init();
di.addedge(id(1, 1) + n*m, T, linf);
di.addedge(id(1, m) + n*m, T, linf);
di.addedge(id(n, 1) + n*m, T, linf);
di.addedge(id(n, m) + n*m, T, linf);
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
di.addedge(id(i, j), id(i, j) + n*m, getVal(i, j));
if((i == 1 || i == n) && (j == 1 || j == m)) continue;
di.addedge(id(i, j) + n*m, id(i+1, j), linf);
di.addedge(id(i, j) + n*m, id(i-1, j), linf);
di.addedge(id(i, j) + n*m, id(i, j+1), linf);
di.addedge(id(i, j) + n*m, id(i, j-1), linf);
}
}
LL ans = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(mp[i][j] == 'B') {
ans = di.max_flow(id(i, j), T, T+10);
}
if(ans) break;
}
if(ans) break;
}
printf("%lld\n", ans >= linf ? -1 : ans);
return 0;
}
/*
10 10 1
..........
..........
..........
...a.a....
..a.a.a...
.a..B.a...
..aaaaa...
..........
..........
..........
1
*/

E.Coprime Integers

题意:给定$a,b,c,d$,求$\sum_{i=a}^{b}\sum_{j=c}^{d}[gcd(i,j)=1]$,$[t=1]$表示$t$等于$1$时的值为$1$,否则为$0$。

思路:容斥原理+莫比乌斯反演,考虑$solve(n,m)=\sum_{i=1}^{n}\sum_{j=1}^{m}[gcd(i,j)=1]$,可以发现$ans=solve(b,d)-solve(a-1,d)-solve(c-1,b)+solve(a-1,c-1)$。接着考虑如何计算$solve(n,m)$

$\sum_{i=1}^{n}\sum_{j=1}^{m}[gcd(i,j)=1]$

$=\sum_{i=1}^{n}\sum_{j=1}^{m}\sum_{t|i,t|j}u(t)$

$=\sum_{t=1}^{min(n,m)}u(t)\sum_{i=1}^{\left \lfloor \frac{n}{t} \right \rfloor}\sum_{j=1}^{\left \lfloor \frac{m}{t} \right \rfloor}1$

$=\sum_{t=1}^{min(n,m)}u(t)\left \lfloor \frac{n}{t} \right \rfloor\left \lfloor \frac{m}{t} \right \rfloor$

预处理莫比乌斯函数前缀和之后整除分块即可在$O(\sqrt n)$复杂度内求出一次$solve$。

#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
const int N = 1e7 + 5; int p[N / 10], cnt, mu[N];
bool tag[N]; void getPrime() {
mu[1] = 1;
for(int i = 2; i < N; i++) {
if(!tag[i]) {
mu[i] = -1;
p[cnt++] = i;
}
for(int j = 0; j < cnt && 1LL * p[j] * i < N; j++) {
tag[i * p[j]] = 1;
if(i % p[j] == 0) {
mu[i * p[j]] = 0;
break;
}
mu[i * p[j]] = -mu[i];
}
}
for(int i = 1; i < N; i++) mu[i] += mu[i - 1];
} LL solve(LL n, LL m) {
LL res = 0;
for(LL l = 1, r; l <= min(n, m); l = r + 1) {
r = min(n / (n / l), m / (m / l));
res += (mu[r] - mu[l - 1]) * (n / l) * (m / l);
}
return res;
} int main() {
getPrime();
LL a, b, c, d;
scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
printf("%lld\n", solve(b, d) - solve(a - 1, d) - solve(c - 1, b) + solve(a - 1, c - 1));
return 0;
}

H.Heir's Dilemma

题意:求$L$到$H$之间满足位数是$6$位,且没有某一位是$0$,且能被每一位的数字整除的数的个数。

思路:数据范围很小,暴力枚举每个数$check$是否可行即可。

#include <bits/stdc++.h>

using namespace std;

bool ck(int x) {
bool vis[10];
for(int i = 0; i < 10; i++) vis[i] = false;
int xx = x, xxx = x, xxxx = x;
while(xxx) {
if(xxx % 10 == 0) return false;
xxx /= 10;
}
while(xxxx) {
if(vis[xxxx % 10] == true) return false;
vis[xxxx % 10] = true;
xxxx /= 10;
}
while(xx) {
int now = xx % 10;
if(x % now != 0) return false;
xx /= 10;
}
return true;
} int main() {
int cnt = 0, a, b;
cin >> a >> b;
for(int i = a; i <= b; i++) cnt += (int)ck(i);
cout << cnt << endl;
}

ComWin’ round 11部分题解的更多相关文章

  1. Codeforces Global Round 11 个人题解(B题)

    Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...

  2. BestCoder Round #11 (Div. 2) 题解

    HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  3. BestCoder Round #11 (Div. 2) 前三题题解

    题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob ...

  4. int和integer;Math.round(11.5)和Math.round(-11.5)

    int是java提供的8种原始数据类型之一.Java为每个原始类型提供了封装类,Integer是java为int提供的封装类.int的默认值为0,而Integer的默认值为null,即Integer可 ...

  5. Math.round(11.5)等于()Math.round(-11.5)等于()

    几天前去面试,这道简单的题目居然做错了,看来基础就是慢慢积累的.并不断使用和复习才会成为高手,假设基础不是那么熟练.恐怕在成为高手的路上会困难重重.所以在做项目的间歇时间.偶尔回顾一下最基础的知识.是 ...

  6. Math.round(11.5)等于多少? Math.round(-11.5)等于多少?

    1.先说下怎么理解 round()方法可以这样理解: 将括号内的数+0.5之后,向下取值, 比如:round(3.4)就是3.4+0.5=3.9,向下取值是3,所以round(3.4)=3; roun ...

  7. Codeforces Round #543 Div1题解(并不全)

    Codeforces Round #543 Div1题解 Codeforces A. Diana and Liana 给定一个长度为\(m\)的序列,你可以从中删去不超过\(m-n*k\)个元素,剩下 ...

  8. Codeforces Round #545 Div1 题解

    Codeforces Round #545 Div1 题解 来写题解啦QwQ 本来想上红的,结果没做出D.... A. Skyscrapers CF1137A 题意 给定一个\(n*m\)的网格,每个 ...

  9. Codeforces Round #539 Div1 题解

    Codeforces Round #539 Div1 题解 听说这场很适合上分QwQ 然而太晚了QaQ A. Sasha and a Bit of Relax 翻译 有一个长度为\(n\)的数组,问有 ...

  10. 【Java面试题】59 Math.round(11.5)等於多少? Math.round(-11.5)等於多少?

    Math类中提供了三个与取整有关的方法:ceil.floor.round,这些方法的作用与它们的英文名称的含义相对应,例如,ceil的英文意义是天花板,该方法就表示向上取整,Math.ceil(11. ...

随机推荐

  1. [R语言] 基于R语言实现环状条形图的绘制

    环状条形图(Circular barplot)是条形图的变体,图如其名,环状条形图在视觉上很吸引人,但也必须小心使用,因为环状条形图使用的是极坐标系而不是笛卡尔坐标系,每一个类别不共享相同的Y轴.环状 ...

  2. 华为云Stack新版发布:构筑行业云底座,共创行业新价值

    摘要:在以"政企深度用云,释放数字生产力"为主题的华为云Stack战略暨新品发布会上,华为云提出深度用云三大关键举措,并发布华为云Stack 8.2版本,以智能进化推动创造行业新价 ...

  3. Matplotlib 绘制折线图

    Matplotlib matplotlib: 最流行的Python底层绘图库,主要做数据可视化图表,名字取材于MATLAB,模仿MATLAB构建 绘制折线图 绘制两小时的温度变化 from matpl ...

  4. 过年必备!亲戚计算器「GitHub 热点速览 v.23.02」

    过完这周大家就要开始为期 7 天的春节长假了,当然有些 HG 小伙伴拥有了 10+ 天的长假就低调点不要告诉他人,以免招人妒忌.春节必经的事情可能就是走亲戚了,所以本周特推选取了一个研究亲戚关系的资深 ...

  5. day03-Spring管理Bean-IOC-01

    Spring管理Bean-IOC 1.Spring配置/管理bean介绍 Bean管理包括两方面: 创建bean对象 给bean注入属性 Bean的配置方式: 基于xml文件配置方式 基于注解配置方式 ...

  6. 刷题笔记——3003.鸡兔同笼问题 & 2767.计算多项式的值

    题目1 3003.鸡兔同笼问题 代码 while True: try: x,y=map(int,input().strip().split()) a = int((4*x-y) / 2) b = x ...

  7. vulnhub靶场之FUNBOX: GAOKAO

    准备: 攻击机:虚拟机kali.本机win10. 靶机:Funbox: GaoKao,下载地址:https://download.vulnhub.com/funbox/FunboxGaoKao.ova ...

  8. 记OPNsense防火墙的安装过程 - 安全

    前些天在网上看到防火墙软件OPNsense,对其有了兴趣,以前写过一个其前面的一个软件M0n0wall( 关于m0n0wall的安装及配置 ),当时也是非常有名的防火墙,现在有了OPNsense,这个 ...

  9. CSS中的各种格式化上下文-FC(BFC)、IFC、GFC、FFC)

    什么是FC? FC是Formatting Context的缩写,中文名:格式化上下文.是 W3C在CSS2.1 规范中的一个概念. FC是指页面中一篇渲染区域,渲染区域内使用的格式化上下文的渲染规则, ...

  10. 【学习笔记】XR872 Audio 驱动框架分析

    Xradio Sdk 的 Audio 驱动框架和 Linux 的 ASOC 驱动框架非常相似,只不过简化了很多. 驱动和芯片之间的关系图 下面的 SOC 表示的是 XR872 芯片,这里以 AC107 ...