HDU
薄层
努力就有收获~
展开
-
HDU-6129 Just do it - 2017 Multi-University Training Contest - Team 7(规律、杨辉三角、组合数奇偶性)
There is a nonnegative integer sequence a1...na1...n of length nn. HazelFan wants to do a type of transformation called prefix-XOR, which means a1...na1...n changes into b1...nb1...n, where bibi equals to the XOR value of a1,...,aia1,...,ai. He will repeat原创 2017-08-16 21:01:39 · 379 阅读 · 0 评论 -
HDU-1024 Max Sum Plus Plus(DP)
题意:可以认为是最大和子序列的进化版, 要求从一串序列中取出若干段, 使得这几段的和最大。思路:可以先推出来一个二维的转移方程式:dp[i][j] = max(dp[i-1][j]+num[i], max(dp[t][j-1]+num[i]); (其中 j-1 表示从前i个数中取j个段能够取得的最大和,并要求最后一个段包含num[i];题目给的序列长度为1e6,二维肯定爆原创 2017-05-23 11:52:38 · 394 阅读 · 0 评论 -
HDU 5898 数位DP
题意: 求满足数位上连续的奇数为偶数个,连续的偶数为奇数个的数的个数。思路: 典型的数位DP,dp[i][p][l]一维表示数位第i位,二维表示上一位的奇偶性,三维表示在第i位之前保持上一位的奇偶性的长度的奇偶性。我的第一层传入的p和l为1,0。因为0个奇数是满足偶数个奇数的性质的,即数位上只有奇数个偶数的的数是满足条件的。#include #include #incl原创 2017-05-15 16:30:50 · 261 阅读 · 0 评论 -
HDU 1176(基础DP)
免费馅饼Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9155 Accepted Submission(s): 2962Problem Description都说天上不会掉馅饼,但有一天gameboy原创 2017-04-02 15:55:30 · 353 阅读 · 0 评论 -
HDU-6178 Monkeys - 2017 Multi-University Training Contest - Team 10(树形DP)
There is a tree having N vertices. In the tree there are K monkeys (K <= N). A vertex can be occupied by at most one monkey. They want to remove some edges and leave minimum edges, but each monkey must be connected to at least one other monkey through the原创 2017-08-26 11:02:58 · 281 阅读 · 0 评论 -
HDU 3037(隔板法+组合数+Lucas)
题意:求在n棵树上摘不超过m颗豆子的方案数,结果对p取膜。思路:其实就相当于把i(0 很明显,需要用到隔板法。所以对于i个球,方案数为C(i+n-1, n-1)。总方案数为C(n-1, n-1)+C(n, n-1)+...+C(n+m-1, n-1);然后根据公式C(n, m) = C(n, n-m)得方案数为C(n-1, 0)+C(n, 1)+...+C(n+m-1, m);原创 2017-06-23 17:19:53 · 445 阅读 · 0 评论 -
HDU-5963 朋友(树上博弈)
题意:B君在围观一群男生和一群女生玩游戏,具体来说游戏是这样的:给出一棵n个节点的树,这棵树的每条边有一个权值,这个权值只可能是0或1。 在一局游戏开始时,会确定一个节点作为根。接下来从女生开始,双方轮流进行 操作。当一方操作时,他们需要先选择一个不为根的点,满足该点到其父亲的边权为1; 然后找出这个点到根节点的简单路径,将路径上所有边的权值翻转(即0变成1,1 变成0 )。当一方原创 2017-10-19 16:12:26 · 933 阅读 · 0 评论 -
HDU-5754 Life Winner Bo(混合博弈)
Bo is a "Life Winner".He likes playing chessboard games with his girlfriend G. The size of the chessboard is N×MN×M.The top left corner is numbered(1,1)(1,1) and the lower right corner is numberd (N,M)(N,M). For each game,Bo and G take turns moving a c原创 2017-09-05 14:57:40 · 289 阅读 · 0 评论 -
HDU-5724 Chess(SG函数+状压)
Alice and Bob are playing a special chess game on an n × 20 chessboard. There are several chesses on the chessboard. They can move one chess in one turn. If there are no other chesses on the right adjacent block of the moved chess, move the chess to its ri原创 2017-08-09 15:21:24 · 362 阅读 · 0 评论 -
HDU-4315 Climbing the Hill(阶梯博弈变形)
题意:在山上有n个人,每个人编号是1~n,这些位置只能同时被一个人占据,但是山顶可以同时被多个人占据,距离山顶第k近的是King,现在Alice和Bob开始向上送人,条件是不能跨越前面最近的人,问在Alice先手,双方最优的条件下谁能把King送到山顶获胜。思路:一道阶梯博弈变形的题,POJ-1704是一道朴素的阶梯博弈题目,但是这题与之有区别:每个点都可以移动到山顶,如果没这个条件再原创 2017-08-09 11:52:05 · 613 阅读 · 0 评论 -
HDU-5115 Dire Wolf(区间dp)
Dire wolves, also known as Dark wolves, are extraordinarily large and powerful wolves. Many, if not all, Dire Wolves appear to originate from Draenor.Dire wolves look like normal wolves, but these creatures are of nearly twice the size. These powerful bea原创 2017-07-12 16:55:28 · 391 阅读 · 0 评论 -
HDU-5787 K-wolf Number(数位DP)
Alice thinks an integer x is a K-wolf number, if every K adjacent digits in decimal representation of x is pairwised different. Given (L,R,K), please count how many K-wolf numbers in range of L,RL,R.InputThe input contains multiple test cases. There are原创 2017-07-17 19:21:52 · 380 阅读 · 0 评论 -
HDU-5647 DZY Loves Connecting(树形dp)
DZY has an unrooted tree consisting of nn nodes labeled from 11 to nn. DZY likes connected sets on the tree. A connected set SS is a set of nodes, such that every two nodes u,vu,v in SS can be connected by a path on the tree, and the path should only cont原创 2017-07-19 23:21:30 · 307 阅读 · 0 评论 -
HDU-4686 Arc of Dream(推公式+矩阵快速幂)
An Arc of Dream is a curve defined by following function: where a 0 = A0 a i = a i-1*AX+AY b 0 = B0 b i = b i-1*BX+BY What is the value of AoD(N) modulo 1,000,000,007?原创 2017-07-30 20:15:13 · 346 阅读 · 0 评论 -
容斥原理+模板题HDU-1796
容斥原理描述如下:说大白话就是求几个集合的并集,要计算几个集合并集的大小,我们要先将所有单个集合的大小计算出来,然后减去所有两个集合相交的部分,再加上所有三个集合相交的部分,再减去所有四个集合相交的部分...依此类推,一直计算到所有集合相交的部分。最简单的就是两个集合的并集:所以数学公式就可以表示为 |A∪B|=|A|+|B|-|A∩B|。对于三个集合,原创 2017-06-03 14:05:48 · 809 阅读 · 0 评论 -
HDU-4549(矩阵快速幂+欧拉定理)
题意:F[0] = a, F[1] = b F[n] = F[n-1] * F[n-2] (n > 1) 现在给出a, b, n,你能求出F[n]的值吗?思路:将F[n]推到F[0], F[1]可发现F[n]能表示成两个连续斐波那契数次幂的F[0]和F[1]的乘积:F[n] = F[0]^(n-1)*F[1]^(n)。矩阵快速幂求出斐波那契数, 然后普通快速幂求出F[n原创 2017-05-30 23:25:24 · 613 阅读 · 0 评论 -
HDU-5046 Airport(二分+DLX重复覆盖)
The country of jiuye composed by N cites. Each city can be viewed as a point in a two- dimensional plane with integer coordinates (x,y). The distance between city i and city j is defined by d ij = |x i - x j| + |y i - y j|. jiuye want to setup airport in K原创 2017-10-03 19:45:36 · 315 阅读 · 0 评论 -
计蒜客-2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛G题Query on a strin(树状数组+暴力更新)
You have two strings S and T in all capitals.Now an efficient program is required to maintain a operation and support a query.The operation C i ch with given integer i and capital letter ch, changes the i-thcharacter of S into ch.The query Q i j asks t原创 2017-09-11 15:50:23 · 271 阅读 · 0 评论 -
HDU-6201 transaction transaction transaction(树形dp)
2017 ACM/ICPC Asia Regional Shenyang OnlineKelukin is a businessman. Every day, he travels around cities to do some business. On August 17th, in memory of a great man, citizens will read a book named "the Man Who Changed China". Of course, Kelukin wouldn'原创 2017-09-10 22:32:40 · 318 阅读 · 0 评论 -
HDU-5900 QSC and Master(区间DP)
Every school has some legends, Northeastern University is the same. Enter from the north gate of Northeastern University,You are facing the main building of Northeastern University.Ninety-nine percent of the students have not been there,It is said that t原创 2017-09-08 13:36:02 · 258 阅读 · 0 评论 -
HDU-5773 The All-purpose Zero(LIS变形)
?? gets an sequence S with n intergers(0 < n <= 100000,0<= S[i] <= 1000000).?? has a magic so that he can change 0 to any interger(He does not need to change all 0 to the same interger).?? wants you to help him to find out the length of the longest increas原创 2017-09-07 15:44:30 · 293 阅读 · 0 评论 -
HDU-6170 Two strings - 2017 Multi-University Training Contest - Team 9(DP)
Giving two strings and you should judge if they are matched. The first string contains lowercase letters and uppercase letters. The second string contains lowercase letters, uppercase letters, and special symbols: “.” and “*”. . can match any letter, an原创 2017-08-23 01:37:41 · 339 阅读 · 0 评论 -
HDU-5973 Game of Taking Stones(大数+二分求精度)
题意:单纯的威佐夫博弈,不过数据范围增加到10^100,所以要用Java大数,所以当数一大,黄金分割数(1+√5)/2.0的精度就很重要了,而黄金分割数的精度又在于√5的精度,所以需要用到二分法求√5到一定精度。import java.math.BigDecimal;import java.math.BigInteger;import java.util.Scanner;原创 2017-05-02 00:31:43 · 598 阅读 · 0 评论 -
HDU 1729 Stone Game
一道SG函数+找规律的博弈。思路:先选个稍大点的数把各点SG状态打印出来,然后找规律,这题很容易看出,当到达第一个满足i*i+i >= s的点,它的SG值为(s-i),这样就可以很快判断出c >= k(k为第一个满足i*i>=s的点)时的SG值。当c = k时直接break,因为>=k时的SG值都是很大且递减的,知道最后SG[s]为0,在找规律时也很容易可看出,第一个不满足i*i+i >=原创 2017-04-11 14:47:07 · 314 阅读 · 0 评论 -
HDU-6058 Kanade's sum - 2017 Multi-University Training Contest - Team 3(思维+模拟链表)
Give you an array A[1..n]A[1..n]of length nn. Let f(l,r,k)f(l,r,k) be the k-th largest element of A[l..r]A[l..r]. Specially , f(l,r,k)=0f(l,r,k)=0 if r−l+1<kr−l+1<k. Give you kk , you need to calculate ∑nl=1∑nr=lf(l,r,k)∑l=1n∑r=lnf(l,r,k) There are T test原创 2017-08-01 20:09:27 · 422 阅读 · 0 评论 -
HDU-6215 Brute Force Sorting(思维、模拟链表)
2017 ACM/ICPC Asia Regional Qingdao OnlineBeerus needs to sort an array of NN integers. Algorithms are not Beerus's strength. Destruction is what he excels. He can destroy all unsorted numbers in the array simultaneously. A number A[i]A[i] of the array is原创 2017-11-11 16:21:10 · 464 阅读 · 0 评论 -
HDU-6069 Counting Divisors - 2017 Multi-University Training Contest - Team 4(分解质因子区间筛法)
In mathematics, the function d(n)d(n) denotes the number of divisors of positive integer nn. For example, d(12)=6d(12)=6 because 1,2,3,4,6,121,2,3,4,6,12are all 1212's divisors. In this problem, given l,rl,r and kk, your task is to calculate the following原创 2017-08-04 16:50:33 · 353 阅读 · 0 评论 -
HDU-6038 Function - 2017 Multi-University Training Contest - Team 1(构造置换或强连通分量)
You are given a permutation aa from 00 to n−1n−1 and a permutation bb from 00 to m−1m−1. Define that the domain of function ff is the set of integers from 00 to n−1n−1, and the range of it is the set of integers from 00 to m−1m−1. Please calculate the quan原创 2017-07-26 00:45:32 · 399 阅读 · 0 评论 -
HDU-6214 Smallest Minimum Cut(最小割)
2017 ACM/ICPC Asia Regional Qingdao OnlineConsider a network $G=(V,E)$ with source $s$ and sink $t$. An s-t cut is a partition of nodes set $V$ into two parts such that $s$ and $t$ belong to different parts. The cut set is the subset of $E$ with all edges原创 2017-09-18 13:24:32 · 716 阅读 · 5 评论 -
HDU-1719 Friend(公式化简)
Friend number are defined recursively as follows. (1) numbers 1 and 2 are friend number; (2) if a and b are friend numbers, so is ab+a+b; (3) only the numbers defined in (1) and (2) are friend number. Now your task is to judge whether an integer is a f原创 2017-11-30 15:50:02 · 305 阅读 · 0 评论 -
HDU-4664 Triangulation(博弈SG打表+类似凸包性质)
There are n points in a plane, and they form a convex set. No, you are wrong. This is not a computational geometry problem. Carol and Dave are playing a game with this points. (Why not Alice and Bob? Well, perhaps they are bored. ) Starting from no edges原创 2017-11-30 17:55:56 · 338 阅读 · 0 评论 -
HDU-6184 (无向图三元环计数)
Little A is an astronomy lover, and he has found that the sky was so beautiful! So he is counting stars now! There are n stars in the sky, and little A has connected them by m non-directional edges. It is guranteed that no edges connect one star with it原创 2017-09-06 17:19:53 · 1948 阅读 · 1 评论 -
HDU-3723 Delta Wave(卡特兰数+大数递推)
A delta wave is a high amplitude brain wave in humans with a frequency of 1 – 4 hertz which can be recorded with an electroencephalogram (EEG) and is usually associated with slow-wave sleep (SWS). -- from Wikipedia The researchers have discovered a new k原创 2017-12-09 19:51:16 · 399 阅读 · 0 评论 -
HDU 4883(区间选点贡献经典问题)
题意:有n组数据是客人到来和离开的时间以及所需的板凳数,问需要多少张桌椅才能满足所有客人来就都能有位置坐。思路:做法一:将区间左右端点都转换成分钟进行排序,如果是左端点,则贡献k,右端点则贡献-k。通俗点就是,把所有客人到来和离开的时间都转换成分钟数进行排序,每次客人到来需要k张桌椅,那么就+上k,每次客人离开就会返还k张桌椅,那么就-去k,求过程中的最大值。这和之前的一道cf题很原创 2017-06-10 13:39:29 · 398 阅读 · 0 评论 -
HDU-4908(思维之贡献问题)
题意:给一个N个数的序列,然后给出一个M,问以M为中位数的奇数长度的子序列序列个数。思路:训练时做的理解错题意了,一上来就连WA几次,中位数的概念都忘了,真是伤..中位数:一组按大小顺序排列起来的数据中处于中间位置的数。正解思路是:将大于m的数的位置贡献1,小于m的数的位置贡献-1,等于m的数的位置贡献0。然后找打最后一个等于m的位置,取其前面若干个以及其后面的若干个共奇数个的贡献总和为0原创 2017-06-20 23:56:36 · 373 阅读 · 0 评论 -
HDU-4886(hash+暴力枚举)
题意:给一个主串s(只包括‘A’‘B’‘C’‘D’‘E’‘F’‘G’‘H’),然后要找出一个串ans(也只包括‘A’‘B’‘C’‘D’‘E’‘F’‘G’‘H’),ans满足条件:在s所有子串中没出现过,其次保证长度最短,最后保证字典序最小。思路:可以估计ans的长度最长为7,因为要使主串s中存在所有的8个字符的排列需要长度为8^7,已经超过了题目给定长度。枚举所有长度的子串,然后将字符串哈希成原创 2017-06-21 12:39:39 · 456 阅读 · 0 评论 -
HDU 1079 Calendar Game(NP状态交替)
It's a easy Game Theory......网上是这么说的,思想到时不难,但操作起来自己遇到些麻烦。作为一只博弈论入门级别弱脊,于是来写一篇题解总结一下吧,虽然是自己模拟出来的,但中间还是遇到了一丝丝麻烦。大家都知道,所有的后继状态是N状态的某个状态叫做P状态,后继状态中存在一个或多个状态为P状态的某个状态叫做P状态,哎,当时写的时候不知道咋想的,写×了,于是WA了好多次,但今天原创 2017-03-24 14:33:29 · 432 阅读 · 0 评论 -
HDU-1848--博弈SG函数模板题
这篇文章写的很好,值得转发。首先定义mex(minimal excludant)运算,这是施加于一个集合的运算,表示最小的不属于这个集合的非负整数。例如mex{0,1,2,4}=3、mex{2,3,5}=0、mex{}=0。对于一个给定的有向无环图,定义关于图的每个顶点的Sprague-Grundy函数g如下:g(x)=mex{ g(y) | y是x的后继 },转载 2017-03-21 16:19:41 · 555 阅读 · 0 评论 -
HDU-5795 A Simple Nim(SG函数打表找规律)
题意:两人以最优策略对n堆物品进行操作,不能操作者输.1.从同一堆中取任意个(不为零).2.把一堆分成任意三堆(任一堆非空).思路:通过SG函数打表找规律,当对一堆物品进行分成三堆时,几种分法就是几种能到达的状态,而一种分法的SG值则是对该分法得到3份个数,对它们的SG值进行抑或起来就是该分法的SG值。最终可以找到规律,SG值当对8取余为7时,SG[x] = x原创 2017-03-21 15:36:33 · 400 阅读 · 0 评论 -
HDU-4424 Conquer a New Region(并查集)
The wheel of the history rolling forward, our king conquered a new region in a distant continent. There are N towns (numbered from 1 to N) in this region connected by several roads. It's confirmed that there is exact one route between any two towns. Traff原创 2017-10-02 00:36:45 · 246 阅读 · 0 评论