BZOJ 1754: [Usaco2005 qua]Bull Math
Description
Bulls are so much better at math than the cows. They can multiply huge integers together and get perfectly precise answers ... or so they say. Farmer John wonders if their answers are correct. Help him check the bulls' answers. Read in two positive integers (no more than 40 digits each) and compute their product. Output it as a normal number (with no extra leading zeros). FJ asks that you do this yourself; don't use a special library function for the multiplication. 输入两个数,输出其乘积
Input
* Lines 1..2: Each line contains a single decimal number.
Output
* Line 1: The exact product of the two input lines
题解:
高精度乘法即可。
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
//by zrt
//problem:
using namespace std;
char a[105],b[105];
int c[105];
int la,lb;
int cc;
int stk[105],top;
int main(){
#ifdef LOCAL
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
scanf("%s%s",a,b);
la=strlen(a);
lb=strlen(b);
for(int i=0;i<la;i++) a[i]-='0';
for(int i=0;i<lb;i++) b[i]-='0';
for(int i=0;i<la/2;i++) swap(a[i],a[la-i-1]);
for(int i=0;i<lb/2;i++) swap(b[i],b[lb-i-1]);
for(int i=0;i<la;i++){
for(int j=0;j<lb;j++){
c[i+j]+=a[i]*b[j];
}
}
for(int i=0;i<=100;i++){
stk[top++]=(c[i]+cc)%10;
cc=(c[i]+cc)/10;
}
while(stk[top-1]==0) top--;
while(top){
printf("%d",stk[--top]);
}
puts("");
return 0;
}
BZOJ 1754: [Usaco2005 qua]Bull Math的更多相关文章
- bzoj 1754: [Usaco2005 qua]Bull Math【高精乘法】
高精乘法板子 然而WA了两次也是没救了 #include<iostream> #include<cstdio> #include<cstring> using na ...
- 1754: [Usaco2005 qua]Bull Math
1754: [Usaco2005 qua]Bull Math Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 398 Solved: 242[Submit ...
- 【BZOJ】1754: [Usaco2005 qua]Bull Math
[算法]高精度乘法 #include<cstdio> #include<algorithm> #include<cstring> using namespace s ...
- BZOJ1754: [Usaco2005 qua]Bull Math
1754: [Usaco2005 qua]Bull Math Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 374 Solved: 227[Submit ...
- bzoj 1755: [Usaco2005 qua]Bank Interest【模拟】
原来强行转int可以避免四舍五入啊 #include<iostream> #include<cstdio> using namespace std; int r,y; doub ...
- bzoj 1753: [Usaco2005 qua]Who's in the Middle【排序】
--这可能是早年Pascal盛行的时候考排序的吧居然还是Glod-- #include<iostream> #include<cstdio> #include<algor ...
- 1755: [Usaco2005 qua]Bank Interest
1755: [Usaco2005 qua]Bank Interest Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 187 Solved: 162[Su ...
- Poj OpenJudge 百练 2389 Bull Math
1.Link: http://poj.org/problem?id=2389 http://bailian.openjudge.cn/practice/2389/ 2.Content: Bull Ma ...
- bzoj1751 [Usaco2005 qua]Lake Counting
1751: [Usaco2005 qua]Lake Counting Time Limit: 5 Sec Memory Limit: 64 MB Submit: 168 Solved: 130 [ ...
随机推荐
- merge into sql优化
今天网友说他的merge into sql跑了15分钟了还没有跑出数据,问我能不能优化一下,我让他把sql和sql的执行计划发过来 merge into F_Sal_P_Camp_Samp_Cust_ ...
- 功能测试中遇到的一些有意思的bug
2016.1.25 1. Xss攻击型的bug Xss攻击即跨站脚步攻击,通过插入恶意脚本 ,实现对用户浏览器的控制. Bug现象:新增物品时,物品名称输入一段JavaScript代码,在提交时此代 ...
- 利用C语言强行点击置灰的按钮
通常很多情况下,会有这样的事情,就是: 我们在运行某些程序的时候,发现按钮置灰了,比如购买版权或者输入序列号才能够获得访问权限.某个按钮才允许点击. 其实所有的这些东西都是 别的人或者公司利用一些编程 ...
- linux下grep命令笔记
grep -i 不区分大小写 --color 添加颜色 alias grep=‘grep --color=auto’ -v 显示没有被模式匹配到的行 -o 只显示 ...
- skynet是什么
云风的skynet,定义为一个游戏服务器框架,用c + lua基于Actor模型实现.代码极其精简,c部分的代码只有三千行左右. 整个skynet框架要解决的核心问题是:把一个消息 ...
- 获取当前时间日期并格式化--JS
工作当中,总是遇到很多觉得不错的JS脚本.现在觉得还是找个地方记录下来,以后可以随时查看. /** *获取当前时间日期并格式化 */ function getNowDate(){ var mydate ...
- JavaScript日常会跳的坑系列(二)
1.Number()将部分非数字类型转换为0 强制转换为数值类型函数: parseFloat.parseInt 优点:对非数值类型统一返回NaN 缺点:会将一部分符合数值类型的字符串也识别为数值 pa ...
- gulp自动化框架的搭建
自动化框架的搭建:https://github.com/zjhsd2007/www 屏蔽掉的部分是Test(文件夹的目录 也是你的项目名称);本地项目启动后 配合sass,会自动启动浏览器,然后好处多 ...
- webstorm 如何修改背景颜色
http://www.cnblogs.com/zxyun/p/4744744.html 见文章底部有图文说明 15个必须知道的chrome开发者技巧(GIF):http://www.wtoutiao. ...
- LSJ_NHibernate第四章 MVC
前言: MVC现在已经成为web开发的一个主流趋势了,还没用过的小伙伴,你们已经落伍了,这里我推荐一篇学习博客 玩转Asp.net MVC 的八个扩展点 代码完全开源,下载地址:https://gi ...