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 ...
随机推荐
- 使用Idea作为go的IDE
Idea是一款非常不错的IDE,只可惜是收费的.Idea可以使用很多的插件,当然里面就包含我们需要的go语言的插件. 1.我们打开file -> Settings -> Plugins - ...
- Smarty自定义函数
自定义函数:<{方法名称}> 在html页面是可以直接赋值的:(没啥作用只是知道即可) <{$a = "hello"}><div><{$a ...
- E: GPG error: http://mirrors.oschina.net trusty-backports InRelease: Clearsigned file isn't valid, got 'NODATA' (does the network require authentication?)
E: GPG error: http://mirrors.oschina.net trusty-backports InRelease: Clearsigned file isn't valid, g ...
- BJFU 1440 fudq的ACM
矩阵快速幂 #include<cstdio> #include<algorithm> using namespace std; ; const int INF =1e9; ; ...
- Robot Framework开发系统关键字详细
本文的目的,是记录如何在rf下,开发属于自己的库函数(又称之系统关键字) 1.首先在..\Python27\Lib\site-packages目录下创建自定义库目录如Verification_Libr ...
- 解决ORA-00904: invalid identifier标识符无效
方法/步骤 1 大部分情况下,此错误是由于引用了不存在的列名导致的.比如select name from Studtent 当studeng表中无name列时,系统就会报此错误. 2 解决思路是,确定 ...
- SB淘宝api的奇葩问题! 一则服务器无法访问淘宝api
<?xml version="1.0" encoding="utf-8" ?><error_response><code>3 ...
- oracle的exp和imp命令的使用【转载】
oracle的exp和imp命令的使用 我们通常要对ORACLE的数据进行导入,导出,在没有expdb,impdb以前(10G以前),我们都是使用exp 导出,imp命令来实现导入. 打开 ...
- NET:交换机的背板带宽,交换容量,包转发率区别
交换机的背板带宽,交换容量,包转发率区别 背板带宽指的是背板整个的交换容量,交换容量指cpu的交换容量,包转发指的是三层转发的容量 一.背板带宽 1.交换机背板带宽含义 交换机的背板带宽也叫背板容量, ...
- s7-300 第二讲