hdu4337 King Arthur's Knights
King Arthur's Knights
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1415 Accepted Submission(s): 612
Special Judge
- from Fate / Stay Night
You must have known the legend of King Arthur and his knights of the round table. The round table has no head, implying that everyone has equal status. Some knights are close friends with each other, so they prefer to sit next to each other.
Given the relationship of these knights, the King Arthur request you to find an arrangement such that, for every knight, his two adjacent knights are both his close friends. And you should note that because the knights are very united, everyone has at least half of the group as his close friends. More specifically speaking, if there are N knights in total, every knight has at least (N + 1) / 2 other knights as his close friends.
1 2
2 3
1 3
4 4
1 4
2 4
2 3
1 3
1 4 2 3
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string.h>
using namespace std;
#define MAXN 155
vector<int > vec[MAXN];
int num[155],visit[155],n,map[155];
int dfs(int node,int step)
{
int i;
// printf("%dnode ",node);
if(step==n-1)
{
if(map[node]==1)
{
printf("%d",node);
return 1;
} else
return -1;
}
for(i=0;i<vec[node].size();i++)
{
int temp=vec[node][i];
num[step]=temp;
if(visit[temp]==0)
{
visit[temp]=1;
if(dfs(vec[node][i],step+1)==1)
{
printf(" %d",node);
return 1;
}
visit[temp]=0;
} }
return -1;
}
int main()
{
int m,i,s,e;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(map,0,sizeof(map));
for(i=1;i<=n;i++)
{
vec[i].clear();
}
for(i=0;i<m;i++)
{
scanf("%d%d",&s,&e);
vec[s].push_back(e);
vec[e].push_back(s);
if(s==1)
{
map[e]=1;
}
if(e==1)
{
map[s]=1;
}
}
num[0]=1;
memset(visit,0,sizeof(visit));
visit[1]=1;
if(dfs(1,0)==-1)
{
printf("no solution\n");
continue;
} printf("\n");
} return 0;
}
hdu4337 King Arthur's Knights的更多相关文章
- hdu 4337 King Arthur's Knights (Hamilton)
King Arthur's KnightsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- POJ3682 King Arthur's Birthday Celebration
King Arthur is an narcissist who intends to spare no coins to celebrate his coming K-th birthday. Th ...
- poj-3682 King Arthur's Birthday Celebration
C - King Arthur's Birthday Celebration POJ - 3682 King Arthur is an narcissist who intends to spare ...
- HDU 4337 King Arthur's Knights 它输出一个哈密顿电路
n积分m文章无向边 它输出一个哈密顿电路 #include <cstdio> #include <cstring> #include <iostream> usin ...
- 【概率论】【POJ 3682】【King Arthur's Birthday Celebration】
题意:进行翻硬币实验,若k次向上则结束,进行第n次实验需花费2*n-1的费用,询问期望结束次数及期望结束费用 设F[i]为第i次结束时的概率 F[i]= c(i-1,k-1)*p^k*(1-p)^( ...
- King Arthur's Birthday Celebration
每天抛一个硬币,硬币正面朝上的几率是p,直到抛出k次正面为止结束,第一天抛硬币需花费1,第二天花费3,然后是5,7,9……以此类推,让我们求出抛硬币的天数的期望和花费的期望. 天数期望: A.投出了k ...
- POJ3682;King Arthur's Birthday Celebration(期望)
传送门 题意 进行翻硬币实验,若k次向上则结束,进行第n次实验需花费2*n-1的费用,询问期望结束次数及期望结束费用 分析 我们令f[i]为结束概率 \[f[i]=C_{i-1}^{k-1}*p^k* ...
- [POJ3682]King Arthur's Birthday Celebration[期望DP]
也许更好的阅读体验 \(\mathcal{Description}\) 每天抛一个硬币,硬币正面朝上的几率是p,直到抛出k次正面为止结束,第\(i\)天抛硬币的花费为\(2i-1\),求出抛硬币的天数 ...
- poj 3682 King Arthur's Birthday Celebration (期望dp)
传送门 解题思路 第一问比较简单,设$f[i]$表示扔了$i$次正面向上的硬币的期望,那么有转移方程 : $f[i]=f[i]*(1-p)+f[i-1]*p+1$,意思就是$i$次正面向上可以 ...
随机推荐
- Redis使用详细教程【转】
转自 Redis使用详细教程 - wangyuyu - 博客园http://www.cnblogs.com/wangyuyu/p/3786236.html 一.Redis基础部分: 1.redis介绍 ...
- 做php网站后台开发,在Linux系统上进行更好吗?【转载】
1. PHP是开源软件,它在bsd/linux/win下都有很好的正式版及孪生版.并非开发php就必须要在linux下进行.主机服务商们习惯性的把asp与php分为两个主机系列几进行销售.由于asp只 ...
- Linux下通过源码编译安装程序(configure/make/make install的作用,然后在/etc/profile文件里修改PATH环境变量)
一.程序的组成部分 Linux下程序大都是由以下几部分组成: 二进制文件:也就是可以运行的程序文件 库文件:就是通常我们见到的lib目录下的文件 配置文件:这个不必多说,都知道 帮助文档:通常是我们在 ...
- Python模块之pxssh
pxssh模块用于在python中ssh远程连接,执行命令,返回结果,但注意不支持Windows系统 #!/usr/bin/env python #-*- coding:utf-8 -*- from ...
- 在flask中返回requests响应
在flask服务端,有时候需要使用requests请求其他url,并将响应返回回去.查阅了flask文档,About Responses,可以直接构造响应结果进行返回. If a tuple is r ...
- Apache配置实现日志按天分割并删除指定几天前的日志
Apache日志默认情况下是一周切割一次,由于访问量大的时候日志的文件还是比较大的,同时也不利于管理员对日志的分析处理.于是尝试对Apache日志设置按天分割,并通过计划任务执行删除几天的日志. 配置 ...
- URL and Ajax Helper Methods
1.Unobtrusive Ajax
- Recursion in Java
Recursion in Java 递归无出口 public class RecursionExample1 { public static void p() { System.out.println ...
- svn代码同步脚本
碰到一个需求,主要是2个项目需要用到同一份代码,主要是域名和配置信息不一样,而且要把svn更新的代码同步过去.本来考虑提交时用钩子同步过去,但考虑到同步过去的代码还需要测试,而且另一边代码的时效性不强 ...
- 关于 Unity 的一些小细节,不注意可能会被“坑”一些时间。
关于 Unity 的一些小细节,不注意可能会被"坑"一些时间. 最近因为一些"小"问题,总是需要找很久的原因,总结一下 UnityEngine.Input 在使 ...