自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 小小知识

8个方向的搜索int dx[8] = {-2, -2, -1, -1, 1, 1, 2, 2};int dy[8] = {-1, 1, -2, 2, -2, 2, -1, 1};

2014-07-17 19:38:33 465

转载 二分图最大匹配的匈牙利算法

二分图是这样一个图,它的顶点可以分类两个集合X和Y,所有的边关联在两个顶点中,恰好一个属于集合X,另一个属于集合Y。 最大匹配: 图中包含边数最多的匹配称为图的最大匹配。  完美匹配: 如果所有点都在匹配边上,称这个最大匹配是完美匹配。 最小覆盖: 最小覆盖要求用最少的点(X集合或Y集合的都行)让每条边都至少和其中一个点关联。可以证明:最少的点(即覆盖数)=最大匹配数 最小路径

2014-07-10 11:12:24 442

转载 函数lower_bound()返回值

函数lower_bound()在first和last中的前闭后开区间进行二分查找,返回大于或等于val的第一个元素位置。如果所有元素都小于val,则返回last的位置举例如下:一个数组number序列为:4,10,11,30,69,70,96,100.设要插入数字3,9,111.pos为要插入的位置的下标则pos = lower_bound( number, num

2014-08-15 09:55:12 689

原创 hdu 1087 简单dp

思路和2391一样的。。#include#include#include#includeusing namespace std;const int inf=(0x7f7f7f7f);int main(){ int a; int s[10005]; int w[10005]; while(scanf("%d",&a)&&a) {

2014-08-14 21:38:49 702

原创 hdu 2391 Filthy Rich

简单dp 水一个处理点的时候,第一行和第一列特殊处理;其余的w[i][j]=show(w[i-1][j-1],w[i-1][j],w[i][j-1])+s[i][j];#include#include#include#include#includeusing namespace std;int s[1005][1005];int w[1005][1005];//存每个点的最大

2014-08-14 21:36:58 775

原创 hdu 1595 最短路

题意是要我们求出最短路中一条路坏的情况下最大的时间;我们先将最短路求出并记录路径,然后枚举最短路中每一条路坏的情况,求出最大的时间。。#include#include#include#include#includeusing namespace std;int s[1005][1005];int p[1005];int vist[1005];int q[1005];co

2014-08-14 17:01:11 758

原创 poj 2573 Bridge (过桥问题 贪心)

对于此问题有两种策略1、最快的带最慢的和次慢的2、最快和次快带最慢和次慢此链接有详细解释点击打开链接#include#include#include#includeusing namespace std;int s[1050];int main(){ int a; scanf("%d",&a); for(int i=0;i<a;i+

2014-08-13 10:49:39 1063

转载 博弈论详解

博弈论(理论知识) 博弈论:是二人或多人在平等的对局中各自利用对方的策略变换自己的对抗策略,达到取胜目标的理论。博弈论是研究互动决策的理论。博弈可以分析自己与对手的利弊关系,从而确立自己在博弈中的优势,因此有不少博弈理论,可以帮助对弈者分析局势,从而采取相应策略,最终达到取胜的目的。 博弈论分类:(摘自百度百科) (一)巴什博奕(Bash Game):只有一堆n个物品,

2014-08-12 22:11:50 816

原创 HDU 1598 find the most comfortable road(并查集+枚举)

先把每条边的权值从大到小排序,在一个个枚举,利用并查集判断是否在一个集合中。。。#include#include#include#include#include#includeusing namespace std;const int maxn=205;const int maxm=1005;const int inf=(0x7f7f7f7f);#define min(a,b)

2014-08-12 09:47:45 574

原创 hdu 4857 逃生(优先队列+逆拓扑排序)

题意是给你一些关系,来进行排序,前面的那个人一定在后一个人前面,也在那些没有交钱的人的前面。。我们用逆拓扑排序,先把入度为零的数从大到小存入数组。然后就是一般的拓扑排序。。最后逆序输出#include#include#include#include#include#include#includeusing namespace std;int m,n;vector

2014-08-11 20:59:12 579

原创 hdu 4932 Miaomiao's Geometry

被秀智商下限了;直接代码。。#include#include#include#include#includeusing namespace std;int s[55];double w[120];int main(){ int a,b,i; scanf("%d",&a); while(a--) { scanf("%d",&b); for(i=0;i<b;i

2014-08-11 10:41:46 502

转载 poj 2492 A Bug's Life (并查集同食物链)

Language: DefaultA Bug's LifeTime Limit: 10000MS Memory Limit: 65536KTotal Submissions: 27157 Accepted: 8841DescriptionBackground Professor Hopper is re

2014-08-10 09:36:38 523

原创 uva 11374 最短路+记录路径 dijkstra最短路模板

UVA - 11374Airport ExpressTime Limit:1000MS Memory Limit:Unknown 64bit IO Format:%lld & %llu[Submit]  [Go Back]  [Status]  DescriptionProblemD: Ai

2014-08-09 08:58:32 1157

原创 UVA - 10917 Walk Through the Forest (最短路+DP)

题意:Jimmy打算每天沿着一条不同的路走,而且,他只能沿着满足如下条件的道路(A,B):存在一条从B出发回家的路径,比所有从A出发回家的路径都短,你的任务是计算有多少条不同的路径从后往前找最短路,对于每一步要更新之后走的位置值;#include#include#include#include#includeusing namespace std;const

2014-08-09 08:54:37 641

原创 UVA 12124 UVAlive 3971 Assemble(二分 + 贪心)

先从中找出性能最好的那个数,在用钱比较少的去组合,能组出来就表明答案在mid的右边,反之在左边,#include#include#include#include#includeusing namespace std;map vic;//以字符映射数字int end,start;int num;int m,n;int sba,sbb;char na

2014-08-08 09:10:46 695

原创 UVA 1422 - Processor (二分+贪心+优先队列)

先对开始时间进行排序,在利用优先队列是结束时间早点先出队;因为时间只有20000,我们可以去枚举每个单位时间,看要给分配给那个任务,如果某个时间队列中还有结束时间大于枚举的时间,就跳出判断是在mid的右边。#include#include#include#include#include#include#includeusing namespace std;

2014-08-08 09:01:05 791

原创 hdu 3336 Count the string(KMP)

一道应用kmp算法中next数组的题目这其中vis[i]从1加到nvis[i]=[next[i]]+1;#include#include#include#include#includeusing namespace std;char s[200005];int b;int next[200005];int vis[200005];void n

2014-08-08 09:00:26 623

原创 codeforce C. Valera and Elections (DFS)

给你几组数代表那两个城镇有路连接和路的好坏。。要找到最少的从城镇1到x的x集合能把所有的坏的路都找到并修好。。C. Valera and Electionstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutp

2014-08-07 10:42:50 938

原创 hdu 1781 Friend

题意是,1,2是Friend number,其他的Friend number必须由两个Friend number   a,b由ab+a+b组成。。ab+a+b=(a+1)(b+1)-1,而a,b也是Friend number,就这样推下去最终会得到friend number=((1+1)^x)*((1+2)^y)-1;#include#include#include#i

2014-08-06 15:25:13 573

转载 sscanf的使用

这里有些sscanf()的一些使用说明,都是从论坛,Blog里整理出来的。供大家使用。    通过学习和使用个人认为,在字符串格式不是很复杂,但是也并不简单的时候用这个函数比较合适,这个尺度就要靠自己把握了,字符串不是很复杂,但自己写个处理的函数比较麻烦,效率也不高,就用这个函数,如果字符串很复杂,那就用正则表达式吧。 不多说了,看看下面这些介绍和列子吧!名称:sscanf() -

2014-08-05 21:45:34 565

原创 hdu 1285 确定比赛名次 拓扑排序

第一道拓扑排序题。。拓扑排序就是一个有向图,如果这个图有环就不能用拓扑排序。对于拓扑排序就是将没有进只有出的点或别的先出。。出来后将原来图中与输出有关的线全部删除,直到找不到这要的点或数据。。#include#include#include#includeusing namespace std;int s[505][505];int a,b;int w[10

2014-08-05 17:17:13 547

原创 poj 2752 Seek the Name, Seek the Fame KMP

对于KMP算法中next函数的应用题意是对于一个字符串的前缀和后缀比较是否相等,再把相等的可能按字符串长度进行输出#include #include#includeusing namespace std;int len;int next[1000005];char s[1000005];int kmp_next(){    int i=0,j=-1;

2014-08-04 20:51:41 529

原创 poj 2406 Power Strings KMP匹配

对于数组s[0~n-1],计算next[0~n](多计算一位)。考虑next[n],假设t=n-next[n],如果n%t==0,则t就是问题的解,否则解为1。这样考虑:比如字符串"abababab",            a  b a b a b a b *next     -1 0 1 2 3 4 5 6  7考虑这样的模式匹配,将"ababa

2014-08-04 19:54:51 554

原创 hdu 2594 Simpsons’ Hidden Talents

题意是求第一个字符的前缀和后一个字符串的后缀最大的公共序列,并输出。。。将两个字符串合并,求出kmp中的next数组就行,但要注意不要大于某个字符串的长度;#include #include const int N = 50005;#define min(a,b) ((a)char s1[N], s2[N], s3[N * 2];int next[N * 2];

2014-08-04 17:31:26 612

原创 hud 2570 迷障(水 贪心)

对给的药水浓度进行排序,对于小于解毒药水浓度的可以直接加上它的体积,对每次混合后的药水浓度进行记录,大于解毒药水浓度就输出,注意你求得是百分比还是百分数。。。#include#include#include#includeusing namespace std;int s[10005];int main(){    int a,i,n,m,k;    s

2014-08-01 16:06:48 706

原创 hdu 1800 Flying to the Mars(水 ,贪心)

其实就是求最大的相同的数的多少。。我是把它当字符串输入。。解决前导0的问题。。#include#include#include#includeusing namespace std;int main(){    char s[35];    int w[3500];    __int64 qq[3500];    int a;    while(

2014-08-01 14:56:21 644

原创 poj 2970 优先队列

就多个等于号纠结死先按di排序,(从小到大)。然后依次完成合同,若发现第i个合同无法在截止日期前完成,便从之前已经完成的任务中选一个aj最大的合同,付钱来使得这个合同尽快完成。#include#include#include#include#includeusing namespace std;struct node{    int q;    in

2014-08-01 11:08:48 970

原创 hdu 1052 田忌赛马

贪心,排序从大到小。。先比大的,跑不过就拿最小的来送死。。,如果是平局就比后面的。。。若后面也是平局就拿去跟前面的去跑。。。#include#include#include#includeusing namespace std;int s[1005],w[1005];int main(){    int n,i;    while(scanf("

2014-07-31 19:40:53 653

原创 hdu 1176 免费馅饼(dp)

对于每个位置的馅饼数目只上一秒它本身和左右位置的最大馅饼数有关。。也可将他看做数塔。。从后往前找最大值。。#include#include#include#include#includeusing namespace std;int s[11][100001];int yy[11];int e,f;int maxn(int y,int u,int k

2014-07-30 11:34:56 631

原创 poj 1088 滑雪

记忆化搜索。。对每个点能走的最远进行记录,如果走过,直接返回上一层。。最后遍历找出最大值。。#include#include#include#includeusing namespace std;struct node{ int q,w;}s[104][105];int a,b;int yy[105][105];int map[4][2]={1,0,-1,0,0,

2014-07-30 10:29:22 519

原创 hdu 1024 Max Sum Plus Plus(DP)

转移方程dp[i][j]=Max(dp[i][j-1]+a[j],max(dp[i-1][k] ) + a[j] ) 0此链接中有详解点击打开链接#include#include#includeusing namespace std;#define MAXN 1000000#define INF 0x7fffffffint dp[MAXN+10];int mma

2014-07-29 21:38:42 685

原创 hdu 1003 MAX sum (简单DP)

起始点是从头开始的,一直到后面搜索,一直到和为小于零,起始点就从开始小于零的后一位开始并把结果改为零,再搜索的过程中,一遇到大的数据就记录下来,把其计为起始点和终点的,这里面主要考虑到,当你搜索到一个位置的,它的和不小于零的,那对于后面来说,加上去还是会变大的,不会给变小的,所以要再搜索下去的,走一边就KO了。代码如下:#include#include#includeusing namesp

2014-07-29 15:09:34 575

原创 hdu 1175 连连看

本题DFS与BFS都可以就是判断在两次转弯后 能不能找到。。BFS#include #include #include using namespace std;struct node{ int x, y; int t, d;};queue q;int n, m, map[1002][1002], prove;int visit[1002][1002][

2014-07-27 11:24:21 468

原创 poj3126Prime Path

就因为在判断素数的时候少个等于号  纠结一天,。。。。#include#include#include#include#include#includeusing namespace std;queue q;int v[10005],c;int yy[10005];int qq(int g){ for(int i=2;i*i<=g;i++) { i

2014-07-25 19:46:12 502

原创 poj1035Spell checker

暴力解决。先把字典里的每个单词的长度存起来,在查找的时候,就比较长度,在多一个少一个之间找,#include#include#include#include#include#includeusing namespace std;char s[10005][20];char h[20];int w[10005],len;int show(int a){ int i,

2014-07-25 16:53:15 631

原创 codeforces 258(Div.2) C. Predict Outcome of the Game

题意:有三个球队进行了N场比赛,其中K场已经比完了,但是你不知道结果。d1,d2是各自胜场的绝对值,比如一队和二队胜场差是d1,二队和三队胜场差是d2.问比完所有N场比赛是否存在各自都打平了。题解:根据他们的两个胜场差d1,d2可以求出他们各自的胜场。但是因为d1,d2是绝对值,所以我们有四种情况需要考虑,比如(+d1,+d2).(+d1,-d2),(-d1,+d2),(-d1,-d2)判

2014-07-25 15:10:58 536

原创 hdu 4217Data Structure?

树状数组+二分就是找第几小的数,,找几次,再求和。。#include#include#include#include#includeusing namespace std;const int N=277777;int t,n,m,bit[N],num,i;long long ans;int low(int g){ return g&(-g);}void up

2014-07-24 17:06:02 679

原创 UVA 127 Accordian'' Patience

题意:把一堆扑克牌,按照规则:如果左边1张或3张和它具有同花色或等级,把这张牌移到上面去,每次移动后,在从头开始移动,知道都移动完,输出剩余几堆与每堆牌数,如果1张牌有2个可以移动的地方,优先移动到左3位置。思路:用结构体存每一张牌,用栈来储存牌堆,每次判断能不能移动牌,每次移动后进行一次变换#include#include#includeusing namespace

2014-07-23 11:33:16 480

原创 uva 699

我们可以把它直接考虑是个一维数组,对每个点向两边扩展,记录数据在数组中,就是DFS#include int a[81],left,right;void sort(int num,int pos){int x,y; if (num!=-1) {if (pos<left) left=pos;  if (pos>right) right=pos;  a[pos]+=num;  s

2014-07-22 21:45:59 960

原创 poj2431 Expedition

直接代码、、、#include#include#include#include#includeusing namespace std;struct node{ int fuel,dist; //bool operator < (const node&d) const{ // return dist>d.dist; // }}s[10005];

2014-07-22 15:46:34 594

空空如也

空空如也

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

TA关注的人

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