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 ...
随机推荐
- SpringMVC集成shrio框架
使用SHIRO的步骤:1,导入jar2,配置web.xml3,建立dbRelm4,在Spring中配置 添加所需jar包: <!--Apache Shiro所需的jar包--> <d ...
- 关于 HIVE Beeline 问题
1 启动 hiveserver2 服务,启动 beeline -u jdbc:hive2:// 正常 ,启动 beeline -u jdbc:hive2://127.0.0.1:10000 包如下错 ...
- Eclipse没有提示了,按Alt+/ 也无代码提示
1.菜单window->Preferences->Java->Editor->Content Assist->Enable auto activation 选项要打上勾 ...
- CSS的基本概念
<!--CSS 一.概念:CSS的全称是Cascading Style Sheets,层叠样式表,用来控制HTML标签样式,在美化网页中起到非常重要的作用 CSS的编写格式是键值对形式的,比如 ...
- CF/div2c/贪心
题目链接[http://codeforces.com/contest/749/problem/C] 题意:给出一个长度为n序列包含D和R,每一轮操作的先后顺序是1-n,规则是每一轮每个人有一次机会杀掉 ...
- sfs - django start from scratch
[TOC] Launch with code git spreading is obsolte lwc Installation Path D:\PythonWebSW\Django-1.5.5 ad ...
- thinkphp 实现微信公众号开发(二)--实现自定义菜单
IndexController.class.php <?php namespace Home\Controller; use Think\Controller; class IndexContr ...
- mybatis 总结(1)
注意事项 1.在使用type 和JavaType 以及reusltType ,ofType的时候一定要设置"别名"在mybatis.cfg.xml中设置 <typeAlias ...
- hdu_5683_zxa and xor(非正解的暴力)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5683 题意: 问题描述 zxa最近对按位异或(exclusive disjunction)产生了极大的 ...
- CCF考试真题题解
CCF考试认证:题解参考博客http://blog.csdn.net/u014578266/article/details/45221841 问题描述 试题编号: - 试题名称: 图像旋转 时间限制: ...