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. YQCB项目介绍

    YQCB记账本软件 制作人:YQCB团队 团队简介:团队成立于2017年11月21日,由陈美琪,张晨阳,邢全阳,刘昭为四人组成. 陈美琪:团队灵魂人物,背负着巨大的压力带起整个团队. 张晨阳:团队领军 ...

  2. c# 消息机制

    1.windows系统是一个消息驱动的系统,windows本身有自己的消息队列. 系统传递消息给应用程序. 应用程序的消息机制:应用程序的执行是通过消息驱动的.消息是整个应用程序的工作引擎. 2.c# ...

  3. ASP.NET MVC5 学习系列之模型绑定

    一.理解 Model Binding Model Binding(模型绑定) 是 HTTP 请求和 Action 方法之间的桥梁,它根据 Action 方法中的 Model 类型创建 .NET 对象, ...

  4. vue+vue-video-player实现弹窗播放视频

    将视频播放器标签放在对话框标签中,实现弹窗 template 中 <el-dialog :visible.sync="dialogVisible" width='680px' ...

  5. Hadoop HDFS环境搭建

    1,首先安装JDK,下面如果JDK出现安装错误,可以卸载 卸载 1.卸载用 bin文件安装的JDK方法: 删除/usr/java目录下的所有东西 2.卸载系统自带的jdk版本方法: 查看自带的jdk: ...

  6. 第84天:jQuery动态创建表格

    jQuery动态创建表格 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...

  7. FZU2121_神庙逃亡

    水题.直接解二次方程判断点的高度即可. #include <iostream> #include <cstring> #include <cstdio> #incl ...

  8. Android四大组件之Service(续2)

    1.HttpRequest package com.joyfulmath.android4example.http; import java.io.BufferedReader; import jav ...

  9. c# 字符串转Byte[],如何将Byte[]插入到Oracle Blob

    byte[] xx=Encoding.Default.GetBytes("12121232"); 插入数据库 string sqlStr = "update sys_ta ...

  10. 【hdu6072】Logical Chain

    Kosaraju算法,然後bitset優化 主要是學習一下自寫bitset的姿勢 #include<cstring> #include<algorithm> #include& ...