HDU 3094 A tree game】的更多相关文章

Problem Description Alice and Bob want to play an interesting game on a tree.Given is a tree on N vertices, The vertices are numbered from 1 to N. vertex 1 represents the root. There are N-1 edges. Players alternate in making moves, Alice moves first…
A tree game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Alice and Bob want to play an interesting game on a tree.Given is a tree on N vertices, The vertices are numbered from 1 to N. vertex…
思路: 叶子节点的SG值为0:中间节点的SG值为它的所有子节点的SG值加1 后的异或和. 详见贾志豪神牛的论文:组合游戏略述 ——浅谈SG游戏的若干拓展及变形 代码如下: #include<cstdio> #include<vector> using namespace std; vector<]; int get_sg(int n,int u) { ; ;i<p[n].size();i++){ +get_sg(p[n][i],n)); } return ans; }…
叶节点SG值至0 非叶节点SG值至于它的所有子节点SG值添加1 XOR和后 #include <cstdio> #include <cstring> #include <vector> using namespace std; vector <int> G[100010]; int sg[100010]; int dfs(int x, int f) { if(sg[x] != -1) return sg[x]; if(!G[x].size()) return…
HDU 5513 Efficient Tree 题意 给一个\(N \times M(N \le 800, M \le 7)\)矩形. 已知每个点\((i-1, j)\)和\((i,j-1)\)连边的花费,求最小生成树的权和. 对于每棵最小生成树\(T\),求\(\tau(T)=\prod{LRdeg_u}\)的和,其中\(LRdeg_u\)表示左.上方连边的个数+1. 思路 因为\(M\)很小,可以考虑轮廓线DP,记录前\(M\)个格子的连通信息. 对于每个格子\((i, j)\)有4种转移:…
基本的树上删边游戏 写过很多遍了 /** @Date : 2017-10-13 18:19:37 * @FileName: HDU 3094 树上删边 NIM变形.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github.com/ * @Version : $Id$ */ #include <bits/stdc++.h> #define LL long long #d…
HDU 4925 Apple Tree 题目链接 题意:给一个m*n矩阵种树,每一个位置能够选择种树或者施肥,假设种上去的位置就不能施肥,假设施肥则能让周围果树产量乘2.问最大收益 思路:推理得到肯定是果树和肥料交叉种好,类似国际象棋棋盘,黑的种,白的施肥.因为格子数不多,直接去枚举每一个位置就可以.假设题目格子数多的话.事实上也能够推出公式一步得到答案 代码: #include <cstdio> #include <cstring> const int d[4][2] = {{0…
题意: 输入一个带权的无向连通图 定义以顶点\(u\)为根的最短路生成树为: 树上任何点\(v\)到\(u\)的距离都是原图最短的,如果有多条最短路,取字典序最小的那条. 然后询问生成树上恰好包含\(k\)个节点的简单路径的最长长度,以及最长的路径有多少条. 分析: 其实我们可以拆分成两个问题. 求出生成树 首先跑一遍SPFA,然后从根节点开始按照子节点的编号从小到大排序,如果这条边是最短的那么就加入到生成树中去. 求最长路径 这里也是很简单的树分治,最长路径无非就是经过重心 或者 在其他子树中…
题目链接: Hdu 5379 Mahjong tree 题目描述: 给出一个有n个节点的树,以节点1为根节点.问在满足兄弟节点连续 以及 子树包含节点连续 的条件下,有多少种编号方案给树上的n个点编号? 解题思路: 对于一个节点来讲,非叶子儿子节点最多有两个才能满足要求,否则满足子树节点连续的话就无法满足兄弟节点连续.然后有dfs计算每棵子树的贡献值,每棵子树的子节点可以分为叶子节点X和非叶子节点Y,叶子节点可以分配到一组连续的编号,非叶子节点只能分配到兄弟节点中最大或者最小编号两种情况,叶子节…
/* HDU 6035 - Colorful Tree [ DFS,分块 ] 题意: n个节点的树,每个节点有一种颜色(1~n),一条路径的权值是这条路上不同的颜色的数量,问所有路径(n*(n-1)/2条) 权值之和是多少? 分析: 考虑单种颜色,这种颜色的贡献是 至少经过一次这种颜色的路径数 = 总路径数(n*(n-1)/2) - 没有经过这种颜色的路径数 求没有经过这种颜色的路径数,即这种颜色的点将整棵树分块,每个分块中的总路径数 */ #include <bits/stdc++.h> u…
题意:给一个数组,每次查询输出区间内不重复数字的和. 这是3xian教主的题. 用前缀和的思想可以轻易求得区间的和,但是对于重复数字这点很难处理.在线很难下手,考虑离线处理. 将所有查询区间从右端点由小到大排序,遍历数组中的每个数字,每次将该数字上次出现位置的值在树状数组中改为0,再记录当前位置,在树状数组中修改为当前的数值.这样可以保证在接下来的查询中该数字只出现了一次.这是贪心的思想,只保留最可能被以后区间查询的位置.如果当前位置是某个查询区间的右端点,这时候就可以查询了.最后再根据查询区间…
Binary Tree 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5573 Description The Old Frog King lives on the root of an infinite tree. According to the law, each node should connect to exactly two nodes on the next level, forming a full binary tree. S…
http://acm.hdu.edu.cn/showproblem.php?pid=4786 Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 49    Accepted Submission(s): 26 Problem Description Coach Pang is interested in Fi…
Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5534 Description In mathematics, and more specifically in graph theory, a tree is an undirected graph in which any two nodes are connected by exactly…
http://acm.hdu.edu.cn/showproblem.php?pid=3333 Turing Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2614    Accepted Submission(s): 892 Problem Description After inventing Turing Tree, 3…
Tree Cutting Problem Description Byteasar has a tree T with n vertices conveniently labeled with 1,2,...,n. Each vertex of the tree has an integer value vi.The value of a non-empty tree T is equal to v1⊕v2⊕...⊕vn, where ⊕ denotes bitwise-xor.Now for…
Tree Maker Problem Description Tree Lover loves trees crazily. One day he invents an interesting game which is named Tree Maker. In this game, all trees are binary trees. Initially, there is a tree with only one vertex and a cursor on it. Tree Lover…
Colorful Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1539    Accepted Submission(s): 616 Sample Input 3 1 2 1 1 2 2 3 6 1 2 1 3 2 1 1 2 1 3 2 4 2 5 3 6 Sample Output Case #1: 6 Case #…
Fibonacci Tree 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4786 Description Coach Pang is interested in Fibonacci numbers while Uncle Yang wants him to do some research on Spanning Tree. So Coach Pang decides to solve the following problem: Consi…
Binary Tree Traversals Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2442    Accepted Submission(s): 1063 Problem Description A binary tree is a finite set of vertices that is either empty or…
Binary Tree Traversals Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9283    Accepted Submission(s): 4193 Problem Description A binary tree is a finite set of vertices that is either empty or…
题目地址:HDU 1710 已知二叉树先序和中序求后序. #include <stdio.h> #include <string.h> int a[1001], cnt; typedef struct node { int date ; node *lchild , *rchild ; }*tree; int getk(int ch,int ino[],int is,int n) { for(int i = is ; i <= is + n -1 ; i++) if(ino[…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3333 Turing Tree Time Limit: 6000/3000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others) 问题描述 After inventing Turing Tree, 3xian always felt boring when solving problems about intervals, because…
题目链接:pid=5379">http://acm.hdu.edu.cn/showproblem.php? pid=5379 Problem Description Little sun is an artist. Today he is playing mahjong alone. He suddenly feels that the tree in the yard doesn't look good. So he wants to decorate the tree.(The tre…
Turing Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5014    Accepted Submission(s): 1777 Problem Description After inventing Turing Tree, 3xian always felt boring when solving problems…
本文纯属原创,转载请注明出处.谢谢. http://blog.csdn.net/zip_fan 题目传送门:http://acm.hdu.edu.cn/showproblem.php? pid=5379 Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Little sun is an artist. Today he is playing…
题链;http://acm.hdu.edu.cn/showproblem.php?pid=1710 Binary Tree Traversals Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4205    Accepted Submission(s): 1904 Problem Description A binary tree i…
http://acm.hdu.edu.cn/showproblem.php? pid=4786 Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1733    Accepted Submission(s): 543 Problem Description Coach Pang is interested i…
\(\mathcal{Description}\)   link.   给定一个 \(n\) 个结点 \(m\) 条边的无向图,\(q\) 次操作每次随机选出一条边.问 \(q\) 条边去重后构成生成树的方案总数,对 \(p\) 取模. \(\mathcal{Solution}\)   首先求出 \(n-1\) 条边构成生成树的方案数,显然矩阵树定理.   接着,令 \(f(i,j)\) 表示操作 \(i\) 次,去重后有 \(j\) 条边的方案数.那么有: \[f(i,j)=jf(i-1,j)…
Dylans loves tree view code#pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <vector> #include <queue> #include <…