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. pat 1062. Talent and Virtue (25)

    难得的一次ac 题目意思直接,方法就是对virtue talent得分进行判断其归属类型,用0 1 2 3 4 表示 不合格 sage noblemen foolmen foolmen 再对序列进行排 ...

  2. [Angular 2] Template property syntax

    This lesson covers using the [input] syntax to change an element property such as “hidden” or “conte ...

  3. eclipse不能识别虚拟机的问题

    1.输入cmd进入dos界面,进入android-sdk-windows\platform-tools目录,执行下面命令启动adb start-server出现下面错误* daemon not run ...

  4. Codeforces 526D - Om Nom and Necklace 【KMP】

    ZeptoLab Code Rush 2015 D. Om Nom and Necklace [题意] 给出一个字符串s,判断其各个前缀是否是 ABABA…ABA的形式(A和B都可以为空,且A有Q+1 ...

  5. css样式float造成的浮动“塌陷”问题的解决办法

    什么是CSS Float? 定义: float 属性定义元素浮动到左侧或右侧.以往这个属性总应用于图像,使文本围绕在图像周围,不过在 CSS 中,任何元素都可以浮动.浮动元素会生成一个块级元素,而不论 ...

  6. c#使用Microsoft Excel 12.0 object Libary导出的Excel文件office2003不能打开!!~~(分享)

    -----转载:http://hi.baidu.com/zhang_zhu_1/item/f3d47d1f86bf037a70d5e87e 使用C#导出数据到Excel文件时,Excel 2007组件 ...

  7. linux 'more' command.

    more命令,功能类似 cat ,cat命令是整个文件的内容从上到下显示在屏幕上. more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会 ...

  8. MySQL被Oracle并购后的409个日日夜夜

    2009年4月20日,Oracle并购了Sun,这也意味着MySQL归属到甲骨文的旗下.四百多天过去了,究竟这场并购结局如何?请看本文. 去年对Sun的收购,让甲骨文顺利的将一个潜在的对手MySQL收 ...

  9. A simple stack

    // simple stack.cpp : 定义控制台应用程序的入口点.// #include "stdafx.h"#include<iostream>using na ...

  10. JSON带来编程界怎样的描述

    JSON是一套数据对象组织格式,从程序员的角度观看,他是以种非常易读易写的形式来描述一种key-value的数据组织.全名称JavaScript Object Notation,从名称上可看已经说明他 ...