自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(80)
  • 收藏
  • 关注

原创 HDU 4442 Physical Examination【2012金华A题,贪心】

这题真不应该花了那么多时间。当时有了一个想法,但是我没有顺着这个想法做下去。后来还是zz_1215那样做了,果断AC。他说:“我不知道为什么这样,但哥就是AC啦!”其实是这样的:假设已经花了t秒,而现在有两个项目可选,所需时间分别为a1, b1和a2, b2。先选项目1再选项目2所需时间为:t1 = a1+b1*t + b2*(a1+b1*t+t)+a2 = a1+a2+(b1+b2)

2012-10-29 17:24:16 1709

原创 POJ 1509 Glass Beads【后缀自动机、最小表示法】

此题为最简单的后缀自动机的应用。#include #include #include #include #include using namespace std;const int maxn = 10010;struct SamNode { int ch[26]; int par, len; void Init() { par =

2012-10-07 17:13:32 2443 1

原创 SPOJ 3261. Race Against Time(RACETIME) 【线段树套SBT】

http://www.spoj.pl/problems/RACETIME/题意:1、修改某个数;2、求区间内小于等于某个数的数有多少个。#include #include #include #include #include using namespace std;const int maxn = 100010;struct Node { int key,

2012-10-04 22:14:47 1719

原创 POJ 3481 Double Queue【SBT】

http://poj.org/problem?id=3481该SBT模板只实现了一些简单的操作,我会不断完善其它功能。#include #include #include #include #include using namespace std;const int maxn = 100010;struct Node { int key, val;

2012-09-27 23:50:28 1065

原创 HDU 3971. Play With Sequence【线段树+排序】

http://acm.hdu.edu.cn/showproblem.php?pid=3971题意:对有n(0=l且=l且解法:首先可以想到线段树,线段树的每个节点存当前区间的最大值和最小值,当然还有延迟标记。但是,如果就只是这样做,还是会TLE。由于每次更新是将>=l且#include #include #include #include #include using na

2012-09-26 00:13:42 1549

原创 HDU 4348. To the Moon【可持久化树状数组】

http://acm.hdu.edu.cn/showproblem.php?pid=4348#include #include #include #include #include #include using namespace std;const int maxn = 100010;int n, m;struct Node { long long d,

2012-09-25 20:38:02 3465

原创 SPOJ 375. Query on a tree【树链剖分】

http://www.spoj.pl/problems/QTREE/给一颗树,每条边有一个权值。有两种操作:1、修改某条边的值;2、询问a、b两点路径上边权的最大值。树链剖分。#include #include #include #include #include #include using namespace std;const int maxn = 10010;

2012-09-18 21:00:39 1677

原创 ZOJ 3018 Population【二维线段树四分动态建树】

Population Time Limit: 10 Seconds      Memory Limit: 32768 KB  It is always exciting to see people settling in a new continent. As the head of the population management office, you are s

2012-09-13 23:37:05 1859 1

原创 HDU 4286 Data Handler【Splay Tree】【2012年天津网络赛1009】

我用伸展树过的这题,一直在TLE和RE之间徘徊。。。以下代码用C++交可以AC,G++会RE的。#include #include #include #include #include #pragma comment(linker, "/STACK:102400000,102400000")using namespace std;const int maxn = 100

2012-09-09 17:51:21 1862

原创 POJ 1084 Square Destroyer【Dancing Links重复覆盖】

Square DestroyerTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 2695 Accepted: 1101DescriptionThe left figure below shows a complete 3*3 grid made with

2012-09-04 14:27:39 2374

原创 HDU 3498 whosyourdaddy【Dancing Links重复覆盖】

有n个单位的敌人,对某个敌人进行攻击时该敌人以及与其直接相邻的敌人都会被消灭。问消灭所有敌人所需的最少攻击次数。重复覆盖问题。我把此题贴出来是想说剪枝优化很有必要,一个小细节就能决定是TLE还是AC。#include #include #include #include #include using namespace std;const int maxn = 60*60

2012-09-04 09:59:02 698

原创 HDU 2295 Radar【二分+Dancing Links重复覆盖】

重复覆盖不同于精确覆盖,要求是在0/1矩阵中选择最少的行使每一列至少有一个1。进行重复覆盖时要使用估价函数来剪枝。这题二分雷达半径,找到能将所有城市覆盖的最小半径即可。#include #include #include #include #include using namespace std;const int maxn = 50*50 + 10;const i

2012-09-04 08:35:12 867

原创 HDU 4069 Squiggly Sudoku【Dancing Links精确覆盖】

跟普通的数独有一点点不同,先预处理一下再用Dancing Links进行精确覆盖即可。#include #include #include #include using namespace std;const int maxn = 9*9*9*9*9*4 + 10;const int oo = 1 << 30;const int maxrow = 9*9*9 + 10;co

2012-09-04 08:26:58 1094

原创 HDU 2829 Lawrence【斜率优化dp】

题意:大概就是给你n(1将“4 5 1 2”分成一组得到的价值为:4*5 + 4*1 + 4*2 + 5*1 + 5*2 + 1*2 = 49;将“4 5 1 2”分成“4 5”和“1 2”两组得到的价值为:4*5 + 1*2 = 22;将“4 5 1 2”分成“4”和“5 1 2”两组得到的价值为:0 + 5*1 + 5*2 + 1*2 = 17。分析:本题可以用动态规划

2012-08-30 09:33:03 2799

原创 HDU 4258 Covered Walkway【斜率优化dp】

这题跟HDU3507差不多。#include #include #include #include #include using namespace std;const int maxn = 1000010;int n;__int64 c, x[maxn];__int64 dp[maxn];int q[maxn], head, tail;__int64 dy(int

2012-08-29 20:44:46 991

原创 HDU 3507 Print Article【斜率优化dp】

斜率优化dp,这篇文章讲的很好。#include #include #include #include #include using namespace std;const int oo = 1LL << 62;const int maxn = 500010;__int64 c[maxn], sum[maxn];__int64 dp[maxn];int q[maxn],

2012-08-29 20:40:03 1729

原创 Codeforces#135(div.2) E.Parking lot【线段树】

E. Parking Lottime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA parking lot in the City consists of n park

2012-08-28 23:07:34 1242

原创 HDU 2993 MAX Average Problem【斜率优化dp】

给由n(n=k的子序列的平均值的最大值。本题O(n^2)的dp算法比较好想,但是n的范围较大,会超时,所以,必须进行优化。这里用到的是斜率优化,《浅谈数形结合思想在信息学竞赛中的应用》这篇论文中有这一题的详细介绍。#include #include #include #include #include using namespace std;const int maxn =

2012-08-28 16:59:21 1403 2

原创 HDU 3401 Trade【单调队列+dp】

题意:已知股票每天的买入和卖出价格、买入上限和卖出上限以及最多能持有的股票数,问n天后的最大收益是多少。#include #include #include #include #include using namespace std;const int oo = 1 << 30;const int maxn = 2010;int tcase;int t, maxp,

2012-08-27 16:49:36 1133

原创 HDU 4262 Juggler(线段树)

2012 ACM/ICPC Asia Regional Online Warmup 1006题#include #include #include #include #include using namespace std;const int maxn = 100010;int sum[maxn<<2];int pos[maxn];int n;void bui

2012-08-25 17:20:12 982

原创 HDU 4393 Throw nails

因为第i个人第1秒走的距离Fi满足0 #include #include #include #include #include #include using namespace std;const int maxn = 50010;int t, n;struct Player { int k, s, id, dis;};Player p[maxn];

2012-08-25 01:22:05 1005

原创 HDU 4366 Successor(线段树)

题意:某公司有n个人,编号从0到n-1,0号是BOSS。除BOSS外,每个人有忠诚度和能力两个属性,每个人的忠诚度都不同。每个人都有可能被BOSS炒鱿鱼,当某个人被炒后,他的所有下级中能力大于他且具有最大忠诚度的人将取代他的位置。现在给定所有人的上下级关系(下级的编号总是比上级小)和一些被炒鱿鱼的人的编号,输出取代被炒人的人的编号,如果没人取代被炒人,输出“-1”。分析:首先,把以每个节点为根

2012-08-19 17:51:27 1295 1

原创 HDU 4374 One hundred layer(单调队列+DP)

#include #include #include #include #include using namespace std;const int maxn = 111;const int maxm = 10010;const int oo = 1 << 30;int n, m, x, t;int s[maxn][maxm];int sum[maxn][maxm];

2012-08-17 20:58:46 895

原创 HDU 4364 Matrix operation(模拟)

矩阵乘法。不过这里加法被xor取代,乘法有三种情况要分别处理。尤其要注意,矩阵中的数是8位的,所能表示的最大数为255,所以,左移后要与上255或对256取模。#include #include #include #include using namespace std;int t;unsigned int state[4][4] = { {0x2,

2012-08-15 17:19:39 1051

原创 HDU 4358 Boring counting(线段树)

用C++交会栈溢出,而G++不会。更新和查询我用的是线段树,1500+ms,用树状数组应该会快一些。将树形结构转换成线性结构后,等价于求指定区间内恰好出现k次的数有多少个。#include #include #include #include #include #include using namespace std;const int maxn = 100010

2012-08-15 00:40:18 1995 1

原创 HDU 4315 Digital root(线段树)

很不错的线段树题。#include #include #include #include using namespace std;const int maxn = 100010;int tcase, n, q;int a[maxn];/*ldr: 从区间左端点开始的前n项和的数字根的二进制表示 rdr: 从区间右端点开始的后n项和的数字根的二进制表示 idr: 区间内

2012-08-14 16:17:44 725

原创 HDU 4339 Query(线段树)

Problem DescriptionYou are given two strings s1[0..l1], s2[0..l2] and Q - number of queries.Your task is to answer next queries:  1) 1 a i c - you should set i-th character in a-th string to c

2012-08-03 15:39:48 672

原创 HDU 4328 Cut the Cake(动态规划)

Problem DescriptionMark bought a huge cake, because his friend ray_sun’s birthday is coming. Mark is worried about how to divide the cake since it’s so huge and ray_sun is so strange. Ray_sun is a

2012-08-02 19:19:30 700

原创 HDU 4325 Flowers(线段树)

线段树的区间更新和单点查询。需要注意的是要把区间端点和查询的点都先读入并离散化。#include #include #include #include #include #include #include using namespace std;const int maxn = 100100;int tcase, n, m;int sum[maxn<<2], add[m

2012-08-01 20:21:05 974 4

原创 HDU 4318 Power transmission(最短路变形)

#include #include #include #include #include #include #include using namespace std;const int maxn = 50010;int n;struct Edge { int v; double p;}edge;vector v[maxn];int start, end, m;

2012-07-27 20:04:41 681

原创 HDU 4313 Matrix (贪心+并查集)

题意:给你一个有n(2思路:我最开始想到的是:1、将边按权值由小到大排序。2、计算每条边连接的两个子树中分别有多少个机器人。3、然后,枚举每条边,如果该条边所连接的两个子树中都有机器人,则将该条边删除。4、重复步骤2和步骤3,直到枚举完所有的边。5、所删除的边的权值之和就是要求的结果。但是,这样做时间复杂度太高,主要是第2步花了太多的时间。后来,发现,完全可以反过来做,

2012-07-27 19:45:09 978

原创 HDU 4310 Hero(贪心)

比较简单的贪心。#include #include #include #include using namespace std;int n;struct Hero { int dps, hp;}hero[22];bool cmp(Hero a, Hero b){ return ((a.dps + b.dps) * a.hp + b.dps * b.hp) < (

2012-07-27 18:58:58 634

原创 HDU 3954 Level up(线段树)

#include #include #include #include #include using namespace std;const int maxn = 10010;int t, n, k, qw;int need[11] = {0};int maxexp[maxn<<2][11];int add[maxn<<2];void build(int l, int

2012-07-22 13:26:52 560

原创 HDU 4302 Holedox Eating (线段树)

#include #include #include #include using namespace std;const int maxn = 111111;int T, L, n;int sum[maxn<<2];void build(int rt, int l, int r){ sum[rt] = 0; if (l == r) retu

2012-07-20 00:48:07 854

原创 POJ 1986 Distance Queries [LCA]

#include #include #include #include using namespace std;const int maxn = 40010;const int maxk = 10010;int n, m, k;int cnt1, cnt2;int head1[maxn], head2[maxn];int set[maxn], an[maxn];int d

2012-05-26 16:28:01 535

原创 HDU 2874 Connections between cities [LCA]

题目给出的图不一定连通,可以虚拟一个根节点。查询时,若LCA(u, v)为根节点,则表示u,v不相连;否则,求出最短距离。#include #include #include #include #include #include using namespace std;const int maxn = 10010;int n, m, c, cnt;int e[maxn<<1]

2012-05-26 13:39:13 541

原创 POJ 1470 Closest Common Ancestors [LCA+RMQ]

这题的输入有点恶心,OLE很多次才过。。。ST:#include #include #include #include #include #include using namespace std;const int maxn = 10010;int n, q, cnt;vector son[maxn];int parent[maxn];bool vis[maxn];

2012-05-25 23:42:37 541

原创 POJ 1330 Nearest Common Ancestors [LCA+RMQ]

LCA的入门题,我用的是ST在线算法和Tarjan离线算法。ST:#include #include #include #include #include #include using namespace std;const int maxn = 10010;int t, n, cnt;vector son[maxn];int parent[maxn];bool vi

2012-05-25 21:38:38 807 1

原创 POJ 2452 Sticks Problem [RMQ+二分]

/*题意:给你一组数a[n],求满足a[i] < a[k] < a[j] (i <= k <= j)的最大的j-i。解法:RMQ + 二分。枚举i,利用二分求出a[i]右边第一个小于a[i]的数的位置k,再求出[i, k]中最大值的位置j,若a[j] > a[i],则更新结果。*/#include #include #include #include #include u

2012-05-24 19:11:00 1785

原创 POJ 2019 Cornfields [二维RMQ]

二维RMQ。求一个矩阵的子矩阵各元素的最大值与最小值之差。用int会超内存,改用short。#include #include #include #include #include using namespace std;const int maxn = 255;int n, b, k;short dpmin[maxn][maxn][10][10];short dpm

2012-05-24 12:24:40 1152

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除