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$次正面向上可以 ...
随机推荐
- ansible 下lineinfile详细使用 【转】
转自 ansible 下lineinfile详细使用 - 散人 - 51CTO技术博客http://zouqingyun.blog.51cto.com/782246/1882367 一.简述 这几天在 ...
- sqlalchemy更新和插入操作
def save_app_info(self): try: # update app_info print(self.dicts) data = db_session.query(App_Info). ...
- 微信小程序开发定制
上海软件定制专家:http://www.dzonly.com/?from=timeline
- 发布PHP项目(nginx+PHP7+mysql 5.6)
一.环境检查 1.检查nginx ps -ef | grep "nginx" 显示如下内容则代表nginx启动正常 root 3285 1 0 12:57 ? 00:00:00 n ...
- 结构体对齐及#pragma详细解释
在linux下c语言结构体对齐: 1.自然对齐 struct 是一种复合数据类型,其构成元素既可以是基本数据类型(如int.long.float 等)的变量,也可以是一些复合数据类型(如array.s ...
- python基础(7)--深浅拷贝、函数
1.深浅拷贝 在Python中将一个变量的值传递给另外一个变量通常有三种:赋值.浅拷贝.深拷贝 Python数据类型可氛围基本数据类型包括整型.字符串.布尔及None等,还有一种由基本数据类型作为最基 ...
- 前端代码编辑器ace 语法提示 代码提示
本文主要是介绍ace编辑器的语法提示,自动完成.其实没什么可特别介绍的,有始有终吧,把项目中使用到的ace的功能都介绍下. { enableBasicAutocompletion: false, // ...
- Hadoop(四)HDFS的高级API操作
一 HDFS客户端环境准备 1.1 jar包准备 1)解压hadoop-2.7.6.tar.gz到非中文目录 2)进入share文件夹,查找所有jar包,并把jar包拷贝到_lib文件夹下 3)在全部 ...
- Deepin 2015 安装后找不到win10 启动选项的解决办法
#sudo vi /boot/grub/grub.cfg 在export linux_gfx_mode后面加 menuentry "Windows 10 (loader)" --c ...
- SaltStack配置管理--状态间的关系(六)
一.include的引用 需求场景:用于含有多个SLS的状态,使用include可以进行多个状态的组合,将安装apache,php,mysql集合在一个sls中 [root@7mini-node1 p ...