蒟蒻语

还是蒟蒻太菜了,这场 div1 竟然一题都没做出来/kk/kk/kk

蒟蒻解

首先我们把每 5 个点分为一组。然后分组结果大概是这样子:

可以看到首先下面需要有一条边来让整张图有一条支撑的路径。然后每一组内都有 6 条边。

那么这样子的图是可行的。原因:

  1. 对于每条线路,都至少经过两个车站,满足第一个条件。
  2. 对于所有点,经过他的路径数不超过 \(3\),满足第二个条件。
  3. 对于任意两条边, 都与最下面的那条边有交点,满足第三个条件。

那么可以先将边的数量-1, 然后再按模 6 的余数分类,单独处理 (细节看代码)。


小蒟蒻太菜了,不会证明这为什么这样点数是最小的。

蒟蒻码

#include<bits/stdc++.h>
#define re register
#define L(i, j, k) for(re int i = j; i <= k; i++)
#define R(i, j, k) for(re int i = j; i >= k; i--)
#define db double
#define ll long long
using namespace std;
int n, m, tot;
void print(int x) { // 把每一个组内的点输出
L(i, 1, x) {
L(j, 1, 3) printf("2 %d %d\n", (i - 1) * 5 + 1, (i - 1) * 5 + 2 + j);
L(j, 1, 3) printf("2 %d %d\n", (i - 1) * 5 + 2, (i - 1) * 5 + 2 + j);
}
}
int main() {
scanf("%d", &n), n--; // 先在最下面放一条线
int ds = n / 6 * 5;
if(n % 6 == 0) {
printf("%d\n", ds);
printf("%d ", ds / 5 * 3);
L(i, 1, ds) if(i % 5 == 0 || i % 5 == 3 || i % 5 == 4) printf("%d ", i) // 输出这一个组内元素
puts("");
print(ds / 5);
}
else if(n % 6 == 1) {
ds -= 5; // 特别注意一下,为了让剩下的那条边有依靠,这里是把一个组再拆开来qwq
printf("%d\n", ds + 7);
printf("%d ", ds / 5 * 3 + 4);
L(i, 1, ds) if(i % 5 == 0 || i % 5 == 3 || i % 5 == 4) printf("%d ", i);
printf("%d %d %d %d\n", ds + 1, ds + 2, ds + 3, ds + 4);
print(ds / 5);
printf("2 %d %d\n", ds + 5, ds + 1); // 处理不属于那一组一组的那些边
printf("2 %d %d\n", ds + 5, ds + 2);
printf("2 %d %d\n", ds + 5, ds + 3);
printf("2 %d %d\n", ds + 6, ds + 2);
printf("2 %d %d\n", ds + 6, ds + 3);
printf("2 %d %d\n", ds + 7, ds + 1);
printf("2 %d %d\n", ds + 7, ds + 4);
} // 后面的分类讨论和上面的几乎一样
else if(n % 6 == 2) {
printf("%d\n", ds + 3);
printf("%d ", ds / 5 * 3 + 2);
L(i, 1, ds) if(i % 5 == 0 || i % 5 == 3 || i % 5 == 4) printf("%d ", i);
printf("%d %d\n", ds + 1, ds + 2);
print(ds / 5);
printf("2 %d %d\n", ds + 3, ds + 1);
printf("2 %d %d\n", ds + 3, ds + 2);
}
else if(n % 6 == 3) {
printf("%d\n", ds + 4);
printf("%d ", ds / 5 * 3 + 3);
L(i, 1, ds) if(i % 5 == 0 || i % 5 == 3 || i % 5 == 4) printf("%d ", i);
printf("%d %d %d\n", ds + 1, ds + 2, ds + 3);
print(ds / 5);
printf("2 %d %d\n", ds + 4, ds + 1);
printf("2 %d %d\n", ds + 4, ds + 2);
printf("2 %d %d\n", ds + 4, ds + 3);
}
else if(n % 6 == 4) {
printf("%d\n", ds + 4);
printf("%d ", ds / 5 * 3 + 2);
L(i, 1, ds) if(i % 5 == 0 || i % 5 == 3 || i % 5 == 4) printf("%d ", i);
printf("%d %d\n", ds + 1, ds + 2);
print(ds / 5);
printf("2 %d %d\n", ds + 3, ds + 1);
printf("2 %d %d\n", ds + 3, ds + 2);
printf("2 %d %d\n", ds + 4, ds + 1);
printf("2 %d %d\n", ds + 4, ds + 2);
}
else if(n % 6 == 5) {
printf("%d\n", ds + 5);
printf("%d ", ds / 5 * 3 + 3);
L(i, 1, ds) if(i % 5 == 0 || i % 5 == 3 || i % 5 == 4) printf("%d ", i);
printf("%d %d %d\n", ds + 1, ds + 2, ds + 3);
print(ds / 5);
printf("2 %d %d\n", ds + 4, ds + 1);
printf("2 %d %d\n", ds + 4, ds + 2);
printf("2 %d %d\n", ds + 5, ds + 1);
printf("2 %d %d\n", ds + 5, ds + 2);
printf("2 %d %d\n", ds + 5, ds + 3);
}
return 0;
}

题解 洛谷P6853 station的更多相关文章

  1. 题解 洛谷P5018【对称二叉树】(noip2018T4)

    \(noip2018\) \(T4\)题解 其实呢,我是觉得这题比\(T3\)水到不知道哪里去了 毕竟我比较菜,不大会\(dp\) 好了开始讲正事 这题其实考察的其实就是选手对D(大)F(法)S(师) ...

  2. 题解 洛谷 P3396 【哈希冲突】(根号分治)

    根号分治 前言 本题是一道讲解根号分治思想的论文题(然鹅我并没有找到论文),正 如论文中所说,根号算法--不仅是分块,根号分治利用的思想和分块像 似却又不同,某一篇洛谷日报中说过,分块算法实质上是一种 ...

  3. 题解-洛谷P5410 【模板】扩展 KMP(Z 函数)

    题面 洛谷P5410 [模板]扩展 KMP(Z 函数) 给定两个字符串 \(a,b\),要求出两个数组:\(b\) 的 \(z\) 函数数组 \(z\).\(b\) 与 \(a\) 的每一个后缀的 L ...

  4. 题解-洛谷P4229 某位歌姬的故事

    题面 洛谷P4229 某位歌姬的故事 \(T\) 组测试数据.有 \(n\) 个音节,每个音节 \(h_i\in[1,A]\),还有 \(m\) 个限制 \((l_i,r_i,g_i)\) 表示 \( ...

  5. 题解-洛谷P4724 【模板】三维凸包

    洛谷P4724 [模板]三维凸包 给出空间中 \(n\) 个点 \(p_i\),求凸包表面积. 数据范围:\(1\le n\le 2000\). 这篇题解因为是世界上最逊的人写的,所以也会有求凸包体积 ...

  6. 题解-洛谷P4859 已经没有什么好害怕的了

    洛谷P4859 已经没有什么好害怕的了 给定 \(n\) 和 \(k\),\(n\) 个糖果能量 \(a_i\) 和 \(n\) 个药片能量 \(b_i\),每个 \(a_i\) 和 \(b_i\) ...

  7. 题解-洛谷P5217 贫穷

    洛谷P5217 贫穷 给定长度为 \(n\) 的初始文本 \(s\),有 \(m\) 个如下操作: \(\texttt{I x c}\),在第 \(x\) 个字母后面插入一个 \(c\). \(\te ...

  8. 题解 洛谷 P2010 【回文日期】

    By:Soroak 洛谷博客 知识点:模拟+暴力枚举 思路:题目中有提到闰年然后很多人就认为,闰年是需要判断的其实,含有2月29号的回文串,前四位是一个闰年那么我们就可以直接进行暴力枚举 一些小细节: ...

  9. 题解 洛谷P2158 【[SDOI2008]仪仗队】

    本文搬自本人洛谷博客 题目 本文进行了一定的更新 优化了 Markdown 中 Latex 语句的运用,加强了可读性 补充了"我们仍不曾知晓得 消失的 性质5 ",加强了推导的严谨 ...

随机推荐

  1. binary hacks读数笔记(ld 链接讲解 二)

    这块将介绍一下ld链接命令的具体使用.ld的作用:ld是GNU binutils工具集中的一个,是众多Linkers(链接器)的一种.完成的功能自然也就是链接器的基本功能:把各种目标文件和库文件链接起 ...

  2. transformer多头注意力的不同框架实现(tensorflow+pytorch)

    多头注意力可以用以下一张图描述: 1.使用pytorch自带的库的实现 torch.nn.MultiheadAttention(embed_dim, num_heads, dropout=0.0, b ...

  3. 使用日志系统graylog获取Ceph集群状态

    前言 在看集群的配置文件的时候看到ceph里面有一个graylog的输出选择,目前看到的是可以收集mon日志和clog,osd单个的日志没有看到,Elasticsearch有整套的日志收集系统,可以很 ...

  4. mon的稳定性问题

    MON的稳定性问题: mon的选举风暴影响客户端IO LevelDB的暴涨 频繁的客户端请求的DDOS mon选举风暴: monmap会因为mon之间或者mon与客户端之间网络的影响或者消息传递的异常 ...

  5. hive显示列名

    查询时显示列名:hive> set hive.cli.print.header;hive.cli.print.header=falsehive> set hive.cli.print.he ...

  6. Navicat总是提示主键不存在问题

    Windows 和 Linux:打开navicat > 找到工具 > 点击选项- > 外观 > 点击数据 & 网格 > 取消勾选显示主键警告 > 确定. M ...

  7. vue中插值表达式中时间转换yyyy-MM-dd HH:mm:ss

    vue插值表达式中将时间转换两种方式:一.定义方法 <div id="app">当前实时时间:{{dateFormat(date)}}</div> //时间 ...

  8. CorelDRAW X7 X8 2017 2018是什么关系?

    从CorelDRAW 2017版本开始我们叫习惯了的X几系列的CorelDRAW毅然决然的就换了称呼,所以有时候很多朋友对于软件版本,经常会傻傻分不清,还有人认为X8版本比2017版本高,究竟为什么会 ...

  9. Linux三剑客grep、awk、sed

    何为Linux三剑客? 第一个剑客是 grep,grep 会根据正则表达式查找相关内容并打印对应的数据. 第二个剑客是 awk,awk 的名字来源于三个作者的名字简称,它可以根据定位到的数据行处理其中 ...

  10. 【mq读书笔记】客户端处理消息(回调提交到异步业务线程池,pullRequest重新入队)

    看一下客户端收到消息后的处理: MQClientAPIImpl#processPullResponse private PullResult processPullResponse( final Re ...