自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Collider

愿所有刷过的题都成为你比赛中信手拈来的水题.

  • 博客(29)
  • 收藏
  • 关注

原创 POJ2686-Traveling by Stagecoach

状态压缩dp,将n张马票看作n种状态进行状态压缩。 s代表到达剩下的车票集合,v代表现在所在的城市。 d[s][v]表示所需的最小费用。 这样一来,dp[s{i}][u] = min(dp[s{i}[u], dp[s][v] + d[v][u] / t[i])#include <cstdio>#include <cstring>#include <algorithm>using names

2016-08-28 20:40:13 445

原创 POJ2104-K-th Number

静态区间求第K大的值,有多种方式。 首先可以用分桶法和平方分割求解,将数据分为多个桶,每个桶分别处理桶内的数据以降低复杂度。#include <cstdio>#include <vector>#include <algorithm>using namespace std;const int maxn = 100000 + 10;const int B = 1000;int a[maxn];

2016-08-27 22:01:34 392

原创 POJ2155-Matrix

楼教主的题被我做出来啦! 有一个01矩阵,两个操作:翻转从(x1, y1)到(x2, y2)的矩阵,查询(x, y)的值。 用二维树状数组记录每一个点的变换次数,按照奇偶性即可得到某个点现在的值。 变换时必须要从某点(x, y)更新到(n, n),以便更新后面的树状数组,因此,将(x1, y1)和(x2, y2)将矩阵分成四个区域,然后变换即可。#include <cstdio>#inclu

2016-08-22 16:40:38 354

原创 POJ1990-MooFest

这道题靠暴力朴素的n^2算法显然是过不了的,因此我们要对算法进行优化,先将读入的每个牛的信息按音量进行排序,这样每头牛只需将比它小的牛的距离总和加起来乘以牛的音量即可。借助两个树状数组,一个维护牛的数量,另一个维护牛的坐标和,这样每次计算出一头牛的左右两边的牛的距离总和并与牛的音量相乘再将牛加入树状数组,反复即可。#include <cstdio>#include <algorithm>using

2016-08-22 13:15:25 551

原创 HDU1106-排序

这样简单的题还用了STL,很惭愧….#include <iostream>#include <string>#include <set>#include <algorithm>using namespace std;int a[1005];int main(int argc, char const *argv[]) { string s; while (cin >> s) {

2016-08-17 12:24:05 245

原创 POJ1050&HDU1081-To the Max

从一个矩阵中寻找和最大的子矩阵,简单的枚举各种情况即可。 数组a表示原矩阵,b表示a中的某几行之和组成的新序列,这样就转换为求新序列的最大连续子序列的和问题了。#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 100 + 5;int a[maxn][maxn];

2016-08-17 11:03:45 254

原创 POJ1176-Party Lamps

这道题里有四个按钮,分别为1234,按钮按两次以上是无效的,因此每个按钮只有按和不按。另外按钮存在如下等式: 1+2=3 1+3=2 2+3=1 1+2+3=0 因此最终只会留下八种状态,将最终的八种状态按二进制顺序排列并枚举这八种状态判断即可。 先做出最终的状态,然后不断“改变复原”直到按钮次数变为c次。 注意只按4和都不按的两种情况,当c为2时是无法“改变复原”的。#include

2016-08-16 16:03:30 337

原创 POJ1125-Stockbroker Grapevine

floyd找出多源最短路后从中选择一个源点。 以该源点出发最大花费最小即满足条件。#include <cstdio>#include <algorithm>using namespace std;const int maxn = 105;const int inf = 1000 + 24;int d[maxn][maxn];void floyd(int n) { for (int k

2016-08-16 09:35:16 203

原创 POJ1083-Moving Tables

巧妙的类似贪心的做法#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef pair<int, int> P;const int maxn = 500;P itv[maxn];int room[maxn];int main(int argc, char const *argv[]) {

2016-08-16 08:55:35 420

原创 HDU1698-Just a Hook

线段树的成段更新问题,这里可以精简的删去build和query函数。#include <cstdio>#define lchild rt << 1, l, m#define rchild rt << 1 | 1, m + 1, rconst int maxn = 1 << 18;int tree[maxn];int lazy[maxn];int n;void push_up(int rt) {

2016-08-15 17:07:59 256

原创 POJ3468-A Simple Problem with Integers

一道经典的线段树区间更新的题,你值得拥有!#include <cstdio>#define lchild rt << 1, l, m#define rchild rt << 1 | 1, m + 1, rconst int maxn = 1 << 18;long long tree[maxn];long long lazy[maxn];int n;void push_up(int rt) {

2016-08-15 14:47:35 210

原创 POJ2991-Crane

维护一个线段树和一个相对变化角度的数组,每个线段树节点表示从左子树到右子树的向量,每条线段(叶子节点)一经初始化后就不改变vx, vy,只需更新父节点即可。#include <cstdio>#include <cmath>const double pi = acos(-1.0);const int st_size = (1 << 15) - 1;const int maxn = 10000 +

2016-08-15 11:11:13 438

原创 POJ2549-Sumsets

这道题可以将a+b+c=d改为a+b=d-c,然后折半枚举d-c的所有可能性,然后找出是否存在a+b满足条件即可。#include <cstdio>#include <algorithm>using namespace std;const int maxn = 1000 + 5;int s[maxn];int main(int argc, char const *argv[]) { int

2016-08-14 09:58:12 378

原创 POJ3977-Subset

35个数字意味着2^35种可能性,穷举是不可能的,因此我们采用二分搜索。 首先枚举一半的可能性存入map容器中,并不断更新答案,因为有可能这一部分中的答案就是最后的答案。同样枚举另一半的可能性,更新答案,但是要注意与上一部份的答案相结合。#include <cstdio>#include <map>#include <algorithm>using namespace std;typedef

2016-08-13 16:50:21 362

原创 POJ2566-Bound Found

给定一串数组和一个值,找出一段连续的子列使它们和的绝对值离这个值最近。#include <cstdio>#include <cstdlib>#include <algorithm>using namespace std;const int maxn = 100000 + 10;typedef pair<int, int> P;int a[maxn];P sum[maxn];int main(i

2016-08-13 13:28:06 370

原创 POJ2785-4 Values whose Sum is 0

如题,有四个数组,分别从四个数组中挑选一个数字使得四个数字之和为0,问有多少种这样的组合。 四个数组总共有n^4种情况,但是如果使用用折半枚举的方法,只需枚举出数组A与数组B中n^2中情况,将这些情况排序后就可以用二分搜索将算法的复杂度降低到n^2logn.#include <cstdio>#include <algorithm>using namespace std;const int max

2016-08-10 16:30:27 229

原创 HDU1754-I Hate It

典型的线段树问题,坑点在于有多组测试数据…#include <cstdio>#include <algorithm>using namespace std;const int maxn = 1 << 18;int n, dat[2*maxn-1];void init(int n_) { n = 1; while (n < n_) { n *= 2; }

2016-08-09 15:48:32 311

原创 POJ3684-Physics Experiment

物理题…. 咋一看因为多个球之间会有碰撞,必须对物理运动进行模拟,事实上并没有这个必要,当两球碰撞时并不是各自折返,而是当作穿过之后继续运动下去,于是就将问题简化啦。#include <cstdio>#include <cmath>#include <algorithm>using namespace std;const double g = 10.0;const int maxn = 10

2016-08-08 18:48:13 277

原创 POJ1222-EXTENDED LIGHTS OUT

反转开关问题,枚举第一行的状态然后从第二行开始翻转即可。#include <cstdio>#include <cstring>const int dx[] = {-1, 0, 0, 0, 1};const int dy[] = {0, -1, 0, 1, 0};int map[8][8];int f[8][8];int get(int x, int y) { int c = map[x

2016-08-08 15:58:27 219

原创 POJ3185-The Water Bowls

反转问题是一种很有意思的题。 首先观察这一排碗中第一个碗,只有第二个碗能改变第一个碗的方向,因此以此类推我们就可以得出解。 枚举第一个碗是否需要翻转,取操作数最小的一个。#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int bowl[25];int f[25]; //记录区间[

2016-08-08 15:09:27 305

原创 POJ3279-Fliptile

这道题是一道反转的开关问题,可以先指定一行的翻转方法,这样每个格子只有它下方的格子能够改变它的颜色。 这道题可以用DFS搜索,也可以用枚举来做。 第一行的状态有2^n次,因此该算法的复杂度为O(mn2^n),反转题的关键在于明白某个格子在被多次翻转后的状态以及检查翻转后剩下的最后一行是否全白。#include <cstdio>#include <cstring>const int maxm =

2016-08-07 16:38:31 254

原创 POJ3662-Telephone Lines

这是一道二分搜索题,在判断条件上使用Dijkstra求最少的花费,令mid为所需的答案,那么长度大于mid即为需要免费的电线,这些电线的数量与k比较后确定答案的位置。#include <cstdio>#include <vector>#include <queue>#include <algorithm>using namespace std;const int inf = 1000 + 10

2016-08-06 20:32:47 502

原创 POJ3438-Look and Say

原本想练一道二分的题的结果题号看错了一看这题的AC率还挺高就顺手做了一下 …. 简单的一道模拟题#include <cstdio>#include <cstring>char a[1002];int main(int argc, char const *argv[]) { int n; scanf("%d", &n); getchar(); while (n--)

2016-08-06 13:41:12 306

原创 POJ1759-Garland

二分好题,只要把判断在地上的灯的数量是否大于0即可#include <cstdio>const int maxn = 1000 + 5;double h[maxn];int n;double a;//x为第二个灯的高度//cnt表示在地上的灯的数量bool test(double x) { h[0] = a; h[1] = x; int cnt = 0; fo

2016-08-06 11:55:45 211

原创 POJ3276-Face The Right Way

这是一道反转开关问题,想让所有的牛都面朝前方,令F为0, B为1,给定一个k值,可以从最左端的牛开始,如果这头牛面朝后方,那么以这头牛为开始往后的k头牛的区间都应该反转,再以下一头牛为起点,以此类推… 用f[i]记录以i为起点的牛是否反转,反转为1,否则为0. 同时用sum记录第i头牛的反转情况,如果sum为奇数则与原方向相反,用sum与原方向相加即可得出是否需要反转。 当所有区间都反转完毕后

2016-08-04 09:51:32 237

原创 HDU1010-Tempter of the Bone

这道题考查了深搜和剪枝,首先要恰好在t的时间内到达,从起点(bx, by)到终点(ex, ey)的最短距离为abs(ex-bx)+abs(ey-by),如果t小于最小距离就是NO。 另外t与最短距离之差如果是奇数也一定是NO。#include <cstdio>#include <cstring>#include <cstdlib>char maze[8][8];int dx[4] = {-1

2016-08-03 15:14:56 195

原创 POJ2100-Graveyard Design

给定一个数要求所有能够构成连续整数平方和的方法。 以1-sqrt(n)为区间用尺取法解决。 区间[s,t),s和t要用long long,用int就会TLE,不知道是为什么….#include <cstdio>#include <cmath>#include <vector>using namespace std;vector<pair<int, int> > v;int main(int

2016-08-02 16:01:00 367

原创 POJ2739-Sum of Consecutive Prime Numbers

只要用尺取法就能轻松秒过!#include <cstdio>const int maxn = 10000;int prime[maxn];bool is_prime[maxn+1];int sieve(int n) { int p = 0; for (int i = 0; i <= n; i++) { is_prime[i] = true; } is

2016-08-02 14:44:15 226

原创 POJ3685-Matrix

观察此题给出的条件 i^2 + 100000 × i + j^2 - 100000 × j + i × j可知,这个函数值随i的增大而增大,因此在写二分条件的时候可以从每一列开始寻找小于等于mid的值是在该列的第几个,由此得出该列小于等于mid的个数,将所有列加起来就是矩阵中比mid小的所有个数,再与m比较即可。#include <cstdio>long long f(long long i, lo

2016-08-02 11:39:05 273

空空如也

空空如也

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

TA关注的人

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