1754: [Usaco2005 qua]Bull Math

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 374  Solved: 227
[Submit][Status]

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

Sample Input

11111111111111
1111111111

Sample Output

12345679011110987654321

HINT

Source

Gold

题解:

呵呵,金组出这种题,防爆零呢吧。。。

代码:

 #include<cstdio>

 #include<cstdlib>

 #include<cmath>

 #include<cstring>

 #include<algorithm>

 #include<iostream>

 #include<vector>

 #include<map>

 #include<set>

 #include<queue>

 #include<string>

 #define inf 1000000000

 #define maxn 10000

 #define maxm 500+100

 #define eps 1e-10

 #define ll long long

 #define pa pair<int,int>

 #define for0(i,n) for(int i=0;i<=(n);i++)

 #define for1(i,n) for(int i=1;i<=(n);i++)

 #define for2(i,x,y) for(int i=(x);i<=(y);i++)

 #define for3(i,x,y) for(int i=(x);i>=(y);i--)

 #define mod 1000000007

 using namespace std;

 inline int read()

 {

     int x=,f=;char ch=getchar();

     while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}

     while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}

     return x*f;

 }
int n,m,a[maxn],b[maxn],c[maxn];
char ch; int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); ch=getchar();
while(ch<=''&&ch>='')a[++n]=ch-'',ch=getchar();
for1(i,n>>)swap(a[i],a[n+-i]);
ch=getchar();
while(ch<=''&&ch>='')b[++m]=ch-'',ch=getchar();
for1(i,m>>)swap(b[i],b[m+-i]);
for1(i,n)
for1(j,m)
c[i+j-]+=a[i]*b[j];
for1(i,n+m)c[i+]+=c[i]/,c[i]%=;
int t=n+m;
while(!c[t])t--;
for3(i,t,)printf("%d",c[i]);
printf("\n"); return ; }

BZOJ1754: [Usaco2005 qua]Bull Math的更多相关文章

  1. 1754: [Usaco2005 qua]Bull Math

    1754: [Usaco2005 qua]Bull Math Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 398  Solved: 242[Submit ...

  2. BZOJ 1754: [Usaco2005 qua]Bull Math

    Description Bulls are so much better at math than the cows. They can multiply huge integers together ...

  3. 【BZOJ】1754: [Usaco2005 qua]Bull Math

    [算法]高精度乘法 #include<cstdio> #include<algorithm> #include<cstring> using namespace s ...

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

    高精乘法板子 然而WA了两次也是没救了 #include<iostream> #include<cstdio> #include<cstring> using na ...

  5. Poj OpenJudge 百练 2389 Bull Math

    1.Link: http://poj.org/problem?id=2389 http://bailian.openjudge.cn/practice/2389/ 2.Content: Bull Ma ...

  6. bzoj1751 [Usaco2005 qua]Lake Counting

    1751: [Usaco2005 qua]Lake Counting Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 168  Solved: 130 [ ...

  7. 1755: [Usaco2005 qua]Bank Interest

    1755: [Usaco2005 qua]Bank Interest Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 187  Solved: 162[Su ...

  8. 1753: [Usaco2005 qua]Who's in the Middle

    1753: [Usaco2005 qua]Who's in the Middle Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 290  Solved:  ...

  9. 1751: [Usaco2005 qua]Lake Counting

    1751: [Usaco2005 qua]Lake Counting Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 190  Solved: 150[Su ...

随机推荐

  1. Facebook Hacker Cup 2015 Round 1--Homework(筛选法求素数)

    题意:给定A,B,K(A<=B)三个数,问在[A,B]范围内的数素数因子个数为K的个数. 题解:典型的筛选法求素数.首先建立一个保存素数因子个数的数组factorNum[],以及到n为止含有素数 ...

  2. java设计模式演示样例

    创建模式 1.工厂方法模式(Factory Method)  将程序中创建对象的操作,单独出来处理,创建一个产品的工厂接口,把实际的工作转移到详细的子类.大大提高了系统扩展的柔性,接口的抽象化处理给相 ...

  3. adb出现adb server is out of date时的解决的方法

    出错的原因是adb的port被其它程序的进程占据了,所以要做的就是找到并kill该进程.步骤:. 1.在cmd中运行adb nodaemon server,查看adb的port号是多少,普通情况下是5 ...

  4. 关于OS_PRIO_SELF的说明

    在看ucosii 中关于删除任务的函数 OSTaskDel 时看到 if (prio == OS_PRIO_SELF) {                                 /* See ...

  5. php 二维数组以树形输出(转)

    <?php /** * @author Skyline * @copyright 2011 */ $cate = array(1=>array('id'=>1,'pid'=>0 ...

  6. 浅析mysql 共享表空间与独享表空间以及他们之间的转化

        innodb这种引擎,与MYISAM引擎的区别很大.特别是它的数据存储格式等.对于innodb的数据结构,首先要解决两个概念性的问题: 共享表空间以及独占表空间.什么是共享表空间和独占表空间共 ...

  7. Composite 组合模式

      简介         <大话设计模式>一书中组合模式的定义为:将对象组合成[树]形结构以表示[部分-整体]的层次结构,组合模式使得用户对[单个对象]和对[组合对象]的使用具有一致性. ...

  8. Mysql数据库一个小程序实现自动创建分表。

    每当跨月的时候也是系统出问题最多的时候,没有表和字段缺失是两个最常见的错误. 为了解决这个问题,研究了一下mysql的 information_schema 表: information_schema ...

  9. 移动端网站或APP点击后出现闪动或灰色背景

    隐藏文本框阴影 input, textarea{-webkit-appearance: @none;} 取消手机点击屏幕时,会出现的灰块 html,body{-webkit-text-size-adj ...

  10. My.Ioc 代码示例——使用条件绑定和元数据(可选)构建插件树

    本文旨在通过创建一棵插件树来演示条件绑定和元数据的用法. 说“插件树”也许不大妥当,因为在一般观念中,谈到插件树,我们很容易会想到 Winform/Wpf 中的菜单.举例来说,如果要在 Winform ...