ural 1108
大数乘法 不会java 比赛的时候各种细节RE WA ........
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
int un[] = {0,0,0,0,0,1,3,6,13,26,52,104,208,416,833,1667,3335,6700};
int a[10010],b[10010],c[10010],ca;
void cc()
{
int w = 0;
memset(c, 0, sizeof(c));
for(int i = 0; i <= un[ca]; i++)
{
for(int j = 0; j <= un[ca]; j++)
{
c[i+j] += a[i]*b[j];
if(c[i+j] > 9999)
{
w = c[i+j]/10000;
c[i+j+1] += w;
c[i+j] %= 10000;
}
}
}
w = 0;
for(int i = 0; i <= un[ca]; i++)
{
c[i] += w;
w = c[i]/10000;
c[i] %= 10000;
}
memcpy(a, c, sizeof(c));
c[0] += 1;
memcpy(b, c, sizeof(c));
}
int main()
{
int n;
scanf("%d",&n);
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
a[0] = 1;
b[0] = 2;
ca = 0;
for(int i = 0; i < n; i++)
{
int j;
for(j = un[ca]; j >= 0; j--)
{
if(b[j])
break;
}
//printf("%d\n",j);
printf("%d",b[j--]);
for(; j >= 0; j--)
{
printf("%.4d",b[j]);
}
putchar('\n');
if(i == n-1)
break;
cc();
ca++;
}
return 0;
}
ural 1108的更多相关文章
- URAL 1108 简单的树形dp背包问题
题目大意: 一颗苹果树上,每条边都对应了一个权值,最后留下包括root : 1在的含有 m 条边的子树 , 希望留下的子树中权值之和最大 这里保留m条边,我们可以看作是保留了 m + 1 个点 令dp ...
- NOIopenjudge 407:Heritage
总时间限制: 5000ms 内存限制: 65536kB 描述 Your rich uncle died recently, and the heritage needs to be divided ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- ural 2068. Game of Nuts
2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...
- ural 2067. Friends and Berries
2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...
随机推荐
- WCF简介
WCF(Windows communication Foundation),顾名思义,就是在windows平台下解决通信的基础框架.WCF做为.NET Framework 3.0的一个组件发布出来的, ...
- Jquery中bind和live的区别
Jquery中绑定事件有三种方法:以click事件为例 (1)target.click(function(){}); (2)target.bind("click",function ...
- jFinal中报对应模型不存在的错误(The Table mapping of model: demo.User not exists)
jFinal中报对应模型不存在的错误(The Table mapping of model: demo.User not exists) 贴出错误: java.lang.RuntimeExceptio ...
- docker & nodejs
Docker 部署 Node js demo程序 1.准备node js程序,使用express框架. mkdir demo 在demo文件夹下建立package.json { "name& ...
- CCM加密学习
这几天终于搞定了AES硬件加密工具的使用,几种简单的加密模式也都实验通过了,比较麻烦的一种是CCM模式的加密,它是CTR加密模式和CMAC认证算法的混合使用.本文先介绍CCM模式的原理与基本实现,然后 ...
- urllib2.urlopen超时
urllib2.urlopen设置超时,可以解决read方法阻塞的问题 urllib2.urlopen(‘xxx’,timeout=30)
- Web前端新人笔记之了解Jquery
与javaScript相比,Jquery更简洁.浏览器的兼容性更强,语法更灵活,对xpath的支持更强大.一个$符就可以遍历文档中各级元素.例:在页面上有一个无序列表,我们需要将所有列表项中的文本内容 ...
- webuploader上传插件
一:官网 http://fex.baidu.com/webuploader/ 二:示例
- 开发问题记录——AE开发提示80040111错误
System.runtime.interpServices.ComException(0X80040111): 80040111 ClassFactory无法供应请求的类(异常来自HRESULT:0X ...
- jQueryr .on方法解析
.On() 其实.bind(), .live(), .delegate()都是通过.on()来实现的,.unbind(), .die(), .undelegate(),也是一样的都是通过.off()来 ...