Gym 100518E Embedding Caterpillars
构造+DFS
很容易的可以构造两个,最后一个不会构造的话 DFS一下就可以了
#include<iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<queue>
#include<iomanip>
#include<algorithm>
#include<map>
using namespace std; int n;
int G[][];
int flag[];
int ans[];
int TOT,FF; void dfs(int now)
{
if(now==*n+)
{
for(int i=; i<=*n; i++) printf("%d ",ans[i]);
FF=;
return;
}
if(now==)
{
for(int i=; i<=*n; i++)
{
if(!flag[i])
{
flag[i]=;
ans[now]=i;
dfs(now+);
if(FF) return;
flag[i]=;
}
}
}
else if(now>=&&now<=n+)
{
for(int i=; i<=*n; i++)
{
if(!flag[i]&&!G[i][ans[now-]])
{
flag[i]=;
ans[now]=i;
dfs(now+);
if(FF) return;
flag[i]=;
}
}
}
else if(now>=n+&&now<=*n)
{
for(int i=; i<=*n; i++)
{
if(!flag[i]&&!G[i][ans[now-n]])
{
flag[i]=;
ans[now]=i;
dfs(now+);
if(FF) return;
flag[i]=;
}
}
}
} int main( )
{
freopen("embedding.in","r",stdin);
freopen("embedding.out","w",stdout);
while(~scanf("%d",&n))
{
if(n==) break;
TOT=;
for(int i=; i<=*n; i++) ans[TOT]=i,TOT++;
TOT--;
for(int i=; i<=TOT; i++) printf("%d ",ans[i]);
printf("\n");
for(int i=; i<=n; i++) G[ans[i]][ans[i+]]=,G[ans[i+]][ans[i]]=;
for(int i=; i<=n; i++) G[ans[i]][ans[i+n]]=,G[ans[i+n]][ans[i]]=;
TOT=; ans[TOT]=; TOT++;
for(int i=n+; i<=*n; i++) ans[TOT]=i,TOT++;
ans[TOT]=n+; TOT++; ans[TOT]=n; TOT++;
for(int i=; i<=n-; i++) ans[TOT]=i,TOT++;
TOT--;
for(int i=; i<=TOT; i++) printf("%d ",ans[i]);
printf("\n");
for(int i=; i<=n; i++) G[ans[i]][ans[i+]]=,G[ans[i+]][ans[i]]=;
for(int i=; i<=n; i++) G[ans[i]][ans[i+n]]=,G[ans[i+n]][ans[i]]=;
FF=;
memset(flag,,sizeof flag);
dfs();
}
return ;
}
Gym 100518E Embedding Caterpillars的更多相关文章
- embedding mono实战笔录(一)
最近在给自己的服务器节点添加脚本功能,考虑到 执行性能.开发效率.调试效率.可维护性.严谨性 五大要素,最终选用C#作为脚本语言,并使用mono作为中间层,使其具备跨平台特性,以备具有在Windows ...
- ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS Memory Limit:65536KB 64bit IO Fo ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
- Gym 100917J---dir -C(RMQ--ST)
题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...
- Gym 101102D---Rectangles(单调栈)
题目链接 http://codeforces.com/gym/101102/problem/D problem description Given an R×C grid with each cel ...
随机推荐
- XueTr 0.45 (手工杀毒辅助工具) 绿色版
软件名称: XueTr 0.45 (手工杀毒辅助工具)软件语言: 简体中文授权方式: 免费软件运行环境: Win7 / Vista / Win2003 / WinXP 软件大小: 3.3MB图片预览: ...
- C: strcpy & memcpy & scanf/printf format specifier.. escape characters..
well, strcpy differs from memcpy in that it stops copy at \0 the format specifier is a string.. whic ...
- Centos 6.5升级到Git2.1.2的步骤
Centos 6.5升级到Git2.1.2的步骤 Centos 6.5升级到Git2.1.2其实是非常的简单,因这款版本控制程序非常的好用,所以小编自己也是使用它了,下面一起来看看Centos 6.5 ...
- 不安装oracle客户端,如何运行sqlplus
1.软件下载 http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html 下载如下三个包: oracle-instantc ...
- Ubuntu cron定时执行任务
1.添加自定义事件 crontab -e 2.选定编辑器 3.添加执行代码 * * * * /usr/bin/curl http://www.exmple.com/cron.php crontab 命 ...
- 在命令提示符下,怎么查看windows开启了哪些服务?
net use \\ip\ipc$ " " /user:" " 建立IPC空链接 net use \\ip\ipc$ "密码" /user: ...
- spark第一篇--简介,应用场景和基本原理
摘要: spark的优势:(1)图计算,迭代计算(2)交互式查询计算 spark特点:(1)分布式并行计算框架(2)内存计算,不仅数据加载到内存,中间结果也存储内存 为了满足挖掘分析与交互式实时查询的 ...
- LCA-倍增法(在线)O(nlogn)-O(logn)
1. DFS预处理出所有节点的深度和父节点 inline void dfs(int u) { int i; ;i=next[i]) { if (!deep[to[i]]) { deep[to[i]] ...
- linux 配置tomcat服务器
1. 找到tomcat安装包 find / -name apache-tomcat* 2. 解压包 tar zxvf apache-tomcat-7.0.67.tar.gz rpm -ivh j ...
- MySQL源码安装(centos)
1.去MySQL官网下载源码包 地址:http://dev.mysql.com/downloads/mysql/ 下载完后需要检查文件的MD5,以确认是否从官网下载的原版本(以防被人篡改过该软件) 使 ...