Link

题意:给出一个图,有n个点,m条边,k个人,每个人至多只能走$\lceil\frac{2n}{k}\rceil$步,输出可行的方案即输出每个人所走的步数和所走点

思路: 由于保证给出的是连通图,且每人$\lceil\frac{2n}{k}\rceil$的步数都用完的话,显然必定有答案。那么我们不妨构造一个DFS的遍历序列(包括回溯的过程),那么最后对这个序列进行分配即可,如果图已经走完,而还有人没走,那么直接输出   即可

/** @Date    : 2017-05-10 18:06:33
* @FileName: 782E DFS.cpp
* @Platform: Windows
* @Author : Lweleth (SoundEarlf@gmail.com)
* @Link : https://github.com/Lweleth
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; int n, m, k;
vector vt[2*N];
int a[2*N];
int ans[2*N];
bool vis[N]; int cnt = 0;
void dfs(int x)
{
vis[x] = 1;
a[cnt++] = x;
int l = vt[x].size();
for(int i = 0; i < l; i++)
{
int np = vt[x][i];
if(vis[np])
continue;
dfs(np);
a[cnt++] = x;//模拟回溯
}
} int main()
{
while(cin >> n >> m >> k)
{
for(int i = 0; i < m; i++)
{
int x, y;
scanf("%d%d", &x, &y);
vt[x].PB(y);
vt[y].PB(x);
}
int ma = 2*n/k + ((2*n)%k?1:0);
MMF(vis);
cnt = 0;
dfs(1);
int cc = 0;
for(int i = 0; i < cnt; i++)
{
//cout << a[i]<<"~";
if(cc < ma)
ans[cc++] = a[i];
else
{
k--;
printf("%d ", ma);
for(int j = 0; j < cc; j++)
printf("%d%s", ans[j], j==cc-1?"\n":" ");
cc = 0;
ans[cc++] = a[i];
}
}
if(cc > 0)
printf("%d ", cc), k--;
for(int i = 0; i < cc; i++)
printf("%d%s", ans[i], i==cc-1?"\n":" ");
for(int i = 0; i < k; i++)
printf("1 1\n");
}
return 0;
}

782E. Underground Lab DFS 好题的更多相关文章

  1. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E Underground Lab

    地址:http://codeforces.com/contest/782/problem/E 题目: E. Underground Lab time limit per test 1 second m ...

  2. codeforces781C Underground Lab

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  3. CodeForces 780 E Underground Lab

    Underground Lab 题解: 如果遍历一棵树,我们可以发现最多需要走的步数也不会超过2 * n步. 所以我们选出一棵树,然后遍历一边这颗树. 然后把序列分成k块就好了. 代码: #inclu ...

  4. POJ 1321 棋盘问题(DFS板子题,简单搜索练习)

    棋盘问题 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44012   Accepted: 21375 Descriptio ...

  5. poj1564 Sum It Up dfs水题

    题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...

  6. 咸鱼的ACM之路:DFS水题集

    DFS的核心就是从一种状态出发,转向任意的一个可行状态,直到达到结束条件为止.(个人理解) 下面全是洛谷题,毕竟能找到测试点数据的OJ我就找到这一个....在其他OJ上直接各种玄学问题... P159 ...

  7. Underground Lab CodeForces - 782E (欧拉序)

    大意:$n$结点,$m$条边无向图, 有$k$个人, 每个人最多走$\left\lceil\frac {2n}{k}\right\rceil$步, 求一种方案使得$k$个人走遍所有的点 $n$结点树的 ...

  8. Oil Deposits(poj 1526 DFS入门题)

    http://poj.org/problem?id=1562                                                                       ...

  9. hdu 1045:Fire Net(DFS经典题)

    Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

随机推荐

  1. CS小分队第二阶段冲刺站立会议(5月27日)

    昨天成果:昨日有些小意外,导致没有按照原定计划工作.昨天为扫雷游戏增加了新的失败特效,只要玩家点到地雷,所有的地雷都会依次出现两帧的爆炸效果,并伴随声音. 今日计划:排除一些现有程序的bug.. 遇到 ...

  2. Eclipse的黑色主题背景(github)

    MoonRise UI Theme   An early version of a dark UI theme for Eclipse 4+. Requirements Eclipse 4.2+ In ...

  3. HDU 5655 CA Loves Stick 水题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5656 CA Loves Stick Accepts: 381   Submissions: 3204 ...

  4. Ubuntu中Google Chrome安装

    转载自博客 1. 方法一   1.在ubuntu中启动终端   2.在终端中,输入以下命令: sudo wget http://www.linuxidc.com/files/repo/google-c ...

  5. Geek荣耀大会总结

    0.0 首先没有被抽中, 其次可乐真难喝,再次我没有去拍无人机合影,再再次还是很受打击的. 1.0 其实 对geek 和1024大会无感,主要原因 没有三倍加班费的节日在我眼里都不是节日. 上面只是简 ...

  6. 【bzoj1005】[HNOI2008]明明的烦恼 Prufer序列+高精度

    题目描述 给出标号为1到N的点,以及某些点最终的度数,允许在任意两点间连线,可产生多少棵度数满足要求的树? 输入 第一行为N(0 < N < = 1000),接下来N行,第i+1行给出第i ...

  7. 苹果手机连wifi跳不出来登录网页解决办法

    1.点开要连接wifi后面的小叹号“!”,打开“自动登录” 2.打开设置,关闭SAFARI的“阻止弹窗” 3.重新连接wifi

  8. BZOJ4925 城市规划

    对每个人行道求出移动距离在哪些区间内时其在建筑物前面.现在问题即为选一个点使得其被最多的区间包含.差分即可.对建筑暴力去掉重叠部分.开始时没有去重用了nm次vector的push_back,时间大概是 ...

  9. Argus UVALive - 3135(优先队列 水题一道)

    有一系列的事件,它每Period秒钟就会产生编号为qNum的事件,你的任务是模拟出前k个事件,如果多个事件同时发生,先处理qNum小的事件 今天再看看数据结构.. #include <iostr ...

  10. 洛谷 P4240 毒瘤之神的考验 解题报告

    P4240 毒瘤之神的考验 题目背景 \(\tt{Salamander}\)的家门口是一条长长的公路. 又是一年春天将至,\(\tt{Salamander}\)发现路边长出了一排毒瘤! \(\tt{S ...