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) [题目描述 - ...
随机推荐
- 数组分组chunk的一种写法
lodash的_.chunk函数可以将数组按照数量分成若干组, 例如: const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; const groupByN ...
- 使用snmp4j实现Snmp功能(二)
相关链接:Snmp学习笔记使用snmp4j实现Snmp功能(一)使用snmp4j实现Snmp功能(二)使用snmp4j实现Snmp功能(三) 前一篇文章讲了如何用snmp4j实现set和get的功能, ...
- 覆盖的面积 HDU - 1255 (线段树-扫描线)模板提
给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. Input输入数据的第一行是一个正整数T(1<=T<=100),代表测试数据的数量.每个测试数据的第一行是一个正整数N(1& ...
- 【转载】Innodb共享表空间VS独立表空间
http://www.mysqlsupport.cn/innodb%E5%85%B1%E4%BA%AB%E8%A1%A8%E7%A9%BA%E9%97%B4vs%E7%8B%AC%E7%AB%8B%E ...
- 深入探索C++对象模型(一)
再读<深入探索C++对象模型>笔记. 关于对象 C++在加入封装后(只含有数据成员和普通成员函数)的布局成本增加了多少? 答案是并没有增加布局成本.就像C struct一样,memeber ...
- centos设置tomcat开机启动
1.编辑开机启动脚本 vi /etc/init.d/tomcat8 #!/bin/bash # tomcat8:start|stop|restart # chkconfig: 345 90 10 # ...
- PowerDesigner16连接mysql5.6逆向生成PDM
一:首先安装ODBC驱动 https://dev.mysql.com/downloads/connector/odbc/ ,安装32位驱动 二:然后配置好ODBC数据源,控制面板\系统和安全\管理 ...
- idea出现:error:java: Target level '1.7' is incompatible with source level '1.8'.解决办法
当我们开始使用idea的时候,编译jsp程序我们有可能出现编译错误,然而我们的代码又没有什么问题. 解决方法一:我们开始的时候可以通过修改java compiler来解决这样的问题,点击file菜单- ...
- 通过.NET客户端异步调用Web API(C#)
在学习Web API的基础课程 Calling a Web API From a .NET Client (C#) 中,作者介绍了如何客户端调用WEB API,并给了示例代码. 但是,那些代码并不是非 ...
- 「6月雅礼集训 2017 Day5」吃干饭
[题目大意] 询问[L,R]中选若干个数异或起来得到的答案集合大小.多组数据. 对于50%的数据,$R - L \leq 10^4$ 对于100%的数据,$R - L \leq 10^{18}, T ...