摘要: 思路:blleman—ford检验负回路代码:#include#include#includeusing namespace std;struct infor{ int from; int to; double r; double c;};infor es[20008];double dis[200],v;int enu,n,s;bool bellman(){ memset(dis,0,sizeof(dis)); dis[s]=v; for(int i=0;i>n>>m>>s>>v; for(int i=0;i>a>>b>> 阅读全文
posted @ 2013-11-08 17:16 Neptunes 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 思路:bellman-ford检验正回路代码:#include#include#includeusing namespace std;struct infor{ int from; int to; double r; double c;};infor es[20008];double dis[200],v;int enu,n,s;bool bellman(){ memset(dis,0,sizeof(dis)); dis[s]=v; for(int i=0;i>n>>m>>s>>v; for(int i=0;i>a>>b>> 阅读全文
posted @ 2013-11-08 17:10 Neptunes 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 思路:Dijkstra代码:#include#include#include#includeusing namespace std;struct infor{ int x; int y;};int t,n=0;infor stone[202];double d(int x,int y){ return sqrt(x*x+y*y);}double dis[201];double map[202][202];bool visit[202];using namespace std;void dijkstra(){ while(true){ double m=10... 阅读全文
posted @ 2013-11-08 17:07 Neptunes 阅读(195) 评论(0) 推荐(0) 编辑
摘要: #include#include#includeusing namespace std;struct edge{ int from,to,cost;};struct vertex{ int value,rank;};const int Max=110;const int INF=0x7fffffff;edge es[Max*Max];vertex v[Max];int dist[Max],en=1;int ans=0x7fffffff;void bellman(int n, int m){ int i; dist[0]=0; while(true){ ... 阅读全文
posted @ 2013-11-07 17:39 Neptunes 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 题意: 一直一个有序数组,给定一个数字n代表已知数组的第n个数,求该书是几。分析: 1,根据数组规律对其分组:1 12 123 1234 12345...... 2,首先求n在第几组中,再求n在其分组的第几个数中同时我们也可求得是该书的第几位。 3,我们分得的数组中数字依次变大,位数越来越多,但我们是要按照每一个数字来计算位置信 息。比如:123(一百二十三)是三个数,所以们就用到 log10求得其位数。 1 #include 2 #include 3 using namespace std; 4 #define size 31269 5 unsigned a[s... 阅读全文
posted @ 2013-10-17 21:52 Neptunes 阅读(182) 评论(0) 推荐(0) 编辑
摘要: *题意:在给定的方格中,按照只能向右向上的格式,求有几种方式可以从左下方到右上方。分析:根据方格的规模,m×n,肯定向右m次,向上n次,所以问题转化为从m+n步中选取m步向右(剩余的n步 自然向上)。在求组合是尽量简化运算。*代码: 1 #include 2 #include 3 #include 4 using namespace std; 5 int main() 6 { 7 long long int a,b,m,n,ans,count; 8 while(cin>>a>>b) 9 {10 if(a==0&&b==0)11 bre... 阅读全文
posted @ 2013-10-17 21:32 Neptunes 阅读(200) 评论(0) 推荐(0) 编辑
摘要: *题意:给定一定的金额cash,在给出n中货币,每种货币有一定的数量。问:在不超过cash的条件下,用给定货币组成最接近cash的金额数是多少。*思路:完全背包问题+数量限制。要实现并不困难,不过由于数据较大,以上思路有三重循环会TLE。所以,必须优化。至于优化,可以选择二进制优化,或者把循环去掉一层。1.二进制优化是把物品个数用二进制数表示出来,以减少循环次数。2.去掉物品书的那层循环:因为我们在计算dp[i+1][j],枚举物品数量k>=1的情况时,与在计算dp[i+1][j-d[i]],枚举的k>0的情况恰好相同,所以我们可以不用在用到k循环达到优化的效果。 1 #inclu 阅读全文
posted @ 2013-10-16 12:35 Neptunes 阅读(195) 评论(0) 推荐(0) 编辑
摘要: *题意:给定三维迷宫,能走出来就输出最短用时,走不出输出*代码:#include#include#includeusing namespace std;char maze[31][31][31];bool visit[31][31][31];int queue[28000][3];int time[31][31][31];int l,c,r;int dir[6][3]={{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};void bfs(int start[3],int end[3]){ int i,k,front=0,back=1,... 阅读全文
posted @ 2013-10-03 15:46 Neptunes 阅读(159) 评论(0) 推荐(0) 编辑
摘要: *题意: 给定一定的金额cash,在给出n中货币,每种货币有一定的数量。问:在不超过cash的条件下,用给定货币组成最接近cash的金额数是多少。*思路: 完全背包问题+数量限制。要实现并不困难,不过由于数据较大,以上思路有三重循环会TLE。所以,必须优化。至于优化,可以选择二进制优化,或者把循环去掉一层。 1.二进制优化是把物品个数用二进制数表示出来,以减少循环次数。 2.去掉物品书的那层循环:因为我们在计算dp[i+1][j],枚举物品数量k>=1的情况时,与在计算dp[i+1][j-d[i]],枚举的k>0的情况恰好相同,所以我们可以不用在用到k循环达到优化的效果。二维数.. 阅读全文
posted @ 2013-09-28 21:43 Neptunes 阅读(308) 评论(0) 推荐(0) 编辑
摘要: *题意: 给定所需珍珠的数量与其相应的价格,计算最小的花费。假如要买某种价格的珍珠必须先额外买10颗,可 以用价格高的替代价格低的。(因此才需要计算最小值)。 比如:某种珍珠价格p,要买q颗,则花费为:(q+10)*p。再比如:价格100的需要1颗,价格150的需要100颗。买两种珍珠共需要100*(10+1)+150*(100+10)=17600.假如我们用150的代替100的,需要150*(101+10)=16650.显然后者省钱。*思路: 动态规划。 用sum[i]存储到第i种珍珠时珍珠的总量,dp[i]存储第i种珍珠是最优的购买方式,p[i]是价格,q[i]是数 量。 ... 阅读全文
posted @ 2013-09-24 21:32 Neptunes 阅读(279) 评论(0) 推荐(0) 编辑