[Vijos P2000]A x B Problem
题目大意:叫你求A × B。
解题思路:高精度。你可千万别小看这道题,这是2017年7月27日的信息。

不过也不要怕,根据twd2的题解里写的,用普通的高精度加上一些小小的修改是可以过的。

那么直接上代码吧。
C++ Code:
#include<cstdio>
#include<cstring>
#include<cctype>
using namespace std;
char s[5005];
long long num1[701],num2[701],num3[1700];
int main(){
int n;
scanf("%d",&n);
while(n--){
memset(num1,0,sizeof(num1));
memset(num2,0,sizeof(num2));
int len=0;
char c=getchar();
while(!isdigit(c))c=getchar();
while(isdigit(c)){
s[++len]=c;
c=getchar();
}
int w=1,l1=1,l2=1;
for(int i=len;i;i--){
if(w==100000000){
w=1;l1++;
}
num1[l1]+=w*(s[i]-'0');
w*=10;
}
len=0;
while(!isdigit(c))c=getchar();
while(isdigit(c)){
s[++len]=c;
c=getchar();
}
w=1;
for(int i=len;i;i--){
if(w==100000000){
w=1;l2++;
}
num2[l2]+=w*(s[i]-'0');
w*=10;
}
memset(num3,0,sizeof(num3));
int l3=l1+l2+4;
for(int i=1;i<=l1;i++)
for(int j=1;j<=l2;j++)num3[i+j-1]+=num1[i]*num2[j];
for(int i=1;i<=l1+l2+3;i++)
if(num3[i]>=100000000){
num3[i+1]+=num3[i]/100000000;
num3[i]%=100000000;
}
while(num3[l3]==0&&l3>1)l3--;
printf("%lld",num3[l3]);
for(int i=l3-1;i;i--)printf("%08lld",num3[i]);
puts("");
}
return 0;
}
这是时间使用情况:

我觉得时间用的并不是很多,就把乘法和除法、取模放在一块,结果居然被我卡过去了!!
C++ Code:
#include<cstdio>
#include<cstring>
#include<cctype>
using namespace std;
char s[5005];
long long num1[701],num2[701],num3[1700];
int main(){
int n;
scanf("%d",&n);
while(n--){
memset(num1,0,sizeof(num1));
memset(num2,0,sizeof(num2));
int len=0;
char c=getchar();
while(!isdigit(c))c=getchar();
while(isdigit(c)){
s[++len]=c;
c=getchar();
}
int w=1,l1=1,l2=1;
for(int i=len;i;i--){
if(w==100000000){
w=1;l1++;
}
num1[l1]+=w*(s[i]-'0');
w*=10;
}
len=0;
while(!isdigit(c))c=getchar();
while(isdigit(c)){
s[++len]=c;
c=getchar();
}
w=1;
for(int i=len;i;i--){
if(w==100000000){
w=1;l2++;
}
num2[l2]+=w*(s[i]-'0');
w*=10;
}
memset(num3,0,sizeof(num3));
int l3=l1+l2+4;
for(int i=1;i<=l1;i++)
for(int j=1;j<=l2;j++){
num3[i+j-1]+=num1[i]*num2[j];
num3[i+j]+=num3[i+j-1]/100000000;
num3[i+j-1]%=100000000;
}
while(num3[l3]==0&&l3>1)l3--;
printf("%lld",num3[l3]);
for(int i=l3-1;i;i--)printf("%08lld",num3[i]);
puts("");
}
return 0;
}
这是时间使用情况,可以发现,除了第一个点,其他都是900+ms的,有一个甚至达到了996ms!!这说明我RP好23333333。

[Vijos P2000]A x B Problem的更多相关文章
- 【BZOJ 1061】【Vijos 1825】【NOI 2008】志愿者招募
http://www.lydsy.com/JudgeOnline/problem.php?id=1061 https://vijos.org/p/1825 直接上姜爷论文... #include< ...
- 【BZOJ 2541】【Vijos 1366】【CTSC 2000】冰原探险
http://www.lydsy.com/JudgeOnline/problem.php?id=2541 https://vijos.org/p/1366 loli秘制大爆搜_(:з」∠)_坑了好久啊 ...
- 【BZOJ 1065】【Vijos 1826】【NOI 2008】奥运物流
http://www.lydsy.com/JudgeOnline/problem.php?id=1065 https://vijos.org/p/1826 好难的题啊TWT ∈我这辈子也想不出来系列~ ...
- [题解]vijos & codevs 能量项链
a { text-decoration: none; font-family: "comic sans ms" } .math { color: gray; font-family ...
- BZOJ 1411&&Vijos 1544 : [ZJOI2009]硬币游戏【递推,快速幂】
1411: [ZJOI2009]硬币游戏 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 897 Solved: 394[Submit][Status ...
- vijos 1605 双栈排序 - 贪心 - 二分图
题目传送门 传送门I 传送门II 题目大意 双栈排序,问最小字典序操作序列. 不能发现两个数$a_{j}, a_{k}\ \ (j < k)$不能放在同一个栈的充分必要条件时存在一个$i$使得$ ...
- Vijos 1404 遭遇战 - 动态规划 - 线段树 - 最短路 - 堆
背景 你知道吗,SQ Class的人都很喜欢打CS.(不知道CS是什么的人不用参加这次比赛). 描述 今天,他们在打一张叫DUSTII的地图,万恶的恐怖分子要炸掉藏在A区的SQC论坛服务器!我们SQC ...
- NOIP 车站分级 (luogu 1983 & codevs 3294 & vijos 1851) - 拓扑排序 - bitset
描述 一条单向的铁路线上,依次有编号为 1, 2, ..., n 的 n 个火车站.每个火车站都有一个级别,最低为 1 级.现有若干趟车次在这条线路上行驶,每一趟都满足如下要求:如果这趟车次停靠了火车 ...
- Vijos 1308 埃及分数 - 迭代加深
描述 在古埃及,人们使用单位分数的和(形如1/a的, a是自然数)表示一切有理数.如:2/3=1/2+1/6,但不允许2/3=1/3+1/3,因为加数中有相同的.对于一个分数a/b,表示方法有很多种, ...
随机推荐
- python3 pymysql学习笔记
练手项目需要用到mysql就顺手把mysql也学了,这个模块没什么好说的,比较简单,实际整个过程我都是在学mysql语句,但还是发现了一些问题. fetchall() 获取结果集中的所有行 这个函数难 ...
- HDU 4535 吉哥系列故事——礼尚往来( 错排水题 )
链接:传送门 思路:错排模板题,水题是非常浪费时间的. /*********************************************************************** ...
- python_字符串常用操作
name = "monicao"name.capitalize() #首字母大写print(name.capitalize()) print(name.count("o& ...
- Eclipse Maven 创建Hello World Web项目
通过Eclipse创建Maven Web项目的简单步骤 先决条件 (Prerequisites) 1,JDK environment, 具体的安装JDK的步骤和环境配置一般网上都有,这里就不在赘述. ...
- HTML5 基础测试题
HTML5 基础测试题 1.HTML5 之前的 HTML 版本是什么?() A.HTML 4.01 B.HTML 4 C.HTML 4.1 D.HTML 4.9 2.HTML5 的正确 d ...
- JavaScript push(),join() 函数
定义和用法 push方法 可向数组的末尾添加一个或多个元素,并返回一个新的长度. join方法 用于把数组中所有元素添加到一个指定的字符串,元素是通过指定的分隔符进行分割的. 语法 arrayObje ...
- Spring boot 使用@Value注入属性
Spring boot 使用@Value注入属性 学习了:http://blog.csdn.net/hry2015/article/details/72353994 如果启动的时候报错: spring ...
- hdu5389(DP)
题意: 给出n个人的id,有两个门,每一个门有一个标号.我们记作a和b,如今我们要将n个人分成两组,进入两个门中,使得两部分人的标号的和(迭代的求,直至变成一位数.我们姑且叫做求"和&quo ...
- C++ OTL MySQL(Windows/Linux) V8.1
Windows每秒钟10000条以上插入:Linux每秒插入300条以上.Q269752451 输出截图: Linux输出: Windows输出: 有须要的联系 QQ 3508551694 water ...
- UVA 11077 Find the Permutations 递推置换
Find the Permutations Sorting is one of the most used operations in real ...