随笔分类 -  OpenJudge百练OJ

编程实现x的y次方的最后三位数(x与y至少是两位数以上)
摘要:Sample Input: 13**13(以两个**代表次方) 13**20Sample Output: 253 801 1 #include <stdio.h> 2 int main() 3 { 4 int x,y,i,h; 5 while(scanf("%d%d",&x,&y)!=-1) 6 { 7 8 x=x%1000; 9 for(h=1,i=0;i<y;i++)10 {11 12 h*=x;13 h%=1000;... 阅读全文

posted @ 2012-12-15 21:59 mycapple 阅读(871) 评论(1) 推荐(0)

三天打鱼两天晒网
摘要:题目描述:中国有句俗语叫“三天打鱼两天晒网”。某人从1990年1月1日起开始“三天打鱼两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”。Sample Input: Enter year/month/day:1991 10 25 Enter year/month/day:1992 10 25 Enter year/month/day:2011 12 10Sample Output:He was fishing at day. He was sleeping at day. He was sleeping at day问题分析与算法设计根据题意可以将解题过程分为三步:1)计算... 阅读全文

posted @ 2012-12-15 21:10 mycapple 阅读(993) 评论(2) 推荐(2)

删数问题(典型的贪心算法问题)
摘要:题目:键盘输入一个高精度的正整数n(<=240位),去掉任意s个数字后剩下的数字按原左右次序将组成一个新的正整数。编程对给定的n和s,寻找一种方案,使得剩下的数最小。Simple Input1785434Simple Output13思路:每一步总是选择一个使剩下的数最小的数字删除,即按高位到低位的顺序搜索,若各位数字递增,则删除最后一个数字;否则删除第一个递减区间的首字符,这样删一位便形成了一个新的数字串。然后回到串首,按上述规则再删除下一个数字参考借鉴代码1如下: 1 #include<iostream> 2 #include<string> 3 using 阅读全文

posted @ 2012-08-23 11:58 mycapple 阅读(21358) 评论(2) 推荐(2)

OpenJudge 803 逆波兰表达式
摘要:地址:http://nenu.openjudge.cn/09jiaoji/803/思路:递归,分治 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 double exp() 5 { 6 char a[10]; 7 scanf("%s",a); 8 switch(a[0]) 9 {10 case '+': return exp()+exp();11 case '-': return exp()-exp();12 case '* 阅读全文

posted @ 2012-08-15 16:56 mycapple 阅读(296) 评论(0) 推荐(0)

OpenJudge 2973 Skew数
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int i,s,t,sum; 5 char skew[32]; 6 while(scanf("%s",skew)) 7 { 8 for(sum=t=i=0;skew[i];i++) 9 {10 sum=(sum<<1)+skew[i]-'0';11 t+=skew[i]-'0';12 }13 sum=(sum<<1)-t;14 if(!sum) break... 阅读全文

posted @ 2012-08-02 16:10 mycapple 阅读(284) 评论(0) 推荐(0)

OpenJudge 2972 确定进制
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 char p[32],q[32],r[32]; 4 int MinRadix()//找出最低限的进制 5 { 6 int i,minRadix; 7 minRadix=1; 8 for(i=0;p[i];i++)//找出p[i]最大的数 9 if(minRadix<p[i]-'0') minRadix=p[i]-'0';10 for(i=0;q[i];i++)11 if(minRadix<q[i]-'0') minRadix= 阅读全文

posted @ 2012-08-02 16:09 mycapple 阅读(445) 评论(0) 推荐(0)

OpenJudge 2742 约瑟夫问题 2
摘要:1 #include <stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 int n, m, i,s; 6 while(scanf("%d%d",&n,&m)&&(n||m)) 7 { s=0; 8 for (i=2;i<=n;i++) s=(s+m)%i; 9 printf ("%d\n", s+1);10 }11 //system("pause");12 return 0;13 }2.问题描述:n个人(编号1~n),从1开 阅读全文

posted @ 2012-08-02 16:07 mycapple 阅读(403) 评论(0) 推荐(0)

OpenJudge 2746 约瑟夫问题 1
摘要:1 #include<stdio.h> 2 typedef struct Node 3 { 4 int data; 5 Node *next; 6 Node(int i){ //Node函数 7 data=i; 8 next=NULL; 9 }10 }node;11 int main()12 {13 int i,m,n;14 node *head,*p,*q;15 while(scanf("%d%d",&n,&m),m||n)16 {17 if(m==1) ... 阅读全文

posted @ 2012-08-02 16:05 mycapple 阅读(427) 评论(0) 推荐(0)

导航