上一页 1 2 3 4 5 6 ··· 8 下一页
摘要: 类似于最大子段和的做法View Code #include <stdio.h>int main(){ int i,n,a,b,sum,cnt,max,ar[100005]; while (scanf("%d",&n)!=EOF) { for (i=0;i<n;i++) { scanf("%d%d",&a,&b); ar[i]=a-b; } sum=cnt=0; max=-1; for (i=0;i<2*n-1;i++) { ... 阅读全文
posted @ 2011-12-22 14:27 104_gogo 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 分组背包,学习了!View Code #include <stdio.h>#include <string.h>int dp[105];int max(int a,int b){ return a>b?a:b;}int main(){ int n,m,i,j,k,ar[105][105]; while (scanf("%d%d",&n,&m)!=EOF&&n&&m) { for (i=1;i<=n;i++) { for (j=1;j<=m;j++) { scanf("%... 阅读全文
posted @ 2011-12-20 17:44 104_gogo 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 简单的bfs只是要注意,当楼梯不能通过的时候,可以等带它变过来,这样时间就要加1分钟(位置不变),然后把这个点重新加入队列View Code #include <stdio.h>#include <queue>using namespace std;struct node{ int x,y,t;}a;int n,m,ex,ey;char map[25][25];void bfs(){ int i,row,col,dir[4][2]={0,1,0,-1,1,0,-1,0};//右左下上 char tmp; queue<node> q; a.t=0; q.pus 阅读全文
posted @ 2011-12-20 17:40 104_gogo 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 写的时候思路很清晰,以面对的方向和它的右边为标准,这样写24个方向出来,不过代码量太大了,后来看了别人的思路后,原来可以写的这么简短!不过还是纪念下自己这个又臭又长的代码吧..View Code #include <stdio.h>#define x1 0#define y1 1#define z1 2#define x2 3#define y2 4#define z2 5int x,y,z,a,b,m;char str[10];void h(){ if(a>=3)m=-m; if(a==0||a==3)x+=m; if(a==1||a==4)y+=m; if(a==2... 阅读全文
posted @ 2011-12-15 23:20 104_gogo 阅读(229) 评论(0) 推荐(0) 编辑
摘要: 枚举的思路,只是利用了行压缩来优化View Code #include <stdio.h>#include <string.h>int map[1005][1005],ar[1005];int main(){ int T,m,n,x,y,i,j,k,sum,ans; scanf("%d",&T); while (T--) { scanf("%d%d%d%d",&m,&n,&x,&y); for (i=0;i<m;i++) { for (j=0;j<n;j++) { ... 阅读全文
posted @ 2011-12-15 21:17 104_gogo 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 简单的最长公共子序列的变形,只是题有点吓人..View Code #include <stdio.h>#include <string.h>int dp[2005][2005],ar[2005];int max(int x,int y){ return x>y?x:y;}int main(){ int n,a,len1,len2,i,j; char str[2005],ans1[2005],ans2[2005]; while(scanf("%d",&n)!=EOF) { scanf("%s",str); for (i 阅读全文
posted @ 2011-12-15 21:13 104_gogo 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 把a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 变换成 a1x13+ a2x23+ a3x33=—( a4x43+ a5x53 )这步很重要。这样这个题就变成了,在一个很大的数组里,查找一个数是否存在,存在的话有几个?View Code #include <stdio.h>#include <algorithm>using namespace std;int ar1[1000010],ar2[10010],cnt1,cnt2,ans;void judge(int a){ int i,l=0,r=cnt2,mid; while (l<=r) 阅读全文
posted @ 2011-12-02 11:40 104_gogo 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 由poj 2083想到,从坐标(1,1)到(x,y)都是有公式的,所以只需给每个地方找到对应的公式就好了View Code #include <stdio.h>#include <math.h>#include <string.h>int p;char ch,map[3005][3005],ans[30][30];void dfs(int n,int x,int y){ int i,j,size; if(n==1) { map[y-1][x-1]=ch; return; } size=pow(p*1.0,n-2); for (i=... 阅读全文
posted @ 2011-12-02 11:33 104_gogo 阅读(449) 评论(0) 推荐(0) 编辑
摘要: 注意这个道题的行和列,别混乱了View Code #include <stdio.h>#include <string.h>#include <math.h>char map[3000][3000];void dfs(int n,int x,int y){ int size; if(n==1) { map[x][y]=map[x-1][y+1]='/'; map[x][y+3]=map[x-1][y+2]='\\'; map[x][y+1]=map[x][y+2]='_'; return; } size=po. 阅读全文
posted @ 2011-12-02 11:27 104_gogo 阅读(376) 评论(0) 推荐(0) 编辑
摘要: 今天一共做了3道分形的题,开始没弄对,后面明白解题思想是从1个地方变到n个地方,就很简单了。View Code #include <stdio.h>#include <math.h>int n;char map[1000][1000];void dfs(int n,int x,int y){ int size; if(n==1) { map[x][y] = 'X'; return; } size = pow(3.0,n-2); dfs(n-1,x,y); dfs(n-1,x+2*size,y); dfs(n-1,x+s... 阅读全文
posted @ 2011-12-02 11:25 104_gogo 阅读(192) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 8 下一页