bzoj 1754: [Usaco2005 qua]Bull Math【高精乘法】

高精乘法板子

然而WA了两次也是没救了

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=105;
int la,lb,lc,a[N],b[N],c[N],tot;
char ch[N];
int main()
{
    scanf("%s",ch+1);
    la=strlen(ch+1);
    for(int i=1;i<=la;i++)
        a[i]=ch[la-i+1]-‘0‘;
    scanf("%s",ch+1);
    lb=strlen(ch+1);
    for(int i=1;i<=lb;i++)
        b[i]=ch[lb-i+1]-‘0‘;
    for(int i=1;i<=la;i++)
        for(int j=1;j<=lb;j++)
            c[i+j-1]+=a[i]*b[j];
    for(int i=1;i<=la+lb;i++)
    {
        c[i+1]+=c[i]/10;
        c[i]%=10;
        if(c[i])
            lc=i;
    }
    for(int i=lc;i;i--)
        printf("%d",c[i]);
    return 0;
}
/*
11111111111111
1111111111
*/

原文地址:https://www.cnblogs.com/lokiii/p/8998814.html

时间: 2024-08-01 04:41:23

bzoj 1754: [Usaco2005 qua]Bull Math【高精乘法】的相关文章

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 tw

【BZOJ】1754: [Usaco2005 qua]Bull Math

[算法]高精度乘法 #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int maxn=100; char s1[maxn],s2[maxn]; int a[maxn],b[maxn],c[maxn],lena,lenb,lenc; int main(){ scanf("%s%s",s1,s2); lena=strlen(s1);lenb

bzoj1754[Usaco2005 qua]Bull Math*

bzoj1754[Usaco2005 qua]Bull Math 题意: 求两个正整数的积,每个数≤40位. 题解: 为什么C++不能支持高精度呢…… 代码: 1 a=int(raw_input()) 2 b=int(raw_input()) 3 print a*b 20160831

bzoj 3287: Mato的刷屏计划 高精水题 &amp;&amp; bzoj AC150

3287: Mato的刷屏计划 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 124  Solved: 43[Submit][Status] Description Mato同学喜欢上QQ,但是有少数傻逼总是问他一些弱智问题.Mato感到很反感,想要鄙视一下他们.他决定在QQ上刷屏,也就是发出一大堆字符.Mato的键盘上有4个键:A.B.C.D.按A就会输入一个字符,按B会把所有字符选中,按C会把选中的字符放入剪贴板,按D会插入剪贴板的内容.他的

bzoj 1755: [Usaco2005 qua]Bank Interest【模拟】

原来强行转int可以避免四舍五入啊 #include<iostream> #include<cstdio> using namespace std; int r,y; double m; int main() { scanf("%d%lf%d",&r,&m,&y); double l=1.0+(double)r/100.0; for(int i=1;i<=y;i++) m*=l; printf("%d\n",(i

vj1010:高精乘+细心模拟

这题的话思路挺简单的,主要是打一个高精乘,然后考虑一些细节的东西 码得挺少时间的,但是调错调了很久... 讲一下思路吧: 就是读入的时候,先把小数点去掉,mark一下小数点的位置 去掉小数点之后也就进行高精乘法即可,去掉前导零 之后计算一下小数点的位置 再去掉小数点后多余的零 以及特判k=1的情况,直接输出答案 细节的地方主要就是在模拟上吧, 我WA了几次: 1.当小数点后面没有数字的时候,当然不需要输出小数点...这个没有考虑进去 2.没有特判k=1的情况,因为答案是放在c数组里,所以当k=1

高精模板(加减乘)

啥都不说直接上板子吧 QAQ #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<cstdlib> using namespace std; const int N=100100; int len; int c[N],a[N],b[N]; string s,s1; //高精加法 inline

[BZOJ 2729][HNOI2012]排队(排列组合+高精)

Description 某中学有 n 名男同学,m 名女同学和两名老师要排队参加体检.他们排成一条直线,并且任意两名女同学不能相邻,两名老师也不能相邻,那么一共有多少种排法呢?(注意:任意两个人都是不同的) Solution 好像必须写压位高精的QAQ 先排n名男生,插空,讨论两名老师插在两个不同的空里的情况和先排在一起再在中间插一名女生的情况 #include<iostream> #include<cstdio> #include<cstring> #include&

BZOJ_1002_[FJOI2007]_轮状病毒(递推+高精)

描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1002 )*&*(^&*^&*^**()*) 分析 题目是求一种特殊的图的生成树的个数,但是貌似有更一般的算法,等明天再看吧... 只搞懂了打表找规律,然后题推的解法. 随便写个暴力打个表(其实我并不会写,明天再写吧今天好累),找一找规律. 1~14的答案如下 1 5 16 45 121 320 841 2205 5776 15125 39601 103680 271441 71