构造+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的更多相关文章

  1. embedding mono实战笔录(一)

    最近在给自己的服务器节点添加脚本功能,考虑到 执行性能.开发效率.调试效率.可维护性.严谨性 五大要素,最终选用C#作为脚本语言,并使用mono作为中间层,使其具备跨平台特性,以备具有在Windows ...

  2. 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 ...

  3. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  4. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  5. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  6. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  7. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  8. Gym 100917J---dir -C(RMQ--ST)

    题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...

  9. Gym 101102D---Rectangles(单调栈)

    题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cel ...

随机推荐

  1. 关于UIFont和计算字符串的高度和宽度

    转自:http://i.cnblogs.com/EditPosts.aspx?opt=1 1.创建方法:+ fontWithName:size:- fontWithSize:2.创建系统字体:+ sy ...

  2. netsh命令之ip设置

    批处理.VBS实现自动设置IP.默认网关.DNS.WINS.IE代理的代码,需要的朋友可以参考下 因为公司有同事负责大连.沈阳两个城市,经常在两地来回走动,到每个城市后,都要自己手动更改相应的网络配置 ...

  3. gridControl 中CellValueChanged,ShowingEditor,CustomDrawCell的用法

    private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventA ...

  4. sql 判断表是否存在,判断列是否存在

    判断表是否存在: 语法: SELECT * FROM dbo.SysObjects where id = object_id(N'表名') 例子: SELECT * FROM dbo.SysObjec ...

  5. ZOJ 2158 POJ 1789 Truck History

    最小生成树,主要是题目比较难懂. #include <cstdio> #include <cstring> #include <cmath> #include &l ...

  6. java操作cookies

    建立一个无生命周期的cookie,即随着浏览器的关闭即消失的cookie,代码如下 HttpServletRequest request HttpServletResponse response Co ...

  7. 笔记整理--Linux多线程

    Unix高级环境编程系列笔记 (2013/11/17 14:26:38) Unix高级环境编程系列笔记 出处信息 通过这篇文字,您将能够解答如下问题: 如何来标识一个线程? 如何创建一个新线程? 如何 ...

  8. c语言-转义序列

    字符组合是由反斜杠 (\) 后接字母或位组合构成的字符组合.若要显示换行符,单引号或某些其他字符在字符串末尾,必须使用转义序列. 转义序列被视为单个字符,因此,它是有效的字符常数. 转义序列通常用于指 ...

  9. VBS基础篇 - 对象(6) - Folder对象

    VBS基础篇 - 对象(6) - Folder对象   描述:提供对文件所有属性的访问,从FSO对象的GetFile方法获得 使用Folder对象 要用Folder对象模型来编程必须先用FSO对象的G ...

  10. java 多线程 一个博客

    http://blog.csdn.net/a352193394/article/category/2563875 Java多线程之~~~线程安全容器的非阻塞容器 在并发编程中,会经常遇到使用容器.但是 ...