上一页 1 ··· 4 5 6 7 8 9 10 11 12 13 下一页

2012年8月15日

oj2694 逆波兰表达式

摘要: 1 #include<stdio.h> 2 #include<stdlib.h> 3 double exp() 4 { 5 char a[10]; 6 scanf("%s",a); 7 switch(a[0]) 8 { 9 case '+': return exp()+exp();10 case '-': return exp()-exp();11 case '*': return exp()*exp();12 case '/': return exp()/exp();13 def... 阅读全文

posted @ 2012-08-15 19:29 小花熊 阅读(224) 评论(0) 推荐(0) 编辑

poj1979 Red and Black

摘要: 1 #include<stdio.h> 2 char m[20][20]; 3 int r,c,count; 4 void cnt(int i,int j)//统计连续黑砖的块数 5 { 6 if(m[i][j]=='#'||(i<0||j<0)||(i>r-1||j>c-1))//边界条件,除去 7 return; 8 m[i][j]='#';//发现了一个新的黑砖,置'#',下次不在访问 9 count++; //count+110 cnt(i,j-1);//往左寻找 11 cnt(i-1,j);//往上寻 阅读全文

posted @ 2012-08-15 18:13 小花熊 阅读(189) 评论(0) 推荐(0) 编辑

oj2755 神奇的口袋

摘要: 1 #include<stdio.h> 2 int n,a[20]; 3 int cnt(int i,int sum) 4 { 5 if(!sum) return 1;//如果sum等于0,说明前面已经找到一种成功的组合方式,返回1, 6 if(i==n||sum<0) return 0;//i==n,说明找遍了数组a,但没找到符合的,返回0,如果sum<0,此路径不符合,返回0。 7 return cnt(i+1,sum-a[i])+cnt(i+1,sum); 8 } 9 int main()10 {11 scanf("%d",&n);12 阅读全文

posted @ 2012-08-15 17:36 小花熊 阅读(204) 评论(0) 推荐(0) 编辑

poj1664 放苹果

摘要: 1 #include<stdio.h> 2 inline int f(int m,int n)//m代表苹果数,n代表盘子数 3 { 4 if(m==0||n==1) return 1;//当没有苹果可放时,定义为1种放法;当n=1时,所有苹果都必须放在一个盘子里,所以返回1; 5 if(n>m) return f(m,m); 6 return f(m,n-1)+f(m-n,n);//递归的两条路,第一条n会逐渐减少,终会到达出口n==1; 第二条m会逐渐减少,因为n>m时,我们会return f(m,m) 所以终会到达出口m==0. 7 8 } 9 int ma... 阅读全文

posted @ 2012-08-15 17:14 小花熊 阅读(194) 评论(2) 推荐(0) 编辑

nyoj32 组合数

摘要: 1 #include<stdio.h> 2 int a[10]; 3 void f(int n,int r)//r用来记录还有多少数字有待寻找 4 { 5 for(int i=n;i>0;--i){ 6 a[r]=i; 7 if(r>1) 8 f(i-1,r-1);//i-1不能换成n-1,否则会出现前面小于后面的情况,这样才能使得后面的绝对小于前面的 9 else{10 for(int j=a[0];j>0;--j)11 printf("%d",a[j... 阅读全文

posted @ 2012-08-15 16:15 小花熊 阅读(284) 评论(0) 推荐(0) 编辑

nyoj236 心急的C小加

摘要: 1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 struct node{ 5 int l,w; 6 }stick[5001]; 7 bool cmp(node a,node b) 8 { 9 if(a.l!=b.l) return b.l>a.l;10 return b.w>a.w;11 }12 int main()13 {14 int i,j,n,cnt,T;15 cin>>T;16 while(T--)17 {18 for(cin... 阅读全文

posted @ 2012-08-15 12:42 小花熊 阅读(298) 评论(0) 推荐(0) 编辑

nyoj19 擅长排列的小明

摘要: 1 #include<stdio.h> 2 int n,a[10]; 3 bool vis[10];//标示数字是否被用过 4 void f(int k,int m)//k用来给a中第k个元素赋值,m表示还需要寻找的数字个数 5 { 6 for(int i=1;i<=n;++i) 7 { 8 if(!vis[i]) a[k]=i; 9 else continue;//用过的 话找下个数字 10 vis[i]=1;//标志为1,下层递归不再使用 11 if(m>1)//m>1继续寻找12 ... 阅读全文

posted @ 2012-08-15 12:37 小花熊 阅读(240) 评论(0) 推荐(0) 编辑

poj1164 The Castle

摘要: 1 #include<stdio.h> 2 int modules,p[50][50]; 3 bool visit[50][50]; 4 void search(int i,int j) 5 { 6 if(visit[i][j])//已经遍历过,不再遍历 7 return; 8 visit[i][j]=1;//标志已访问 9 modules++;//块数加一 10 if(!(p[i][j]&8))//判断有没有南墙 11 search(i+1,j);12 if(!(p[i][j]&4))//判断有没有东墙 13 ... 阅读全文

posted @ 2012-08-15 10:03 小花熊 阅读(312) 评论(0) 推荐(0) 编辑

2012年8月14日

poj1011 Sticks

摘要: 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 bool anUsed[65]; 7 int L,N,stick[65]; 8 bool cmp(int a,int b) 9 {10 return a>b;11 }12 bool DFS(int nUnusedSticks,int nLeft)13 {14 int i,j,k;15 if(!(nUnusedSticks||nLe 阅读全文

posted @ 2012-08-14 21:10 小花熊 阅读(152) 评论(0) 推荐(0) 编辑

poj1161 Walls

摘要: 1 #include<cstdio> 2 #include<iostream> 3 #define MAX 0xfffffff 4 using namespace std; 5 int m,l; 6 int Area[201][251],G[201][201],People[251],Dist[31]; 7 int Init()//初始化数据 8 { 9 int i,j,k,t;10 for(i=1;i<=l;++i)11 {12 scanf("%d",&t);13 People[t]=i;14 }15 for(i=1... 阅读全文

posted @ 2012-08-14 19:38 小花熊 阅读(303) 评论(0) 推荐(0) 编辑

上一页 1 ··· 4 5 6 7 8 9 10 11 12 13 下一页

导航