sicily 1020. Big Integer
Long long ago, there was a super computer that could deal with VeryLongIntegers(no VeryLongInteger will be negative). Do you know how this computer stores the VeryLongIntegers? This computer has a set of n positive integers: b1,b2,...,bn, which is called a basis for the computer.
The basis satisfies two properties:
1) 1 < bi <= 1000 (1 <= i <= n),
2) gcd(bi,bj) = 1 (1 <= i,j <= n, i ≠ j).
Let M = b1*b2*...*bn
Given an integer x, which is nonegative and less than M, the ordered n-tuples (x mod b1, x mod b2, ..., x mod bn), which is called the representation of x, will be put into the computer.
The input consists of T test cases. The number of test cases (T) is given in the first line of the input.
Each test case contains three lines.
The first line contains an integer n(<=100).
The second line contains n integers: b1,b2,...,bn, which is the basis of the computer.
The third line contains a single VeryLongInteger x.
Each VeryLongInteger will be 400 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative).
The output format is:(r1,r2,...,rn)
2 3
2 3 5
10 4
2 3 5 7
13
(0,1,0)
(1,1,3,6)
#include <iostream>
#include <string>
#include <string.h>
using namespace std; int* findMod(string str, int* arr, int len) {
int size = str.size();
int* arrt = new int[len];
memset(arrt, , sizeof(int) * len); for (int i = ; i != size; ++i) {
for (int j = ; j != len; ++j) {
arrt[j] = (arrt[j] * + (str[i] - '')) % arr[j];
}
}
return arrt;
} int main(int argc, char* argv[])
{ int T, n, *arr;
string x;
cin >> T;
while (T--) {
cin >> n;
arr = new int[n];
for (int i = ; i != n; ++i)
cin >> arr[i];
cin >> x;
int *result = findMod(x, arr, n);
cout << "(";
for (int i = ; i != n - ; i++)
cout << result[i] << ",";
cout << result[n - ] << ")" << endl;
} return ;
}
因为给的空间还是很大的,所以我在mod的时候用空间换时间,其实这样实现是不好的,因为申请的空间根本没释放。下面这样的话比较好一点,时间上也只是差了0.07多
sicily 1020. Big Integer的更多相关文章
- 大数求模 sicily 1020
Search
- Sicily1020-大数求余算法及优化
Github最终优化代码: https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1020.c 题目如下: 1020. ...
- .Net Core CLR FileFormat Call Method( Include MetaData, Stream, #~)
.Net Core CLR PE 文件启动方法,找到函数入口点,调用整个.Net 程式宿主. 使用方法:可以利用Visual Studio新建一个控制台应用程序,然后生成DLL,替换掉本程序DLL, ...
- PAT 1020
1020. Tree Traversals (25) Suppose that all the keys in a binary tree are distinct positive integers ...
- Sicily 1510欢迎提出优化方案
这道题我觉得是除1000(A-B)外最简单的题了……不过还是提出一个小问题:在本机用gcc编译的时候我没包括string.h头文件,通过编译,为什么在sicily上却编译失败? 1510. Mispe ...
- HDU字符串基础题(1020,1039,1062,1088,1161,1200,2017)
并不是很精简,随便改改A过了就没有再简化了. 1020. Problem Description Given a string containing only 'A' - 'Z', we could ...
- 【PAT】1020 Tree Traversals (25)(25 分)
1020 Tree Traversals (25)(25 分) Suppose that all the keys in a binary tree are distinct positive int ...
- PAT 1020 Tree Traversals[二叉树遍历]
1020 Tree Traversals (25)(25 分) Suppose that all the keys in a binary tree are distinct positive int ...
- HDU 1020:Encoding
pid=1020">Encoding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
随机推荐
- Codeforces Round #524 Div. 2 翻车记
A:签到.room里有一个用for写的,hack了一发1e8 1,结果用了大概600+ms跑过去了.惨绝人寰. #include<iostream> #include<cstdio& ...
- P1086 花生采摘
题目描述 鲁宾逊先生有一只宠物猴,名叫多多.这天,他们两个正沿着乡间小路散步,突然发现路边的告示牌上贴着一张小小的纸条:“欢迎免费品尝我种的花生!――熊字”. 鲁宾逊先生和多多都很开心,因为花生正是他 ...
- LUOGU 1440
#include<cstdio> #include<algorithm> #include<cstring> #define N 1000005 using nam ...
- JavaScript SandBox沙箱设计模式
沙箱模式常见于YUI3 core,它是一种采用同一构造器(Constructor)生成彼此独立且互不干扰(self-contained)的实例对象,而从避免污染全局对象的方法. 命名空间 JavaSc ...
- PowerDesigner 技巧【1】
Name与Code同步的问题: PowerDesigner中,修改了某个字段的name,其code也跟着修改,这个问题很讨厌,因为一般来说,name是中文的,code是字段名. 解决方法如下: 1.选 ...
- HDU1832 二维线段树求最值(模板)
Luck and Love Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- scrapy架构设计分析
scrapy是一个Python爬虫框架.我们自己用requests也能写爬虫(GET某个URL,然后Parse网页的内容),那么,问题来了,scrapy高明在哪些地方呢?下面就来讨论下这个话题,看看业 ...
- [技巧篇]13.从今天开始做一个有理想的人,放弃alter的调试,拥抱console.log
在js前端开发时,为了调试经常会加上 console.log.但是在有的浏览器(比如IE)中会报错,怎么办呢?好像10之后也开始支持了!如果以防方一,可以使用如下方式 在js文件最前面添加如下js代码 ...
- springboot-部署到centos7
环境 系统:centos7 64位 安装jdk 第一步:下载 先进入官网:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-do ...
- mybatis在Mapper的xml文件中的转义字符的处理
XML转义字符 < < 小于号 > > 大于号 & & 和 ' ’ 单引号 " " 双引号 用转义字符进行替换 例如 SE ...