Countries   描述 There are two antagonistic countries, country A and country B. They are in a war, and keep launching missiles towards each other. It is known that country A will launch N missiles. The i-th missile will be launched at time Tai. It flie…
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5877 Problem Description You are given a rooted tree of N nodes, labeled from 1 to N. To the ith node a non-negative value ai is assigned.An ordered pair of nodes (u,v) is said to be weak if  (1) u…
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6447 思路:很容易推得dp转移公式:dp[i][j] = max(dp[i][j-1],dp[i-1][j],dp[i-1][j-1]+val[i][j]) ,但是很明显离散化后也无法储存这些点,我们可以用树状数组对这个状态转移公式进行优化,我们先以y轴为第一优先级从小到大排序,以x轴为第二优先级从大到小排序,对x轴坐标进行离散化,这样我们就只需要维护x轴上的最大值即可,状态转移方程可优化为: dp[i…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6203 题意:n+1 个点 n 条边的树(点标号 0 ~ n),有若干个点无法通行,导致 p 组 U V 无法连通.问无法通行的点最少有多少个. 解法:按照询问的LCA深度排序,然后顺序标记每个询问的LCA.根据所给的树(任意点为根)预处理出每个点的前序 DFS 序和后序 DFS 序(需统一标号),及点的深度.根据 p 组 U V 处理每组两点的 LCA .压入优先队列(LCA 深度大的点优先出队).…
2016 10 28 考试 时间 7:50 AM to 11:15 AM 下载链接: 试题 考试包 这次考试对自己的表现非常不满意!! T1看出来是dp题目,但是在考试过程中并没有推出转移方程,考虑了打表,但是发现暴力程序的速度不够,直接交了暴力,没想到暴力程序爆0,考试后仔细查找发现是在深搜过程中的一个剪枝处忘记调整全局变量的值,,,低级错误要引以为戒!! for (int i = 0; i <= cur; i++) { a[x] += i; if (a[x] < a[x-1]) { a[x…
Bubble Sort 题意: 给你一个1~n的排列,问冒泡排序过程中,数字i(1<=i<=n)所到达的最左位置与最右位置的差值的绝对值是多少 题解: 数字i多能到达的最左位置为min(s[i],i) i为它的初始位置,s[i]为它的最终位置(因为最后是排好序,这个数是多少,就排在哪个位置,故为s[i]) 那最右位置呢? 就是判断数i初始时,右边有多少个数比i小,这个就能用树状数组来求解了 循环从右到左,对于数s[i],我们只需判断它右边1~s[i]-1中有几个数即可 树状数组是从1开始,所以…
Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of length n and q questions. The i-th question is whether P remains balanced after p ai and p bi  swapped. Note that questions are individual so that they have no affect on others. Parenthesis se…
首先整体二分,问题变成是否存在经过一个点的满足条件的路径 那么我对于每个路径(a,b,lca),在树状数组的dfn[a]++,dfn[b]++,dfn[lca]--,dfn[fa[lca]--] 然后直接查那个点的子树和就行了 #include<bits/stdc++.h> #define CLR(a,x) memset(a,x,sizeof(a)) #define MP make_pair using namespace std; typedef long long ll; typedef…
Given a rooted tree ( the root is node 1 ) of N nodes. Initially, each node has zero point. Then, you need to handle Q operations. There're two types: 1 L X: Increase points by X of all nodes whose depth equals L ( the depth of the root is zero ). (x…
任意门:https://nanti.jisuanke.com/t/31459 There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy ) means the wave is a rectangle whose vertexes are ( 00 , 00 ), ( xx , 00 ), ( 00 , yy ), ( xx , yy ). Every ti…