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. ...
随机推荐
- Cocos2d-x中自定义粒子系统
除了使用Cocos2d-x的11种内置粒子系统外,我们还可以通过创建ParticleSystemQuad对象,并设置属性实现自定义粒子系统,通过这种方式完全可以实现我们说需要的各种效果的粒子系统.使用 ...
- 第一章、C#委托和事件(Delegate、Event、EventHandler、EventArgs)
第一章.C#委托和事件(Delegate.Event.EventHandler.EventArgs) 分类: 学习笔记-C#网络编程2012-12-08 14:10 7417人阅读 评论(3) 收藏 ...
- (转)使用SVN+CruiseControl+ANT实现持续集成之一
在前面的文章中, 介绍自己当时所在团队的处境(使用.NET开发),一个不到十个人的研发团队在保证正常开发进度同时需要并发支持四.五十个项目问题处理,经常为了程序版 本冲突.日常测试版本.发布版本提供等 ...
- css3学习笔记之渐变
CSS3 线性渐变 语法 background: linear-gradient(direction, color-stop1, color-stop2, ...); 1 2 3 4 5 6 7 8 ...
- Spring boot 1.3.5 RELEASE 官方文档中文翻译--Part2:新手入门
Part II. 新手入门 如果你刚刚开始学习Spring boot或"普通"的Spring,这部分非常适合你!在这里,我们回答了最基础的"什么是?".&quo ...
- VS代码模板
Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\Csharp\Code\2052\Class
- 对整站的a链接进行监控,对匹配规则进行指定页面的跳转
项目中有个需求,就是将非本站的链接跳转到过渡页(提示即将离开本站的那种页面).这个时候想起了腾讯邮箱,不安全链接会有新的页面提示,如下图: 本以为ASP.NET中有全局的方法获取到点击或者跳转的链接, ...
- PHP 魔术方法 __isset __unset (三)
慢慢长寻夜,明月高空挂 __isset() - 在对类中属性或者非类中属性使用isset()方法的时候如果没有或者非公有属性,则自动执行__isset()的方法 __unset() - 在对类中属性 ...
- CCNA第一讲笔记
园区网:一组连续的局域网(校园网.企业内部网) 园区网拓扑: 一层楼的PC连接到一台交换机(同一层的PC可以互联):一栋楼的每层的交换机连接到同一台交换机(整栋楼的PC可以互联):每栋楼的交换机连接到 ...
- java 读写锁
http://tutorials.jenkov.com/java-concurrency/read-write-locks.html 翻译 读写锁比LOCK的实现更复杂,想象有一个应用程序能读和写一些 ...