- 博客(23)
- 收藏
- 关注
原创 poj-3268-Silver Cow Party dijkstra模板题
第一遍dijkstar(求终点到起点的最短路) 第二遍dijkstra 权值反转(把mp[i][j]和mp[j][i]交换)(求各起点到终点的最短路) 水水水水水~~~~~#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int ans[1005],dis[1005],mp[1005][1005
2016-03-26 14:03:43 314
原创 poj-1797-Heavy Transportation dijkstra 水模板
求所有路径中最小权值最大的那条路径 水水水水水~#include<cstdio> #include<cstring> #include<algorithm> using namespace std; bool sym[1010]; int mp[1010][1010],st,en,we,n,m,maw[1010]; int dijkstra() { memset(sym,0,sizeof(s
2016-03-26 13:15:22 344
原创 HDOJ-1428-BFS+记忆化搜索
题意难理解 1.让你先求各点到终点的最短距离 2.求起点到终点的方案数,方案满足途中经过的每个点的到终点的最短距离都要比前面经过的点到终点的最短距离要短。。。#include<cstdio> #include<cstring> #include<queue> using namespace std; #define MAX 9999999 struct node{ int x,y; }n
2016-03-20 21:58:55 360
原创 HDOJ-小希的迷宫 水并查集
1.判断所有点的根节点是不是同一个 2.加点时判断两个点之前的祖宗是不是一个#include<cstdio> int am[100005],fa[100005],n,a[100005],b[100005]; bool sym; void init() { for(int i=0;i<100005;i++) { am[i] = 1; fa[i] = i;
2016-03-20 19:21:30 279
原创 快排模板
http://www.acmerblog.com/quick-sort-5789.html/* 快速排序朴素的实现 */ #include<stdio.h>void swap(int* a, int* b) { int t = *a; *a = *b; *b = t; }/*取最后一个作为基准 */ //划分操作的 第二种实现 int partition(int * arr,
2016-03-20 17:35:33 317
原创 aoj-733-闭合折线
1.先按x从小到大排序,再按y从小到大排序,x值相同的各点数肯定为偶数且从下到上两两匹配形成一组线段 2.判断在点内点外的方法应该会几何的都知道。。。毕竟我这种渣货都能熟练敲出来。#include<cstdio> #include<cmath> #include<cstdlib> struct point{ int x,y; }p[20000],p1; int cmp(const void
2016-03-20 15:19:29 412
原创 codeforces-Goodbye2015- New Year and Ancient Prophecy
第一次做这种难度的题刚开始做一点思路没有,看完别人的思路做出来以后感觉好简单我居然当时没有思路! 1.先求最长连续子串。因为后面要比较两个字串的大小如果在下面DP的时候在一次次比较两个数的大小妥妥会爆的。 2.DP (1)dp[i][j]代表最末尾为s[i]s[i+1]…s[j]这个数时的方案数,如果末尾为s[i]s[i+1]…s[j]这个数的方案可以,那这些方案同样适用s[i]s[i+1]
2016-03-20 15:12:16 335
原创 codeforces-Good Bye 2015-New Year and Domino
有点容斥原理的意思。。。#include<cstdio> long long dp[505][505],n,m; char mp[505][505]; int main() { while(scanf("%d%d",&n,&m)!=EOF) { for(int i=1;i<=n;i++) scanf("%s",mp[i]+1); for(in
2016-03-19 19:53:44 297
原创 poj-1611-The Suspects
并查集。。。 怎么分?想起了人民公社化。。。刚开始每个人在一个小社里。后来人际交流嘛各种互相介绍结果开始合成大社。总结和编号为0的人在一个大社的总人数。#include<cstdio> #include<algorithm> int n,m,l,fa[30005],am[30005],faGroup[30005]; void init() { for(int i=0;i<n;i++)
2016-03-19 15:19:19 249
原创 poj-2236-Wireless Network
并查集简单题 题意表面是1000*20000的数量级 其实最坏只需要(1+1000)*1000/2次合并就行了。。。#include<cstdio> int n,d; char order[10]; struct node{ int x,y; }a[2000]; int fa[2000],am[2000],st[2000]; void init() { for(int i=1;i<
2016-03-19 14:18:09 305
原创 HDU-1176-免费馅饼
题意没申清 刚开始以为在s点s+1和s-1的馅饼也可以捡和0和10不能到(题意坑也不说清楚)最后发现就是水DP。。。 没做任何优化除了用了个滚动数组。。。#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; int dp[2][13]; int th[100005][1
2016-03-18 21:20:00 547
原创 HDU-1159-最长公共序列模板。。。
简单但总忘只能记录了。。。#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> using namespace std; char s1[600],s2[600]; int dp[600][600]; int main() { while(scanf("%s %s",s1+1,s2+1)!=EOF)
2016-03-17 19:48:03 357
原创 HDOJ 1078 FatMouse and Cheese 记忆化搜索模板
记忆花搜索和普通搜索的区别 前者dp思想从终点推到起点也就是祖宗的最优值从他的子孙中的最优值选取 后者枚举从起点到终点刷新一遍#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int dp[200][200],mp[200][200],n,k,bu[4][2] = {0,1,0,-1,1,0,-
2016-03-16 21:09:41 752
原创 Hdoj-1074-状压dp
n个课程就是一个有n位置的二进制数,然后从0(也就是还没写作业)到(1<< n)-1(也就是全写完DP求最优解) 比如说 要完成四门作业的话此时要推dp[1011](第1,2,4门作业完成最少扣得分)那它就是由 dp[1001],dp[0011],dp[1010]三个状态转移的最优解, 置于顺序输出则先由0011转移再由1001转移再由1010转移(物品从n-1到0进行选取也就是先把下表大的作业
2016-03-16 15:28:29 438
原创 codeForces-Longest Subsequence
#include<cstdio> #include<cstring> using namespace std; int a[1100000],b[1100000],n,k, c[1100000]; int main() { while(scanf("%d%d",&n,&k)!=EOF) { memset(b,0,sizeof(b)); int i1 =
2016-03-15 21:04:09 309
原创 hdoj-1251-tire树模板
#include<cstdio> #include<cstring> using namespace std; struct tire{ int cnt; tire *next[26]; }; tire *root = new tire; void BuildTire(char *str) { tire *p = root; int l = strlen(str);
2016-03-12 16:20:36 326
原创 ahu-557容斥原理
用容斥求1-n中能被2-i中素数整除的个数ans其中 i*i<=n;然后结果为n-ans-1;#include<cstdio> int pri[10005],pri2[10005],i1,n,ans; void toGetPrim(){ for(int i=2;i<=10001;i++) if(!pri[i]){ for(int j=2;j*i<=10001;j++
2016-03-12 14:16:15 410
原创 hdoj-1796 容斥水题
第一发略坑#include<cstdio> #include<iostream> #include<algorithm> using namespace std; __int64 n,m,ans,sum,a[20],b; __int64 lcm(__int64 a,__int64 b) { int a1 = a,b1 = b; while(b){ long long
2016-03-11 22:11:50 266
原创 hdoj-1800-Flying to the Mars ELFhash模板
#include<cstdio> #include<cstring> #define max 3007 int n,am[max],ans,hash[max]; inline int ELFhash(char *str) { int h = 0,k; while(*str) { h = (h<<4) + *str++; k = h&0xf0000000L;
2016-03-08 21:51:42 266
原创 Hdoj-5637Transform
题意 s^t^w = 0, w为选取a1,a2,a3。。。an.2的0次方,2的1次方,2的2次方。。。2的16次方 选几个数异或出来的,w = s^t;最多31个数用bfs把生成w(0-100000)的步骤都求出来。#include<cstdio> #include<queue> #include<cstring> using namespace std; int a[50],n,m,no1,no
2016-03-08 11:47:56 231
原创 codeforces633D Fibonacci-ish map容器
map就是建一个红黑书 把每个元素的值都加进树种,当查找这个元素的值时算法复杂度logn 关于map的用法: map#include<cstdio> #include<cstring> #include<map> #include<algorithm> using namespace std; map<int,int>mp; map<int,int>mp2; int n; int main()
2016-03-01 13:11:51 303
原创 codeforces-A Trivial Problem 判断n!末尾0的个数模板
即判断n!有多少个5#include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> #include<queue> #include<stack> #include<set> #include<vector> #include<ctime> using namespace std; i
2016-03-01 12:52:29 332
原创 poj-1584 判断凸包算法+极角排序+判断点在几何内外 模板
几何问题的重点 1 精度问题 有时答案一直错不是因为算法错误 而是精度没有处理好 2 代码能力 几何代码量较大 要不断练习熟能生巧,否则因为一个bug可能要查错很长时间#include<cstdio> #include<cmath> #include<stack> #include<algorithm> using namespace std; struct point{ double
2016-03-01 12:36:23 883
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人