HUD-5379
Mahjong tree
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 506 Accepted Submission(s): 161
Thought for a long time, finally he decides to use the mahjong to decorate the tree.
His mahjong is strange because all of the mahjong tiles had a distinct index.(Little sun has only n mahjong tiles, and the mahjong tiles indexed from 1 to n.)
He put the mahjong tiles on the vertexs of the tree.
As is known to all, little sun is an artist. So he want to decorate the tree as beautiful as possible.
His decoration rules are as follows:
(1)Place exact one mahjong tile on each vertex.
(2)The mahjong tiles' index must be continues which are placed on the son vertexs of a vertex.
(3)The mahjong tiles' index must be continues which are placed on the vertexs of any subtrees.
Now he want to know that he can obtain how many different beautiful mahjong tree using these rules, because of the answer can be very large, you need output the answer modulo 1e9 + 7.
For each test case, the first line contains an integers n. (1 <= n <= 100000)
And the next n - 1 lines, each line contains two integers ui and vi, which describes an edge of the tree, and vertex 1 is the root of the tree.
3
9
2 1
3 1
4 3
5 3
6 2
7 4
8 7
9 3
8
2 1
3 1
4 3
5 1
6 4
7 5
8 4
1
Case #1: 32
Case #2: 16
Case #3: 1
/**
题意:给一个树,现在要求一个树的叶子结点之间的数十连续的,并且一个树的所有的
子数节点的数也是连续的
做法:搜索
如果当前节点头n个节点,如果没有非叶子的节点那么它的可能是n!
否则 如果存在一个非叶子节点 那么就是2*(n-1)! 一段区间的开始和结束
如果存在两个非叶子节点 那么就是2*(n-2)!
如果非叶子节点大于2 那么该树没有解
**/
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <vector>
using namespace std;
#define maxn 100000 + 10
const int mod = 1e9 + ;
vector<int>G[maxn];
long long res = ;
int vis[maxn];
bool flag = true;
void dfs(int u)
{
vis[u] = ;
int tt = G[u].size();
int cet = ;
for(int i = ; i < tt; i++)
{
int v = G[u][i];
if(vis[v]) {
continue;
}
if(G[v].size() == && vis[v] == ) {
cet++;
}
else if(vis[v] == ) {
dfs(v);
}
}
if(u != ) {
tt--;
}
if(tt - cet > )
{
flag = false;
return;
}
if(tt - cet > )
{
res *= ;
res %= mod;
}
while(cet > )
{
res *= cet;
res %= mod;
cet--;
}
}
int main()
{
int T;
scanf("%d", &T);
int Case = ;
while(T--)
{
int n;
scanf("%d", &n);
int u, v;
memset(vis, , sizeof(vis));
for(int i = ; i <= n; i++)
{
G[i].clear();
}
for(int i = ; i < n - ; i++)
{
scanf("%d %d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
res = ;
flag = true;
dfs();
if(n == ) {
res = ;
}
else {
res *= ;
}
if(flag == false) {
printf("Case #%d: 0\n", Case++);
}
else {
printf("Case #%d: %lld\n", Case++, res % mod);
}
}
return ;
}
HUD-5379的更多相关文章
- 如何用Unity GUI制作HUD
若知其所以然,自然知其然. HUD是指平视显示器,就是套在脸上,和你的眼睛固定在一起,HUD的意思就是界面咯,一般我们说HUD特指把3D空间中的界面的某些信息(比如血条,伤害之类)的贴在界面上,对应3 ...
- xamarin UWP平台下 HUD 自定义弹窗
在我的上一篇博客中我写了一个在xamarin的UWP平台下的自定义弹窗控件.在上篇文章中介绍了一种弹窗的写法,但在实际应用中发现了该方法的不足: 1.当弹窗出现后,我们拖动整个窗口大小的时候,弹窗的窗 ...
- xamarin UWP设置HUD加载功能
使用xamarin开发的时候经常用到加载HUD功能,就是我们常见的一个加载中的动作,Android 下使用 AndHUD , iOS 下使用 BTProgressHUD, 这两个在在 NuGet 上都 ...
- OSG中的HUD
OSG中的HUD 所谓HUD节点,说白了就是无论三维场景中的内容怎么改变,它都能在屏幕上固定位置显示的节点. 实现要点: 关闭光照,不受场景光照影响,所有内容以同一亮度显示 关闭深度测试 调整渲染顺序 ...
- CREATE A ENERGY / HEALTH BAR HUD
Now then, let's get started. 1. Open the Play scene which you had created in the previous post. If y ...
- iOS之UI--指示器HUD的创建和设置
指示器的创建和设置 渐变动画 描述: 使用label就能制作指示器,原理:就是让label以动画的形式慢慢显示和消失 最好是半透明的 指示器有时候也被称为:HUD,遮盖,蒙版 思路步骤: 1.先在st ...
- NGUI:HUD Text(头顶伤害漂浮文字)
HUD Text 很早之前就有闻于NGUI中的HUD Text插件,今天得以尝试,看了会儿官方的文档,楞是没给看明白,官方的ReadMe.txt写的使用方法如下: 官网Usage 1. Attach ...
- iOS开发必备HUD(透明指示层)
iOS开发必备HUD(透明指示层) 字数421 阅读2123 评论1 喜欢51 1.MBProgressHUD GitHub地址:https://github.com/jdg/MBProgressHU ...
- UE4编程之C++创建一个FPS工程(二)角色网格、动画、HUD、子弹类
转自:http://blog.csdn.net/u011707076/article/details/44243103 紧接上回,本篇文章将和大家一同整理总结UE4关于角色网格.动画.子弹类和HUD的 ...
- HUD 2203 亲和串
HUD 2203 亲和串 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768K (Java/Others) [题目描述 - ...
随机推荐
- BZOJ4034:[HAOI2015]树上操作——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=4034 https://www.luogu.org/problemnew/show/P3178 有一棵 ...
- [LOJ 6159] 最长树链
看到要求gcd不为1所以肯定在这条答案链上都是一个质数的倍数,所以就会产生一个很暴力的想法 没错,正解就是这样的暴力 只让走是i(素数)倍数的点,作最长链 最长链可以树形dp或两遍bfs,一遍找端点, ...
- Friendship POJ - 1815 基本建图
In modern society, each person has his own friends. Since all the people are very busy, they communi ...
- git revert HEAD
使用git reset回退公共远程分支的版本后,需要其他所有人手动用远程master分支覆盖本地master分支,显然,这不是优雅的回退方法,下面我们使用另个一个命令来回退版本: git revert ...
- LightOJ 1340 - Story of Tomisu Ghost 阶乘分解素因子
http://www.lightoj.com/volume_showproblem.php?problem=1340 题意:问n!在b进制下至少有t个后缀零,求最大的b. 思路:很容易想到一个数通过分 ...
- MyBatis框架的使用及源码分析(二) 配置篇 SqlSessionFactoryBuilder,XMLConfigBuilder
在 <MyBatis框架中Mapper映射配置的使用及原理解析(一) 配置与使用> 的demo中看到了SessionFactory的创建过程: SqlSessionFactory sess ...
- 鸡尾酒排序Cocktail sort
鸡尾酒排序基于冒泡排序,双向循环 还是看例子吧,给定待排数组[2 3 4 5 1] 第一趟过去时的每一步 第一步迭代,2 < 3不换 [2 3 4 5 1] 第二步迭代,3 < 4不换 [ ...
- 长ping域名带时间戳
ping www.baidu.com |awk '{print $0 "\t" strftime("%Y:%m:%d-%H:%M:%S",systime())} ...
- os.fork()
ret = os.fork() if ret == 0: child_suite # 子进程代码 else: parent_suite # 父进程代码 Python中的fork() 函数可以获得系统中 ...
- IConfigurationSectionHandler 接口
IConfigurationSectionHandler 处理对特定的配置节的访问. 示例代码: public class MyConfig : IConfigurationSectionHandle ...