- 博客(41)
- 收藏
- 关注
原创 HDU-1317 XYZZY SPEA
http://acm.hdu.edu.cn/showproblem.php?pid=1317最短路变型注意环的问题 出现正环可以无限积累能量用SPEA求最长路 可以找出正环没有环的话就正常求最长路 有正环的话 就要模拟绕环积累能量 这样就可以跳过环 #include "stdio.h"#include "string.h"#include "vector"
2013-10-30 17:47:42 527
原创 HDU-1754 I Hate It 线段树
#include "stdio.h"#include "string.h"#include "algorithm"using namespace std;const int maxn = 200005;const int inf = 1<<30;int n,m;int x,y,ad,ans;struct node{ int score;}tree[max
2013-10-29 12:50:45 501
原创 HDU-1542 Atlantis 矩形面积并 扫描线
和hdu1255、hdu1264 一个类型 就不多做解释 详见:1255 http://blog.csdn.net/u011742541/article/details/132982371264 http://blog.csdn.net/u011742541/article/details/13233973 #include "stdio.h"#include "a
2013-10-28 18:47:35 496
原创 HDU-1264 Counting Squares 矩形面积并 线段树+扫描线
题意: 给任意个矩形求矩形的并集 交集算的面积为覆盖一次或一次以上的面积 并集为覆盖两次或两次以上的面积 代码就多个求覆盖两次或两次的函数 可以参考矩形面积交http://blog.csdn.net/u011742541/article/details/13233973 #include "stdio.h"#include "algorithm"us
2013-10-28 18:42:13 1078 1
原创 HDU-1255 覆盖的面积 线段树 + 扫描线
求矩形面积交 主要是扫描线不太懂 纠结了很久 #include "stdio.h"#include "algorithm"using namespace std;const int maxn = 2010;int n;double y[maxn];struct node{ double x,y1,y2; //x 边的位置 y边的区间大小
2013-10-27 20:08:24 1463
原创 HDU-1166 敌兵布阵 线段树
http://acm.hdu.edu.cn/showproblem.php?pid=1166 #include "stdio.h"#include "string.h"const int maxn = 50005;int a[maxn],tree[maxn*4];int n;void Pushup( int t ){ tree[t] = tree[t*2]
2013-10-27 19:57:30 585
原创 HDU-1166 敌兵布阵 简单树状数组
http://acm.hdu.edu.cn/showproblem.php?pid=1166#include "stdio.h"#include "string.h"const int maxn = 50005;int n,c[maxn];int lowbit( int x ){ return x&(-x);}void add( int x,int ad
2013-10-27 19:54:58 614
原创 HDU-1047 Integer Inquiry 大数相加
第一道java AC代码 =。= import java.io.*;import java.util.*;import java.text.*;import java.math.*;public class Main{ public static void main(String args[]) { int t; Sc
2013-10-27 15:03:04 663
原创 POJ-2892 Tunnel Warfare 树状数组
http://acm.hdu.edu.cn/showproblem.php?pid=1540题意: 给出直线上一系列的村庄,如果相邻村庄都没有被破坏, 则两村庄是连接的,题目给出一系列的破坏操作,对指定号码的村庄进行破坏, 还有一系列的询问操作,询问与指定号码的村庄直接相连或间接相连的村庄有几个, 还有一个修复操作,是对最后破坏的村庄进行修复。 #include "s
2013-10-26 19:25:37 560
原创 HDU-1556 Color the ball 简单树状数组
#include "stdio.h"#include "string.h"const int maxn = 100005;int n;int c[maxn];int lowbit( int x ){ return x&(-x);}void add( int x,int ad ){ while( x <= n ) { c[x] += ad;
2013-10-26 18:38:44 497
原创 HDU-3191 How Many Paths Are There 次最短路
http://acm.hdu.edu.cn/showproblem.php?pid=3191#include "stdio.h"#include "string.h"#include "vector"#include "queue"using namespace std;const int maxn = 210;const int inf = 1<<30;int n,
2013-10-25 20:06:00 886 2
原创 FAFU- 1387 Astar寻妹纸 a*
http://acm.fafu.edu.cn/problem.php?id=1387 #include#include#include#includeusing namespace std;const int maxn = 410;const int inf = 1<<29;int n,m;int map[maxn][maxn];int xs[] = {
2013-10-24 17:02:14 659
原创 HDU-3832 Earth Hour 最短路
思路: 计算3次裸Dijstra 求出前三个点到任意点的距离 枚举以每个点为中间点连接前三个点 Min( dist[1][i] + dist[2][i] + dist[3][i]; ) 答案为 n - Min - 1 #include#include#include#includeusing na
2013-10-22 20:39:32 605
原创 HDU-3507 Print Article DP斜率优化
/*HDU 3507*/#include#include#include#includeusing namespace std;const int MAXN=500010;int dp[MAXN];int q[MAXN];//队列int sum[MAXN];int head,tail,n,m;// dp[i]= min{ dp[j]+
2013-10-22 10:38:22 431
原创 HDU-2807 The Shortest Path 最短路
题意: 给你n个矩阵 如果矩阵a*b = c 则 a 与 c 有路思路: 最短路 难点是怎么把处理数据 只会暴力 5个for =。= #include#include#include#include#include#includeusing namespace std;const int maxn = 85;
2013-10-21 22:59:28 565
原创 HDU-1221 HDU Today 裸最短路 + STL
http://acm.hdu.edu.cn/showproblem.php?pid=2112裸最短路 主要是练练map STL还是不太熟悉 这题起点可能等于终点 = = 坑了半个多小时 #include#include#include#include#include#includeusing namespace std;const int maxn
2013-10-21 21:05:20 825
原创 HDU-1874 畅通工程续 最短路算法模板
水题拿来敲代码用 一些细节还是不是很熟悉 敲的还是太慢了 #include#include#includeusing namespace std;const int maxn = 205;const int inf = 1<<28;int n,m;int map[maxn][maxn],dis[maxn];bool vis[maxn];typede
2013-10-21 19:27:03 1080
原创 HDU-1869 六度分离 最短路
简单题 裸floyd 被DP虐了 把之前学的算法拉出来复习下题意: 任何2个素不相识的人中间最多只隔着6个人,即只用6个人就可以将他们联系在一起,因此他的理论也被称为“六度分离”理论;模型: 以直接认识的距离设为1 不认识的为无穷大 进行floyd(因为是要任意2个人) 最后判断是否有任意2人的距离超过7(间隔6人); #include
2013-10-21 18:36:21 549
原创 HDU-2066 一个人的旅行 最短路
http://acm.hdu.edu.cn/showproblem.php?pid=2066老早以前做的题 翻出来重新刷了次复习下dijkstra思路: 加一个起始点 把相邻的城市与起始点相连 距离为零 这样就可以把多源化成单源#include "stdio.h"#include "string.h"const
2013-10-19 22:51:47 586
原创 堆排序 - 最小堆
#include#include#includeusing namespace std;const int maxn = 1005;int n;int a[maxn];void Swap( int &a,int &b ){ int temp = a; a = b; b = temp;}// 从i节点开始调整,n为节点总数 从0开始计算 i节点的子节点为 2*i+1,
2013-10-18 19:59:43 418
原创 HDU-1540 Tunnel Warfare 线段树 区间合并
http://acm.hdu.edu.cn/showproblem.php?pid=1540题意: 给出直线上一系列的村庄,如果相邻村庄都没有被破坏, 则两村庄是连接的,题目给出一系列的破坏操作,对指定号码的村庄进行破坏, 还有一系列的询问操作,询问与指定号码的村庄直接相连或间接相连的村庄有几个, 还有一个修复操作,是对最后破坏的村庄进行修复。 //线段树定义三
2013-10-17 18:20:36 812
原创 FAFU-1272 官渡 线段树成段更新
http://acm.fafu.edu.cn/problem.php?id=1272#include "stdio.h"const int maxn = 100050;int data[maxn],n,q,max,min,x,y;struct node{ int max,min; node() { max = -1<<30; min = 1<<3
2013-10-17 18:17:24 552
原创 FAFU-1008 魔棍 线段树成断更新
http://acm.fafu.edu.cn/problem.php?id=1008#include "stdio.h"const int Max=100005;int x,y,v;int tree[4*Max+1];void creat( int l,int r,int t ) //创建结点{ tree[t]=10; if( l==r ) return;
2013-10-17 18:15:04 705
原创 HDU-2159 fate 二维背包
#include#includeint dp[101][101];int main(){ int n,m,k,s; int a,b; while(scanf("%d %d %d %d",&n,&m,&k,&s)!=EOF) //还需的经验值,保留的忍耐度,怪的种数和最多的杀怪数 { memset(dp,0,sizeof(dp)); for(int i=1;
2013-10-17 18:11:15 526
原创 POJ-3260 Coins 多重背包
#include "stdio.h"#include "string.h"int p[105],num[105];int dp[100005];int v;void CompletePacc(int cost,int weight) { int i; for(i=cost;i<=v;i++) if(dp[i]<dp[i-cost]+weight)
2013-10-17 18:09:03 498
原创 HDU-1081 To The Max 二维最大子序列和
http://acm.hdu.edu.cn/showproblem.php?pid=1081把行压缩成一行 再一这行求最大子序列和 这样就把二维转化为一维#include #include #include using namespace std;const int maxn = 105;int n;int maxs;int map[maxn][maxn
2013-10-17 18:05:54 639
原创 HDU-1513 Palindrome LCS+滚动数组
http://acm.hdu.edu.cn/showproblem.php?pid=1513将原字符串倒置,然后与原字符串求最长公共子序列, 答案就是len-dp[len][len]。#include "stdio.h"#include "string.h"const int maxn = 510;int n;char str1[maxn],str2[maxn
2013-10-17 18:03:12 455
原创 HDU-1494 跑跑卡丁车 DP
http://acm.hdu.edu.cn/showproblem.php?pid=状态 dp[i][j] 表示第i段能量为j的时间#include #include #include using namespace std;const int maxn = 105;const int inf = 1<<30;int n,m;int a[maxn],b[max
2013-10-17 18:00:26 526
原创 HDU-1520 简单树形dp
http://acm.hdu.edu.cn/showproblem.php?pid=1520dp[i][1] 表示选择i点 dp[i][0]表示不选择i点#include #include #include #include using namespace std;const int maxn = 6005;int n;int w[maxn],dp[maxn]
2013-10-17 17:58:04 517
原创 HDU - 2577 How to Type
http://acm.hdu.edu.cn/showproblem.php?pid=2577对于每个字母之前的字母有两种状态 1.tab开启 2.tab没有开启,有数组分别记录两种状态下的最短时间,接下来状态转移方程:0代表没开,1代表开了,对当前字母分类小写字母: timer[i+1][0]=min(timer[i][0]+1,tim
2013-10-17 17:54:38 476
原创 HDU-3392 Pie DP
http://acm.hdu.edu.cn/showproblem.php?pid=3392题目意思是让输入N个男的身高M个女的身高让min(N,M)那一方全部配对完,求最小的差值总和注意题目条件 |n – m| 所以每个只要从i+1找到i+n-m就可以了#include "stdio.h"#include "string.h"#include "algorit
2013-10-17 17:48:41 632
转载 树形DP总结
列出一些经典问题吧:1:给出一棵树 每个节点有权值 要求父节点和子节点不能同时取 求能够取得的最大值 (hdu1520)2:给出一棵树,求离每个节点最远的点的距离 (hdu2196)3:1>在一个地图上,有N座城堡,每座城堡都有一定的宝物,在每次游戏中允许攻克M个城堡并获得里面的宝物。但由于地理位置原因,有些城堡不能直接攻克,要攻克这些城堡必须先攻克其他某一个特定的城堡
2013-10-17 14:04:07 649 2
原创 HDU-1565 方格取数(1) 状态压缩DP
对于每一个数字,或取或不取,记1为取该数,0为不取该数,对于每行的数来说,它的状态就可以用一个二进制的数来描述,对于第一行,若果我们取75,21,我们就可以用二进制的5来描述,即101,因为取的数所在的2个格子不能相邻,所以每一行的二进制数不能有相邻的1,再来看列,相邻的两行不能有相邻的,对于两个二进制,也就是两个数相与(&)为0,这样就可以得到当前的行和上一行的关系,dp[i][j]=dp[i-
2013-10-16 23:40:39 567
原创 POJ - 1185 炮兵阵地 状态压缩DP
http://poj.org/problem?id=1185#include #include #include #include #include using namespace std; const int maxn = 105;int n,m;int dp[maxn][65][65]; //dp[i][j][k]表示第i行的状态为是s[j] 第i-1
2013-10-14 18:26:19 566
原创 HDU - 1466 计算直线的交点数
http://acm.hdu.edu.cn/showproblem.php?pid=1466看题目第一反应几何题... 结果跟我说用DP = =!果断没想法看别人报告才懂 DP真是博大精深 采用数组dp[i][j]。若dp[i][j]==1,则说明放i条直线有j个交点,则只需要把dp[n][i]从i=0到i=190扫一遍,因为20条直线最多有190个交点。
2013-10-14 13:06:09 600
原创 HDU-1500 Chopsticks DP
与上一题搬寝室基本一样 多点条件而已!状态: dp[i][j]表示前i个取j组转移方程: dp[i][j] = Min( dp[i-2][j-1] + (w[i] - w[i-1])*(w[i] - w[i-1]),dp[i-1][j] ); dp[i%3][j] = Min( dp[(i-2)%3][j-1] + (w[i] - w[i
2013-10-13 19:16:20 603
原创 HDU - 1421 搬寝室(经典DP)
http://acm.hdu.edu.cn/showproblem.php?pid=1421状态: dp[i][j] 表示i件物品搬j组转移方程: dp[i][j] = Min( dp[i-2][j-1] + qwe(w[i] - w[i-1]),dp[i-1][j] );#include#include#include#includ
2013-10-13 15:38:48 707
原创 HDU - 1080 Human Gene Functions DP
http://acm.hdu.edu.cn/showproblem.php?pid=1080题意: 给定两个字符串 s1 和 s2 ,在两个串中都可以插入空格,使两个串的长度最后相等,然后开始匹配,怎样插入空格由匹配规则得到的值最大。状态转移方程: dp[i][j] = Max( dp[i-1][j] + val(str1[i],'-
2013-10-12 11:23:12 414
原创 HDU - 1224 Free DIY Tour DP
Free DIY TourTime Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 4 Accepted Submission(s) : 2Problem DescriptionWeiwei is a software
2013-10-11 22:28:25 599
原创 HDU-1025 裸最长递增子序列
题意:河两岸各有n个城市 每个城市可以向对岸建路 建的路不能交叉 问最多可以建多少条路思路:可以把模型转化为最长递增子序列河的一岸作为序列的下标 另一岸作为序列的值 不相交既为 城市i前面的城市不能建比城市i连接的城市后 由于数据比较大 n坑:深坑... 输出要分单复数 只能建一条路的时候要输出road而复数要输出roads ..... 不看讨论区 坑
2013-10-10 22:38:51 540
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人