题目Dijkstra,正反两次最短路,求两次和最大的。#define _CRT_SECURE_NO_WARNINGS//这是找出最短路加最短路中最长的来回程//也就是正反两次最短路相加找最大的和#include#include#include#includeusing namespace std;const int MAXN=1010; #define typec int const typec INF=0x3f3f3f3f;//防止后面溢出,这个不能太大 bool vis[MAXN]; typec cost1[MAXN][MAXN],cost2[MAXN][MAXN];typec ... Read More
posted @ 2014-02-10 21:04 laiba2004 Views(244) Comments(0) Diggs(0) Edit
题目改动见下,请自行画图理解具体细节也请看下面的代码:这个花了300多ms#define _CRT_SECURE_NO_WARNINGS#include#include#include#includeusing namespace std;const int MAXN=1010; #define typec int const typec INF=200000000;//防止后面溢出,这个不能太大 bool vis[MAXN]; typec cost[MAXN][MAXN];typec lowcost[MAXN];void Dijkstra(int n,int beg) //连通图... Read More
posted @ 2014-02-10 16:06 laiba2004 Views(180) Comments(0) Diggs(0) Edit
题目这里的dijsktra的变种代码是我看着自己打的,终于把代码和做法思路联系上了,也就是理解了算法——看来手跟着画一遍真的有助于理解。#define _CRT_SECURE_NO_WARNINGS#include#include#include#includeusing namespace std;const int MAXN=210; #define typec double const typec INF=0x3f3f3f3f*1.0;//防止后面溢出,这个不能太大 bool vis[MAXN]; typec cost[MAXN][MAXN];typec lowcost[MAX... Read More
posted @ 2014-02-10 14:05 laiba2004 Views(270) Comments(0) Diggs(0) Edit
题目#define _CRT_SECURE_NO_WARNINGS#include#include#includeconst int MAXN=1010; #define typec int const typec INF=0x3f3f3f3f;//防止后面溢出,这个不能太大 bool vis[MAXN]; int pre[MAXN];typec cost[MAXN][MAXN];typec lowcost[MAXN];void Dijkstra(int n,int beg) { for(int i=1;ic) cost[a][b]=cost... Read More
posted @ 2014-02-09 22:28 laiba2004 Views(171) Comments(0) Diggs(0) Edit
题目题目很简单,只是多了对地名转化为数字的处理,好吧,这我也是参考网上的处理办法,不过大多数的人采用map来处理注意初始化注意范围,不然会wa!!!(这是我当时wa的原因org)大家容易忽视的地方——双向边,起点等于终点(虽然我当时都考虑到了)#define _CRT_SECURE_NO_WARNINGS#include#include#includeconst int MAXN=155; #define typec int const typec INF=0x3f3f3f3f;//防止后面溢出,这个不能太大 bool vis[MAXN]; int pre[MAXN];typec c... Read More
posted @ 2014-02-09 16:00 laiba2004 Views(158) Comments(0) Diggs(0) Edit
题目以下不是KMP算法——以下是kiki告诉我的方法,好厉害的思维——就是巧用标记,先标记第一个出现的所有位置,然后一遍遍从标记的位置往下找。#include#include#includeusing namespace std;int main(){ int xin,t,i,j,n,ans,id,xiabiao[200010],shunxu; char ch[200010]; scanf("%d",&t); while(t--) { memset(xiabiao,0,sizeof(xiabiao)); scanf("%... Read More
posted @ 2014-01-25 22:39 laiba2004 Views(156) Comments(0) Diggs(0) Edit
题目/******************************************************************/以下题解来自互联网:Juny的博客思路核心:给你的闭包其实就是一个有向图;方法:1,对此图进行缩点,对于点数为n(n>1)的强连通分量最少要 n 条边,对点数为 1 的强连通不需要边,这样计算出边数 m1 ;2,在缩点后的有向无环图中进行反floyd,如果有边a->b,b->c,a->c那么显然a->c可以去掉,就这样一直去除这样的边,直到不能再去为止,算出最终边数 m2;3,m1+m2 即为答案;这样做速度比较慢,但小草还没 Read More
posted @ 2014-01-24 21:56 laiba2004 Views(141) Comments(0) Diggs(0) Edit
题目这是一道可以暴力枚举的水题。//以下两个都可以ac,其实差不多一样,呵呵//1://4 wei shu#includestruct tt{ char a[5],b[5],c[5];}e[110];int main(){ int n,i,count,j,num[5],mark[5],yi,flag,a1,a2,a3,a4; while(scanf("%d",&n),n) { for(i=0;i9)//原来之前是这里细节出错了,要注意哦 num[2]++,num[3]=num[3]%10; ... Read More
posted @ 2014-01-23 23:24 laiba2004 Views(208) Comments(0) Diggs(0) Edit
题目/***************************参考自****************************/http://www.cnblogs.com/newpanderking/archive/2012/10/16/2726757.html上有详细注解,我是看了之后写的,我的代码有一咪咪的改动//这是一道典型的拓扑排序的题,刚开始时没有理解,//上网查了好多关于拓扑排序的知识才明白,//就是针对一个顶点活动网(Activity On Vertex network),简称AOV网,//从中去除入度为0的顶点,同时更新从改点出发引起的入度,//让这些点的入度减1,直到最后如果A Read More
posted @ 2014-01-23 16:12 laiba2004 Views(171) Comments(0) Diggs(0) Edit
这是一道模版题题目#define _CRT_SECURE_NO_WARNINGS#include#include#includeusing namespace std;#define M 100010void init();void build(int u,int v);void solve(int n);void tarjan(int v);struct tt{ int num,next;}edge[M];int dfn[M],low[M],first[M],instack[M],stack[M],index,top,lin,sum;void init(){ index=top... Read More
posted @ 2014-01-23 14:23 laiba2004 Views(180) Comments(0) Diggs(0) Edit