nyist 655 光棍的yy(大数问题)(一)

2014-11-23 21:55:41 · 作者: · 浏览: 21

光棍的yy

时间限制:1000 ms | 内存限制:65535 KB 难度:2
描述

yy经常遇见一个奇怪的事情,每当他看时间的时候总会看见11:11,这个很纠结啊\

现在给你m个1,你可以把2个1组合成一个2,这样就不是光棍了\,问这样的组合有多少种??

例如(111 可以拆分为 111 12 21 有三种)

输入
第一行输入一个n表示有n个测试数据
以下n行,每行输入m个1
(1 <= n,m <= 200)
输出
输出这种组合种数,占一行
样例输入
3
11
111
11111
样例输出
2
3
8
来源
hdu
上传者
yangyin1217


今天从这个题开始就勾起了我做大数的兴趣(这个词用的不够贴切),这个题先前是看到别人写的大数模板,看起来很不错,就果断点进去学习了一番,然后就一直停不下来了,把大数和大精度都复习了一次~

http://blog.csdn.net/y990041769/article/details/19545179 以后我也就用这个模板啦~

#include 
      
       
#include 
       
         #include 
        
          using namespace std; string sum(string a,string b) { if(a.length()
         
          =0;i--,j--) { a[i]=char(a[i]+(j>=0 b[j]-'0':0));//这里写的比较巧妙~值得学习 if(a[i]-'0'>=10) { a[i]=char((a[i]-'0')%10+'0'); if(i) a[i-1]++; else a='1'+a; } } return a; } int main() { int n; scanf("%d",&n); while(n--) { string s; cin>>s; if(s.size()==1) { printf("1\n"); continue; } else if(s.size()==2) { printf("2\n"); continue; } string temp,a,b; a="1",b="2"; for(int i=3;i<=s.size();i++) { temp=sum(a,b); a=b; b=temp; } cout<
          
           

明天在用java写一次吧~,感觉java在这类问题上真的很方便~

以前自己写的算是加法的一个模板吧

 
#include
            
             
#include
             
               int main() { int t,i,j,a[1001],b[1001],c[1001],lenth1,lenth2,n,m=1; char s1[1001],s2[1001]; scanf("%d",&t); while(t--) { n=0; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); scanf("%s%s",s1,s2); lenth1=strlen(s1); lenth2=strlen(s2); n=(lenth1>lenth2) lenth1:lenth2; for(j=0,i=lenth1-1;i>=0;i--) a[j++]=s1[i]-'0'; for(j=0,i=lenth2-1;i>=0;i--) b[j++]=s2[i]-'0'; for(i=0;i
              
               =10)//进位 { c[i+1]=c[i]/10; c[i]%=10; } } printf("Case %d:\n",m++); printf("%s + %s = ",s1,s2); while(n>=0 && !c[n]) n--; //去前导零 while(n>=0) printf("%d", c[n--]); //输出 printf("\n"); } return 0; } 
              
             
            

真的感觉写的好戳啊!!! 写代码能力还有待加强啊!!

还要用java把这道题做一下~(未完)



<script type="text/java script">
<script type="text/java script">BAIDU_CLB_fillSlot("771048");
点击复制链接 与好友分享! 回本站首页
<script> function copyToClipBoard(){ var clipBoardContent=document.title + '\r\n' + document.location; clipBoardContent+='\r\n'; window.clipboardData.setData("Text",clipBoardContent); alert("恭喜您!复制成功"); }
分享到: 更多
<script type="text/java script" id="bdshare_js" data="type=tools&uid=12732"> <script type="text/java script" id="bdshell_js"> <script type="text/java script"> var bds_config = {'snsKey':{'tsina':'2386826374','tqq':'5e544a8fdea646c5a5f3967871346eb8'}}; document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js cdnversion=" + Math.ceil(new Date()/3600000)
您对本文章有什么意见或着疑问吗?请到 论坛讨论您的关注和建议是我们前行的参考和动力
上一篇: 强大的 java 分页器
下一篇: 大精度问题(java)
相关文章
<script type="text/java script">BAIDU_CLB_fillSlot("182716");
<script type="text/java script">BAIDU_CLB_fillSlot("517916");
图文推荐
<iframe src="http://www.2cto.com/uapi.php tid=299000&catid=85&title=bnlpc3QgNjU1ILniufe1xHl5o6i088r9zsrM4qOp&forward=http://www.2cto.com/kf/201405/299000.html" width="100%" height="100%" id="comm