2011年7月14日

poj-1190 生日蛋糕 **

摘要: /* * dfs+剪枝 * 注意到:N = (ri * ri * hi)求和 * S = r1 * r1 + (2*ri*hi)求和 (水平面面积之和第一层的半径有关) * */#include <cstdio>#include <cmath>using namespace std;const int INF = 10000000;const int MAXM = 20 + 5;int n, m, s;//可以使剪枝更加精确。。 79ms->63msint min_v[MAXM];int min_s[MAXM];void build(){ min_v[m] = 1 阅读全文

posted @ 2011-07-14 22:27 龙豆 阅读(476) 评论(0) 推荐(0)

poj-1874 Trade on Verweggistan *

摘要: /*排序..水。。 * * WA的话试试以下2租数据 * 1 * 2 11 16 * 2 * 2 11 16 * 2 1 3 * 输出应该是 * Workyards 1 * Maximum profit is 0. * Number of pruls to buy: 0 * * Workyards 2 * Maximum profit is 16. * Number of pruls to buy: 2 * 要注意最大利润小于0时的情况,最大利润小于0时,商人是不会买该堆的物品,即此时该堆最大的利润应该是0,而不是所求得的那个负数。 * */#include <cstdio>#in 阅读全文

posted @ 2011-07-14 19:57 龙豆 阅读(425) 评论(0) 推荐(0)

2011年7月11日

poj-3321 Apple Tree ****

摘要: /* 看了网上的代码。。再自己写了一个。。。( 网上很多代码都是默认输入的数据u是v的父节点。。 也能AC。。 但不严谨。。)【转】思路:树状数组。这道题重点怎么建立树到树状数组的映射关系:利用dfs遍历树,对每个节点进行两次编号,第一次搜到第i个节点时的深度dep,为这个节点管辖区间的上限low[i](也为这个节点的下标),然后搜这个节点的子节点,最后搜回来后的深度dep,为这个节点管辖区间的下限high[i]。接下来就是树状数组部分了。*//* * 3321 * 邻接表建树+树状数组 * */#include <cstdio>using namespace std;const 阅读全文

posted @ 2011-07-11 21:43 龙豆 阅读(343) 评论(0) 推荐(0)

poj-1195 Mobile phones *

摘要: /* 难得的1A题~~ 标准的树状数组 * 1195.cpp * 注意坐标从0开始, 应处理成从1开始 * Created on: 2011-7-11 * Author: */#include <cstdio>using namespace std;const int MAXS = 1024 + 5;int map[MAXS][MAXS] = {};int c[MAXS][MAXS] = {};int s, x, y , a, l, r, b, t, cmd; //题目中的参数int lowbit(int x){ return x & (-x);}void update(i 阅读全文

posted @ 2011-07-11 15:37 龙豆 阅读(274) 评论(0) 推荐(0)

poj-2777 Count Color *

摘要: //蛮水的线段树//2777//用scanf() 用位运算#include <cstdio>#include <cstring>using namespace std;const int MAXL = 100000 + 5;const int MAXT = 30 + 5;int L, T, O, a, b, c, ans;bool vis[MAXT * 3];char cmd;struct node{ int l, r; int c;};node tree[MAXL * 3];void build(int i, int l, int r){ tree[i].l = l; 阅读全文

posted @ 2011-07-11 15:06 龙豆 阅读(257) 评论(0) 推荐(0)

2011年7月10日

poj-2828 Buy Tickets ***

摘要: 线段树//2828View Code /* * [这段话转的。。] * 如果我们从头开始一次做的话,无论是用链表还是数组,肯定会超时(链表寻址时间长,数组移位时间长。)。 * 所以要用一个快速的方法直接找到位置。但是换个角 度,如果我们反过来排,那样的话,我们就知道他所在的 * 精确位置!把存储的结构想象成是链表,插队的人插入后,把他所在的位置从链表中屏蔽掉,然后在新的链 表种 * 继续这样存,这样的话我们就得到了我们想要的顺序! * * 按照这种思想,可以用线段树实现。。。 * */#include <cstdio>using namespace std;const int MA 阅读全文

posted @ 2011-07-10 16:41 龙豆 阅读(469) 评论(0) 推荐(0)

poj-2528 Mayor's posters

摘要: 离散化 + 线段树坐标按从小到大排序,再构造映射。。View Code 1 //color=0表示未着色或为杂色 2 3 #include <cstdio> 4 #include <cstring> 5 #include <algorithm> 6 using namespace std; 7 8 const int MAXN = 40000 + 5; 9 const int MAX_R = 10000000 + 5; 10 11 int n, ans; 12 bool vis[MAXN] = {}; 13 struct SData{ //记录数据 14 i 阅读全文

posted @ 2011-07-10 14:06 龙豆 阅读(254) 评论(0) 推荐(0)

2011年7月9日

poj-3034 Whac-a-Mole

摘要: dp先自己写了一个。。 n次WA后搞成TLE~ 。。。 忍无可忍。。 后来参考了网上的代码。 最终AC~先贴人家的代码吧~【转】思路:DP。改了要一天,很纠结的一道题。DP部分,dp[t][x][y]表示第t时间把锤子停在(x,y)上最多能够打到的地鼠数量。则dp[t][x][y]= max(dp[t-1][xx][yy]+ (xx,yy)到点(x,y)新打的地鼠数),(xx,yy)和(x,y)的直线距离<d。但是最主要的是下面两点:1:中转点可能在区域外,如下数据: //相当重要!!!20 5 41 0 10 1 10 5 21 6 2答案应该是4而不是3,这就需要扩展区域为n+2d就 阅读全文

posted @ 2011-07-09 16:52 龙豆 阅读(628) 评论(0) 推荐(0)

2011年7月8日

poj-1925 Spiderman

摘要: dpd[i] 表示从apartment到 横坐标 i 最少需跳几步。。 p[i] 建筑物 i 的横坐标, h[i]建筑物i的纵坐标注意 由对称性,spiderman的纵坐标始终是 apartment 的高度!! 所以不需要管纵坐标!!遍历每个建筑物。。 从横坐标 j 能跳过建筑物 i 需满足: (p[i] - j)^2 <= h[i] ^ 2 - (h[i] - h[1]) ^2 从横坐标 j 经建筑物 i 后 到达横坐标 2 * p[i] - j。。 综上, d[2 * p[i] - j] = min(d[2 * p[i] - j] , d[j] + 1)...最后注意到达west t 阅读全文

posted @ 2011-07-08 22:09 龙豆 阅读(819) 评论(0) 推荐(0)

2011年7月7日

poj-2948 Martian Mining

摘要: dpdp[i][j]表示(1,1)-(i,j)小矩阵的最大收获,可以轻松得到dp方程:dp[i][j] = max( dp[i][j-1] + col[j][i], dp[i-1][j] + row[i][j]);其中row[i][j]表示第i行从第0列到j列的和,col[i][j]表示第i列从第0行到j行的和。#include <cstdio>#include <cstring>using namespace std;const int MAXN = 500 + 5;int n, m;int data_x[MAXN][MAXN];int data_y[MAXN][MA 阅读全文

posted @ 2011-07-07 21:09 龙豆 阅读(301) 评论(0) 推荐(0)

导航