hdu1230火星A+B (大数题)
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; int hash[];
int sir[];
char ch1[],ch2[];
int num1[],num2[],n1[],n2[],sum[]; int main()
{
int k=;
for(int i=;i<=;i++)
{
if(!hash[i])
{
sir[k++]=i;
for(int j=i+i;j<=;j+=i)
hash[j]=;
}
} while(scanf("%s%s",ch1,ch2)!=EOF)
{ if(strcmp(ch1,"")==&&strcmp(ch2,"")==)
break;
int k1=,k2=;
num1[]=num2[]=;
for(int i=;i<strlen(ch1);i++)
{
if(ch1[i]==',')
{
k1++;
num1[k1]=;
continue;
}
num1[k1]=num1[k1]*+ch1[i]-'';
//cout<<num1[k1];
}
//cout<<endl;
for(int i=;i<strlen(ch2);i++)
{
if(ch2[i]==',')
{
k2++;
num2[k2]=;
continue;
}
num2[k2]=num2[k2]*+ch2[i]-'';
//cout<<num2[k2];
}
//cout<<endl; memset(n1,,sizeof(n1));
memset(n2,,sizeof(n2));
for(int i=k1;i>;i--)
n1[k1-i+]=num1[i];
for(int i=k2;i>;i--)
n2[k2-i+]=num2[i]; //for(int i=1;i<=k1;i++)
//printf("%d,",n1[i]); int K=k1>k2?k1:k2;
for(int i=;i<=K;i++)
{
if(i==)
sum[i]=n1[i]+n2[i];
else
{
if(sum[i-]>=sir[i-])
sum[i]=n1[i]+n2[i]+;
else
sum[i]=n1[i]+n2[i];
}
//cout<<sum[i]<<endl;
}
if(sum[K]>=sir[K])
sum[++K]=;
for(int i=K;i>;i--)
{
if(i==K)
{
printf("%d",sum[i]%sir[i]);
}
else
printf(",%d",sum[i]%sir[i]);
}
printf("\n");
}
return ;
}
hdu1230火星A+B (大数题)的更多相关文章
- HDU1230 火星A+B
火星A+B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- hdu1002 A + B Problem II(大数题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 A + B Problem II Time Limit: 2000/1000 MS (Java/ ...
- [火星补锅] 水题大战Vol.2 T2 && luogu P3623 [APIO2008]免费道路 题解
前言: 如果我自己写的话,或许能想出来正解,但是多半会因为整不出正确性而弃掉. 解析: 这题算是对Kruskal的熟练运用吧. 要求一颗生成树.也就是说,最后的边数是确定的. 首先我们容易想到一个策略 ...
- oj 1002题 (大数题)
#include <stdio.h> #include <string.h> int main(void) { int q,j,h,k,l; int d; ],s2[];//题 ...
- [火星补锅] 水题大战Vol.2 T1 && luogu P1904 天际线 题解 (线段树)
前言: 当时考场上并没有想出来...后来也是看了题解才明白 解析: 大家(除了我)都知道,奇点和偶点会成对出现,而出现的前提就是建筑的高度突然发生变化.(这个性质挺重要的,我之前没看出来) 所以就可以 ...
- HDU2054_A == B ?【模拟题】【大数】【水的问题】
A == B ? Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- 大数运算(python2)
偶然又遇到了一道大数题,据说python大数运算好屌,试了一发,果然方便-1 a = int( raw_input() ); //注意这里是按行读入的,即每行只读一个数 b = int( raw_in ...
- 玲珑杯1007-A 八进制大数加法(实现逻辑陷阱与题目套路)
题目连接:http://www.ifrog.cc/acm/problem/1056 DESCRIPTION Two octal number integers a, b are given, and ...
- JAVA大数类练手
今天突然看到了OJ上的大数类题目,由于学习了一点大数类的知识.果断水了6道题......都是非常基础的.就当的练手的吧. 学到的只是一些大数类的基本操作.以后多做点这样的题,争取熟练运用水大数题... ...
随机推荐
- c# 绘图常用对象和方法
//BitMap 位图,常用的方法, Save:主要方式有:(1)保存在图像文件里,可以指定格式[gif,bmp]:(2) 保存在流中,以指定格式[gif,bmp] //gra ...
- Unity笔记
1.使某个对象上的脚本失效和生效: GameObject.Find("xxx").transform.GetComponent<xxx>().enabled = fal ...
- Linux下Socket编程的端口问题( Bind error: Address already in use )
Linux下Socket编程的端口问题( Bind error: Address already in use ) 在进行linux网络编程时,每次修改了源代码并再次编译运行时,常遇到下面的地使用错误 ...
- (转载)PHP_Memcache函数详解
(转载)http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/04/19/2021605.html memcache函数所有的方法列表如下: M ...
- 数学(线性规划): ZJOI2013 防守战线
偷懒用的线性规划. #include <iostream> #include <cstring> #include <cstdio> using namespace ...
- Codeforces Round #263 (Div. 1) C. Appleman and a Sheet of Paper 树状数组暴力更新
C. Appleman and a Sheet of Paper Appleman has a very big sheet of paper. This sheet has a form of ...
- JavaScript 操作 DOM 常用 API 总结
文本整理了javascript操作DOM的一些常用的api,根据其作用整理成为创建,修改,查询等多种类型的api,主要用于复习基础知识,加深对原生js的认识. 基本概念 在讲解操作DOM的api之前, ...
- AngularJS测试二 jasmine测试路由 控制器 过滤器 事件 服务
测试应用 1.测试路由 我们需要检测路由是否在运作,是否找到了,或者是404了.我们要确认路由事件触发了,预期的模板是否真的加载了.既然路由会改变页面的地址(URL)和页面内容,我们需要检测路由是否被 ...
- Mac内建Apache开机启动
取消: sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 添加: sudo launchctl ...
- .NET 性能分析工具
Download .NET Profiler http://www.yourkit.com/dotnet/download/ dotTrace 5.5 Performance http://www.j ...