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 ...
随机推荐
- Mainline/Stable/Legacy
Nginx官网提供了三个类型的版本Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版Stable version:最新稳定版,生产环境上建议使用的版 ...
- arguments对象,caller 和 callee
arguments对象是比较特别的一个对象,arguments非常类似Array,但实际上又不是一个Array实例. 它指的是函数对象里的参数,且只能在函数内部使用. 使用 检测函数的参数个数,引用属 ...
- SVN ---文件加锁,执行clean up命令
一.SVN 中 clean up 的功能 当Subversion改变你的工作拷贝(或是.svn中的任何信息),它会尽可能的小心,在修改任何事情之前,它把意图写到日志文件中去,然后执行log文件中的命令 ...
- 单击Echart饼图实现数据钻取
使用场景和需求: 第一层饼图显示党员党龄分布的情况. 点击某个党龄段,查看拥有该党龄段的党支部. 默认显示3个党支部,余下的党支部合并为其它,点击其它,查看余下的党支部. 点击某个党支部,返回第一层饼 ...
- 使用HttpClient工具类测试WebService接口(soap)
import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream;import jav ...
- android 属性动画
一直再追郭霖的博客和imooc上的一些新的视频,最近有讲到属性动画. 以下内容为博客学习以及imooc上视频资料的学习笔记: 在3.0之前比较常见的动画为tween动画和frame动画: tween动 ...
- JavaScript在智能手机上的应用-使用手机GPS定位用户所在城市
---------------------------- <script type="text/javascript" language="javascript&q ...
- LeetCode OJ 160. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- 后台数据download成excel的方法(controller/action)
jsp页面端 <a href="/portal/server/importExec" title="Data Download"> <img ...
- Road to Cinema
Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard input ...