POJ2389 Bull Math
- /*
- POJ2389 Bull Math
- http://poj.org/problem?id=2389
- 高精度乘法
- *
- */
- #include <cstring>
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- const int Nmax=;
- struct BigInt
- {
- int a[Nmax];
- int n;
- void init()
- {
- for(int i=;i<Nmax;i++)
- a[i]=;
- }
- BigInt()
- {
- init();
- n=;
- }
- BigInt(int _a[],int _n)
- {
- init();
- n=_n;
- //for(int i=0;i<Nmax;i++)
- //a[i]=0;
- for(int i=;i<=n;i++)
- a[i]=_a[i];
- maintain();
- }
- BigInt(char s[])
- {
- init();
- n=strlen(s+);
- for(int i=;i<=n;i++)
- a[i]=s[n-i+]-'';
- maintain();
- }
- BigInt(long long x)
- {
- init();
- n=;
- while(x>0LL)
- {
- a[++n]=x%10LL;
- x/=10LL;
- }
- }
- BigInt(int x)
- {
- init();
- n=;
- while(x>)
- {
- a[++n]=x%;
- x/=;
- }
- }
- void read()
- {
- init();
- n=;
- char c=getchar();
- if(c==-)
- return;
- while(c==' ' || c=='\n' )
- {
- c=getchar();
- if(c==-)
- break;
- }
- int num[Nmax];
- while(c!=' ' && c!='\n' && c!=-)
- {
- num[++n]=c-'';
- c=getchar();
- }
- for(int i=;i<=n;i++)
- a[i]=num[n-i+];
- maintain();
- }
- void print()
- {
- if(n==)
- printf("");
- for(int i=n;i>=;i--)
- printf("%d",a[i]);
- }
- void maintain()
- {
- for(int i=;i<=n;i++)
- {
- a[i+]+=a[i]/;
- a[i]%=;
- }
- int j=n+;
- while(a[j]!=)
- {
- a[j+]+=a[j]/;
- a[j]%=;
- j++;
- }
- n=j-;
- while(a[n]== && n>)
- n--;
- }
- friend BigInt operator + (BigInt a,BigInt b)
- {
- int len=max(a.n,b.n);
- BigInt ans;
- ans.n=len;
- for(int i=;i<=len;i++)
- ans.a[i]=a.a[i]+b.a[i];
- ans.maintain();
- return ans;
- }
- //friend BigInt operator - (BigInt a,BigInt b)
- //{
- //int len=max(a.n,b.n);
- //BigInt ans;
- //ans.n=len;
- //for(int i=1;i<=len;i++)
- //ans.a[i]=a.a[i]-b.a[i];
- //for(int i=1;i<=len;i++)
- //{
- //if(ans.a[i]<0)
- //{
- //ans.a[i]+=10;
- //a.a[i+1]--;
- //}
- //ans.a[i]+=10
- //}
- //}
- friend BigInt operator * (BigInt b,int a)
- {
- int n=b.n;
- BigInt ans;
- ans.n=n;
- for(int i=;i<=n;i++)
- ans.a[i]=b.a[i]*a;
- ans.maintain();
- return ans;
- }
- friend BigInt operator * (int a,BigInt b)
- {
- int n=b.n;
- BigInt ans;
- ans.n=n;
- for(int i=;i<=n;i++)
- ans.a[i]=b.a[i]*a;
- ans.maintain();
- return ans;
- }
- friend BigInt operator * (BigInt a,BigInt b)
- {
- BigInt ans;
- ans.n=a.n+b.n+;
- int k;
- for(int i=;i<=a.n;i++)
- for(int j=;j<=b.n;j++)
- ans.a[j+i-]+=a.a[i]*b.a[j];
- ans.maintain();
- return ans;
- }
- };
- int main()
- {
- char s[];
- char s1[];
- BigInt a,b;
- //freopen("test.in","r",stdin);
- a.read();
- b.read();
- (a*b).print();
- printf("\n");
- return ;
- }
POJ2389 Bull Math的更多相关文章
- POJ2389 Bull Math【大数】
Bull Math Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15040 Accepted: 7737 Descri ...
- Poj OpenJudge 百练 2389 Bull Math
1.Link: http://poj.org/problem?id=2389 http://bailian.openjudge.cn/practice/2389/ 2.Content: Bull Ma ...
- BZOJ1754: [Usaco2005 qua]Bull Math
1754: [Usaco2005 qua]Bull Math Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 374 Solved: 227[Submit ...
- 1754: [Usaco2005 qua]Bull Math
1754: [Usaco2005 qua]Bull Math Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 398 Solved: 242[Submit ...
- POJ 2389 Bull Math(水~Java -大数相乘)
题目链接:http://poj.org/problem?id=2389 题目大意: 大数相乘. 解题思路: java BigInteger类解决 o.0 AC Code: import java.ma ...
- BZOJ 1754: [Usaco2005 qua]Bull Math
Description Bulls are so much better at math than the cows. They can multiply huge integers together ...
- [PKU2389]Bull Math (大数运算)
Description Bulls are so much better at math than the cows. They can multiply huge integers together ...
- poj 2389.Bull Math 解题报告
题目链接:http://poj.org/problem?id=2389 题目意思:就是大整数乘法. 题目中说每个整数不超过 40 位,是错的!!!要开大点,这里我开到100. 其实大整数乘法还是第一次 ...
- 【BZOJ】1754: [Usaco2005 qua]Bull Math
[算法]高精度乘法 #include<cstdio> #include<algorithm> #include<cstring> using namespace s ...
随机推荐
- ubuntu14.04 安装LNMP
新书上市<深入解析Android 5.0系统> 通常我们使用centos来组建LNMP,可是我们开发时多使用ubuntu的桌面版本号来调试,以下将具体介绍怎样在ubuntu上安装一套LNM ...
- 轻快的VIM(五):复制
操作相同文本的时候复制尤其有效,在Windows中我们都习惯了先用鼠标选择文本 而Vim下则不用那么麻烦,你甚至可以使用可视模式操作,但这里先略过 我在这一节主要说说命令模式下的复制 在讲复制之前我要 ...
- 0x59 单调队列优化DP
倍增DP太难啦心情好再回去做 poj1821 先让工匠按s排序,f[i][j]表示枚举到第i个工匠涂了j个木板(注意第j个木板不一定要涂) 那么f[i][j]可以直接继承f[i-1][j]和f[i][ ...
- ReflectionSugar 通用反射类
http://www.cnblogs.com/sunkaixuan/p/4635710.html
- js 对象方法、类方法、原型方法区别
function People(name){this.name=name;//对象方法this.Introduce=function(){alert("My name is "+t ...
- java中的访问修饰符2
综上所述:protected强调的是子类,deafult强调的是本包,private强调的是本类,public强调的是开放性.
- 大数据查询——HBase读写设计与实践--转
背景介绍 本项目主要解决 check 和 opinion2 张历史数据表(历史数据是指当业务发生过程中的完整中间流程和结果数据)的在线查询.原实现基于 Oracle 提供存储查询服务,随着数据量的不断 ...
- 豆瓣项目(用react+webpack)
用豆瓣电影api的项目 电影列表组件渲染 步骤: 1. 发送Ajax请求 1.1 在组件的componentWillMount这个生命周期钩子中发送请求 1.2 发送ajax XMLHttpReque ...
- rem简单实现移动端适配
rem:移动web开发 默认字体大小是16px 在<html>中设置字体大小 与em的区别: em是在父级设置字体大小受影响 移动端适配 首先获取屏幕的宽度 计算当前屏幕宽度和640的比例 ...
- Android 拍照图片选取与图片剪裁
最近从以前的项目中扒下来一个常用的模块,在这里有必要记录一下的,就是android上获取图片以及裁剪图片,怎么样?这个功能是不是很常用啊,你随便打开一个App,只要它有注册功能都会有设置人物头像的功能 ...