自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 C++ STL

STL 1 优先队列priority_queue empty() 如果队列为空返回真 pop() 删除对顶元素 push() 加入一个元素 size() 返回优先队列中拥有的元素个数 top() 返回优先队列队顶元素 在默认的优先队列中,优先级高的先出队。在默认的 int 型中先出队的为较大的数。 priority_queueq1;//大的先出对  priori

2015-02-09 10:05:05 488

原创 POJ 2676 Sudoku (DFS)

数独,开三个标记,直接暴力,400多mS还是可以接受的#include#include#include#include#include#include#includeusing namespace std;typedef long long LL;const int INF = 0x3f3f3f3f;const int M = 1010;int vish[15][15]

2015-10-30 14:22:46 340

原创 POJ 3083 Children of the Candy Corn(BFS + DFS)

优先左转 优先右转  两点最短#include#include#include#include#include#include#includeusing namespace std;typedef long long LL;const int INF = 0x3f3f3f3f;const int M = 1010;int dir[][2] = { 0,-1,-1,0,0

2015-10-26 23:03:33 366

原创 HDU 1172 猜数字 (傻逼暴力题)

第一次做这么傻逼的暴力题,心塞塞。。#include#include#include#include#include#include#includeusing namespace std;typedef long long LL;const int INF = 0x3f3f3f3f;const int M = 1010;struct node{ int num, v

2015-10-25 23:50:32 442

原创 拓扑排序

时间复杂度O(n+m)int tuopu(int n){ queueq; for(int i=1; i<=n; ++i) { if(indgree[i]==0) { q.push(i); } } while(!q.empty()) { int u=q.fr

2015-10-25 20:54:32 277

原创 HDU 1242 Rescue (BFS+优先队列)

从天使的位置开始,直到找到r,优先队列每次选择最短时间的路#include#include#include#include#include#includeusing namespace std;typedef long long LL;const int INF = 0x3f3f3f3f;const int M = 1010;struct node{ int x, y

2015-10-25 09:50:28 294

原创 HDU 1428 漫步校园(Spfa+记忆化搜索)

#include#include#include#include#include#includeusing namespace std;typedef long long LL;const int M = 10000;const int INF = 0x3f3f3f3f;int n;int dir[][2] = { 1,0,-1,0,0,-1,0,1 };int mp[5

2015-10-20 21:01:09 342

原创 HDU 1078 FatMouse and Cheese (记忆化搜索)

#include#include#include#include#includeusing namespace std;typedef long long LL;const int M = 10000;const int INF = 0x3f3f3f3f;int n, k;int dir[][2] = { 1,0,-1,0,0,1,0,-1 };int dp[105][10

2015-10-19 19:30:30 207

原创 POJ 3616 Milking Time(DP)

dp[i]= i-1时间段产奶量 + 现在的产奶量#include#include#include#include#includeusing namespace std;typedef long long LL;const int M = 10000;const int INF = 0x3f3f3f3f;struct node{ int st, et, w; boo

2015-10-18 21:05:32 265

原创 HDU 2859 Phalanx(DP)

基础DP#include#include#include#include#includeusing namespace std;typedef long long LL;const int M = 10000;const int INF = 0x3f3f3f3f;string s[1050];int dp[1050][1050];//char s[1050][1050]

2015-10-18 19:48:39 284

原创 POJ 1661 Help Jimmy (DP)

dp[i][j], j = 0, 1 (dp[i][0]表示以i号平台左边为起点到地面的最短时间,dp[i][1]]表示以i号平台右边为起点到地面的最短时间)状态转移方程:dp[i][0] = H[i] - H[m] + Min (dp[m][0] + X1[i] - X1[m], dp[m][1] + X2[m] - X1[i]);  m为i左边下面的平台的编号dp[i][1]

2015-10-10 21:06:45 269

原创 POJ 3186 Treats for the Cows (DP)

从里到外逆推//#pragma commmpnt(linkmpr, "/STACK:102400000,102400000")#include #include #include #include #include #include using namespace std;typedef long long LL;const int M = 100010;const int

2015-10-08 21:33:22 368

原创 POJ 2533 Longest Ordered Subsequence (LIS)

最长上升子序列O(n*logn)//#pragma commmpnt(linkmpr, "/STACK:102400000,102400000")#include #include #include #include #include #include using namespace std;typedef long long LL;const int M = 10001

2015-10-07 19:30:36 257

原创 HDU 1160 FatMouse's Speed(DP)

//#pragma commmpnt(linkmpr, "/STACK:102400000,102400000")#include #include #include #include #include #include using namespace std;typedef long long LL;const int M = 100010;const int INF =0x

2015-10-07 18:46:56 254

原创 HDU 1114 Piggy-Bank (完全背包)

完全背包for i=[0,n)    for(j=weight[i]; j        tab[j] = max(tab[j-weight[i]]+value[i],tab[j])//#include #include #include #include using namespace std;typedef long long LL;const int

2015-10-06 21:47:53 242

原创 POJ 1330 Nearest Common Ancestors (LAC)

LCA转RMQ 在线算法,,,//#pragma commmpnt(linkmpr, "/STACK:102400000,102400000")#include #include #include #include #include #include using namespace std;typedef long long LL;const int M = 100010;

2015-09-20 10:51:12 277

原创 HDU 4762 Cut the Cake (高精度 + 公式)

可得公式:  n / (m^(n-1))import java.io.*;import java.math.*;import java.util.*;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nex

2015-09-09 19:23:29 329

原创 POJ 3261 Milk Patterns (可重叠的出现K次的最长重复子串)

//#pragma commmpnt(linkmpr, "/STACK:102400000,102400000")#include #include #include #include #include using namespace std;typedef long long LL;const int M = 10055;/* *suffix array *倍增算法 O(n

2015-09-07 12:01:49 290

原创 POJ 1743 Musical Theme (不可重叠最长重复子串)

后缀数组+二分答案题目:找到一个字符串内长度不小于五的最长不重复字串,字串的所有数字同时加上或减去一同一个数也算重复出现。解析:首先最所有数字作差,原数据为a[i]新数据为a[i]=a[i+1]-a[i],这样一来及时原先的字串是进行过加或减那他们的差值也会相同,所以转换为求现有a[]中大与5的最长重复字串,用后缀数组。首先由二分答案的方法将问题变成判定性的:长度大于k的重复字串有没有

2015-09-07 10:52:36 301

原创 HDU 4080 Stammering Aliens (后缀数组 + 二分答案)

//#pragma commmpnt(linkmpr, "/STACK:102400000,102400000")#include #include #include #include #include using namespace std;typedef long long LL;const int M = 10005;/* *suffix array *倍增算法 O(n

2015-09-03 12:01:01 375

原创 HDU 4705 Y (树形DP)

思路:反面考虑,用总的方案数减去A,B,C三点在同一路径上的方案数。于是我们可以确定中间点B,在当前以B为根求得的son中任选一个,在剩下的节点n-tmp-1(tmp为已经求得的B的儿子的个数)中任选一个,产生tmp*(n-tmp-1)中组合。//#pragma comment(linker, "/STACK:102400000,102400000")#pragma comment(link

2015-08-20 19:55:29 302

原创 HDU 1814 Peaceful Commission (2-SAT)

矛盾的情况为:存在Ai,使得Ai既必须被选又不可选。 枚举每一对尚未确定的Ai, Ai‘ ,任选1个,推导出相关的组,若不矛盾,则可选择;否则选另1个,同样推导。若矛盾,问题必定无解。此算法正确性简要说明:由于Ai,Ai '  都是尚未确定的,它们不与之前的组相关联,前面的选择不会影响Ai, Ai '  。算法的时间复杂度在最坏的情况下为O(nm)。在这个算法中,并

2015-08-19 15:03:34 412

原创 HDU 3342 Legal or Not (拓扑排序)

拓扑排序应用,判断是否有环,,//#pragma comment(linker, "/STACK:102400000,102400000")#include #include #include #include #include using namespace std;typedef long long LL;const long long mod = 1e9 + 7;con

2015-08-18 09:59:49 306

原创 HDU 1285 确定比赛名次 (拓扑排序)

基础题,不多说。。//#pragma comment(linker, "/STACK:102400000,102400000")#include #include #include #include #include using namespace std;typedef long long LL;const long long mod = 1e9 + 7;const int

2015-08-18 09:51:27 277

原创 POJ 3020 Antenna Placement (Hungary)

求最小覆盖边, 无向二分图的最小路径覆盖 = 顶点数 – 最大二分匹配数/2 由于构图过程中匹配双向的,所以匹配数多了一倍,最后要/2 构图可以用奇偶,或者用数来标记//#pragma comment(linker, "/STACK:102400000,102400000")#include #include #include #include #include usi

2015-08-15 10:08:30 409

原创 HDU 2853 Assignment (KM算法)

来自网上的巧妙思路:因为我们要变动最小,所以对在原计划中的边要有一些特殊照顾,使得最优匹配时,尽量优先使用原计划的边,这样变化才能是最小的且不会影响原匹配。根据这个思想,我们可以把每条边的权值扩大k倍,k要大于n。然后对原计划的边都+1。精华全在这里。我们来详细说明一下。全部边都扩大了k倍,而且k比n大,这样,我们求出的最优匹配就是k倍的最大权值,只要除以k就可以得到最大权值。实现原计

2015-08-13 22:16:21 343

原创 HDU 2255 奔小康赚大钱 (KM算法)

直接输入w[i][j]边权值建图套模板就可以了 //#pragma comment(linker, "/STACK:102400000,102400000")#include #include #include #include #include using namespace std;typedef long long LL;const long long mod = 1e9

2015-08-12 20:20:16 327

原创 HDU 5379 Mahjong tree (DFS)

#pragma comment(linker, "/STACK:102400000,102400000")#include #include #include #include #include using namespace std;typedef long long LL;const long long mod = 1e9+7;const int inf = 0x3f3f3f

2015-08-12 13:39:41 269

原创 HDU 5373 The shortest problem (水题)

~~水题,,,#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;const int inf = 0x3f3f3f3f;typedef lon

2015-08-11 19:47:48 321

原创 HDU 5371 Hotaru's problem (Manacher+暴力)

#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;const int inf = 0x3f3f3f3f;typedef long long LL;

2015-08-11 18:10:25 400 1

原创 HDU 4634 Swipe Bo (BFS+状压)

哎,学到了~!@~!@//#pragma comment(linker, "/STACK:102400000,102400000")#include#include#include#include#include#include#includeusing namespace std;const int M = 60005;const int INF = 1e10;//

2015-08-09 18:43:45 543

原创 HDU 5237 Base64 (Java大法好)

~!#~#@~!@~~~import java.util.Base64;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int casee = 0; int t = sc.nex

2015-08-09 17:00:55 544

原创 HDU 4666 Hyperspace(最长曼哈顿距离)

POJ 2926加强版,使用set处理,,//#pragma comment(linker, "/STACK:102400000,102400000")#include#include#include#includeusing namespace std;const int M= 60005;#define inf 1e100int a[M][5];int n,dem

2015-08-07 15:15:07 547

原创 POJ 2926 Requirements (多维最远曼哈顿距离)

考虑二维空间上两个坐标之间的曼哈顿距离(x1, y1) 和 (x2, y2),|x1-x2| +|y1-y2|去掉绝对值符号后共有下列四种情况(x1-x2) + (y1-y2), (x1-x2) + (y2-y1), (x2-x1) + (y1-y2), (x2-x1) + (y2-y1)转化一下:(x1+y1) - (x2+y2), (x1-y1) - (x2

2015-08-07 13:55:09 709

原创 后缀表达式计算

将中缀表达式转换为后缀表达式:与转换为前缀表达式相似,遵循以下步骤:(1) 初始化两个栈:运算符栈S1和储存中间结果的栈S2;(2) 从左至右扫描中缀表达式;(3) 遇到操作数时,将其压入S2;(4) 遇到运算符时,比较其与S1栈顶运算符的优先级:(4-1) 如果S1为空,或栈顶运算符为左括号“(”,则直接将此运算符入栈;(4-2) 否则,若优先级比栈顶运算符的高,也将

2015-08-05 21:04:50 471

原创 HDU 1063 Exponentiation (高精度)

JAVA大法好~~import java.util.Scanner;import java.math.BigInteger;import java.math.BigDecimal;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); i

2015-08-05 11:57:50 375

原创 HDU 5351 MZL's Border(找规律)

由于有高精度,用JAVA写。。。第一次写正规的JAVA,哭晕import java.util.Scanner;import java.math.BigInteger;public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in);

2015-08-04 18:08:25 700

原创 HDU 3473 Minimum Sum (划分树)

查询某区间的中位数与区间所有值的差值和//#include #include #include #include #include using namespace std;typedef long long LL;const int MAXN = 200010;int tree[20][MAXN];//表示每层每个位置的值int sorted[MAXN];//已经排序好的数

2015-08-04 09:55:32 293

原创 POJ 2104 K-th Number (主席树 || 划分树)

静态区间查询第K大   主席树入门//#include #include #include #include #include using namespace std;const int MAXN = 100010;const int M = MAXN * 30;int n,q,m,tot;int a[MAXN], t[MAXN];int T[M], lson[M], r

2015-08-03 13:55:46 264

原创 HDU 2852 KiKi's K-Number(树状数组+二分)

0的时候增加元素 1的时候删除 2的时候查找第几个比当前数大的//#include #include #include #include #include using namespace std;const int M = 100005;int N;int d[100005];int s[100005];int flag;int s1[100005];int lo

2015-08-02 18:26:08 292

空空如也

空空如也

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

TA关注的人

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