上一页 1 ··· 27 28 29 30 31 32 33 34 35 ··· 42 下一页
摘要: 题意:从起点到终点bfs即可注意P的作用:一遇到P即将所有的P进队。View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #include<queue> 5 #include<algorithm> 6 using namespace std; 7 const int maxn = 5005; 8 const int inf=999999; 9 char mat[ maxn ][ maxn ];10 bool vis[ maxn ][ maxn 阅读全文
posted @ 2013-01-29 14:16 xxx0624 阅读(311) 评论(0) 推荐(1) 编辑
摘要: 题意:整数划分问题是将一个正整数n拆成一组数连加并等于n的形式,且这组数中的最大加数不大于n。View Code 1 #include<stdio.h> 2 const int maxn = 124; 3 int dp[ maxn ][ maxn ]; 4 int main(){ 5 for( int i=0;i<maxn;i++ ){ 6 //dp[ 0 ][ i ]=dp[ i ][ 0 ]=0; 7 dp[ 1 ][ i ]=dp[ i ][ 1 ]=1; 8 } 9 for( int i=2;i<=120;i++ ){10 ... 阅读全文
posted @ 2013-01-29 10:13 xxx0624 阅读(484) 评论(0) 推荐(0) 编辑
摘要: 题意:求N个数全排列,顺着数第M个调用函数即可快速搞定。View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 using namespace std; 6 const int maxn = 1002; 7 int num[ maxn ]; 8 int main(){ 9 int n,m;10 while( scanf("%d%d",&n,&m)!=EOF ){11 mem 阅读全文
posted @ 2013-01-29 09:31 xxx0624 阅读(838) 评论(0) 推荐(0) 编辑
摘要: 题意:从起点到终点,输出路径长度,时间。bfs+记录路径View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #include<queue> 5 const int N = 105; 6 const int inf = 9999999; 7 using namespace std; 8 9 struct node{ 10 int x,y; 11 }; 12 node p,pp,path[N][N]; 13 struct node2{ 14 int x1, 阅读全文
posted @ 2013-01-29 09:28 xxx0624 阅读(541) 评论(0) 推荐(0) 编辑
摘要: 题意简单View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<math.h> 4 #include<algorithm> 5 using namespace std; 6 const int maxn = 1005; 7 char s[ maxn ]; 8 char ch[ maxn ]; 9 int mm[ maxn ];10 int main(){11 while( scanf("%s",ch)!=EOF ){12 int len;13 len=strl 阅读全文
posted @ 2013-01-29 09:24 xxx0624 阅读(237) 评论(0) 推荐(0) 编辑
摘要: 经典问题走的方向确定,如dir[][]所示。bfs 当搜到终点跳出View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #include<algorithm> 5 #include<queue> 6 using namespace std; 7 const int maxn = 10; 8 int mat[ maxn ][ maxn ]; 9 const int dir[8][2]={{2,1},{2,-1},{1,-2},{1,2},{-2 阅读全文
posted @ 2013-01-28 21:30 xxx0624 阅读(226) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include 2 #include 3 using namespace std; 4 const int maxn = 1005; 5 int a[ maxn ],dp[ maxn ];//dp[i]表示以a[i]结尾的子序列的和最大 6 int main(){ 7 int n; 8 while( scanf("%d",&n)!=EOF && n ){ 9 for( int i=0;i<n;i++ )10 scanf("%d",&a[ i ]);11 int ans=a[ 0 ];12 . 阅读全文
posted @ 2013-01-28 21:06 xxx0624 阅读(316) 评论(0) 推荐(0) 编辑
摘要: 将二维转化为一维。第一个FOR循环用于枚举 行,第二个和第三个FOR 用于求从当前行(J)开始的每一个矩阵方块和,从而得到ANS。View Code 1 #include<stdio.h> 2 #include<algorithm> 3 using namespace std; 4 const int maxn = 105; 5 int a[ maxn ][ maxn ],temp[ maxn ]; 6 int n; 7 8 int dp( ){ 9 int ans=temp[ 0 ];10 int tmp_sum=0;11 for( int i=0;i<n;i+ 阅读全文
posted @ 2013-01-28 20:46 xxx0624 阅读(283) 评论(0) 推荐(0) 编辑
摘要: 详见代码View Code 1 /* 2 改变一个点,询问区间和 3 线段树 4 */ 5 #include<stdio.h> 6 #define lson l , mid , rt << 1 7 #define rson mid + 1 , r , rt << 1 | 1 8 const int maxn = 50005; 9 int sum[ maxn<<2 ],data[ maxn ];10 11 void PushUp( int rt ){12 sum[ rt ]=sum[ rt<<1 ]+sum[ rt<<1 | 阅读全文
posted @ 2013-01-28 17:34 xxx0624 阅读(483) 评论(0) 推荐(0) 编辑
摘要: lazy思想当一个数开了6到7次根号时,就变成1了。View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #include<algorithm> 5 #include<math.h> 6 using namespace std; 7 typedef __int64 int64; 8 #define L( x ) (x<<1) 9 #define R( x ) ((x<<1)+1)10 const int64 maxn 阅读全文
posted @ 2013-01-28 17:32 xxx0624 阅读(1876) 评论(0) 推荐(0) 编辑
上一页 1 ··· 27 28 29 30 31 32 33 34 35 ··· 42 下一页