摘要:#include<iostream>#include<queue>#include<algorithm>#include<stdio.h>#include<cstring>using namespace std;/*题意:马里奥要从A+B出的城堡走到1处的村庄,途中他可以使用boot,从任意i处到达j处,但是i与j的距离不能超过L,且使用boot的次数不能多于K次,而且在使用时 遇到城堡就要停下来,而且只能在村庄或城堡开始或停止使用boot,求从A+B到1所用的最短时间*/int A,B,M,L,K,ANS;const int INF
阅读全文
摘要:#include<iostream>#include<queue>#include<algorithm>#include<cstring>using namespace std;int n,g[101][101],d[101];const int INF=10000000;int broken;int spfa(int x){ queue <int > q; q.push(x); bool inq[101]; memset(inq,0,sizeof(inq)); for(int i=1;i<=n;i++)d[i]=(i==x?0
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=85zju Alien Security spfa#include<iostream>#include<algorithm>#include<string>#include<cstring>#include<queue>using namespace std;const int INF=1000000;int vis[101],g[101][101],d[101];int n,ET;//ET目标房间void spfa(
阅读全文
摘要:#include<string>#include<set>#include<iostream>#include<cstring>using namespace std;/*题意:根据已有的变量关系能否推出别的变量关系(条件中已给出的滤去,若推不出别的关系输出NONE)传递闭包*/int small[30][30],vis[30][30],hash[30][30];//vis[][]标记关系在输入中已给出,hash[][]表示关系已在DFS中得到 set <string> ans; void DFS(int x,int cet){ fo
阅读全文
摘要:#include<iostream>#include<string>#include<cstring>#include<map>using namespace std;int key[100];string ans;map <char,int> m;map <char,string> c;map <string,char> d;void set(){ m['A']=2;m['B']=4,m['C']=4,m['D']=3,m['E'
阅读全文
摘要:割点算法example1 21 31 42 52 63 73 84 94 80下面是算法运行过程 from 1 enter to the adj ares 2from 2 enter to the adj ares 5end 5return 2 is a cut node ,find subnet 1from 2 enter to the adj ares 6end 6return 2 is a cut node ,find subnet 2end 2from 1 enter to the adj ares 3from 3 enter to the adj ares 7end 7return
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=60拓扑排序0度>1多解0度==1正常0度==0矛盾#include<iostream>#include<stdio.h>#include<queue>#include<string>#include<algorithm>#include<cstring>using namespace std;int vis[30],d[30],adj[30][30];int m,n,flag,ok,pos;stri
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=311割点算法《算法与艺术信息学竞赛》P285建立在DFS的基础上#include<iostream>#include<cstring>#include<vector>#include<algorithm>#include<stdio.h>#include<string>#include<sstream>using namespace std;int n,m,k,ans,d[101],ances
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1050位运算+BFS^运算表示 翻转#include<iostream>#include<string>#include<queue>#include<cstring>using namespace std;int vis[(1<<16)+1],dir[5][2]={1,0,-1,0,0,1,0,-1,0,0};int ANS;struct node{ int step,key;};node fir;string m
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1072题目难点在于标记 状态vis[x][y][time] 表示在倒计时为time时走到了(x,y)处优先队列+BFS#include<iostream>#include<stdio.h>#include<queue>#include<cstring>using namespace std;int cas,n,m;int map[10][10],vis[10][10][7],dir[4][2]={1,0,-1,0,0,1,0,-1},ans;struct nod
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1475水水的拓扑的一部分事先看别人的解题报告再做的,注意测试数据里有 a b,#include<iostream>#include<cstring>using namespace std;int n,m,f,tar,ans,ok;int g[105][105],vis[105];void topo(int x){ if(!ok)return; vis[x]=1; for(int i=1;i<=n;i++) { if(g[x][i]) { if(v
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1741只能用一个词来形容--“恶心”数据里有double#include<iostream>#include<stdio.h>#include<string>#include<vector>#include<sstream>using namespace std;struct node{ double x,y;};node change(string s){ node a; int it=s.find(',&
阅读全文
摘要:dp[i][j]表示在第i段赛道能量为j时所耗最短时间(i=0为第一段)#include<iostream>#include<stdio.h>#include<algorithm>using namespace std;int m,n,ans;int t1[111],t2[111],t3[110],f1[111],f2[111],dp[111][111];const int INF=100000000;int main(){ int cas; scanf("%d",&cas); while(cas--) { scanf("
阅读全文
摘要:DFS 题意:相邻的节点不能都涂成黑色,问是黑色节点最多的方案(只能选择黑和白)#include<iostream>#include<cstring>#include<stdio.h>using namespace std;int G[101][101],black[101],ANS[101];int n,m,ans;void DFS(int cur,int w)//cur当前要处理的节点,当前已有白色节点个数{ if(w>=n-ans)return;//白色节点多于最优情况下白色节点时 if(cur==n+1) { ans=n-w; for(int
阅读全文
摘要:求输出所有 含h个1的且长度为n的01串可重集全排列 集合为{1,0} #include<iostream>#include<stdio.h>using namespace std;int cas,n,h;int tmp[17];void DFS(int cur,int num){ if(num>h)return; if(cur==n) { if(num==h) { for(int i=0;i<n;i++) printf("%d",tmp[i]); printf("\n"); } return; } for(int i
阅读全文
摘要:http://acm.zjut.edu.cn/ShowProblem.aspx?ShowID=1624这是去年校赛得题目,作为当时的fresh man我们水水地硬是人工枚举把答案暴力出来了,今天回过头来写,感觉大不一样了!一道简单的DFS#include<iostream>using namespace std;int n,num;void dfs(int k,int tmp,int last,int c)//k表示接下来要在k与k+1中间进行处理,tmp当前获得值,last表示最后一次加上或减去的数,c表示最后一次进行的运算 ,1表示‘+’,0表示‘-’ { if(n==k){i
阅读全文