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 ...
随机推荐
- BZOJ 口胡记录
最近实在是懒的不想打代码...好像口胡也算一种训练,那就口胡把. BZOJ 2243 染色(树链剖分) 首先树链剖分,然后记录下每个区间的左右端点颜色和当前区间的颜色段.再对每个节点维护一个tag标记 ...
- 【bzoj2073】[POI2004]PRZ 状态压缩dp
题目描述 一只队伍在爬山时碰到了雪崩,他们在逃跑时遇到了一座桥,他们要尽快的过桥. 桥已经很旧了, 所以它不能承受太重的东西. 任何时候队伍在桥上的人都不能超过一定的限制. 所以这只队伍过桥时只能分批 ...
- javascript中检测一个变量的类型
/** * 怎么检测一个变量的类型? * 在js中检测对象类型主要有三种:typeof, instanceof, constructor, 这几种都可以检测对象的类型. * 另外还可以适应jQuery ...
- C++中Map的使用 (个人简单的对于String的使用)
#include<map> #include<iostream> #include<string> using namespace std; int main() ...
- HDOJ(HDU).2660 Accepted Necklace (DFS)
HDOJ(HDU).2660 Accepted Necklace (DFS) 点我挑战题目 题意分析 给出一些石头,这些石头都有自身的价值和重量.现在要求从这些石头中选K个石头,求出重量不超过W的这些 ...
- odex文件格式
apk安装或启动时,会通过dexopt来将dex生成优化后的odex文件.过程是将apk中的classes.dex解压后,用dexopt处理并保存为“/data/dalvik-cache/data@a ...
- 【神仙题】【P4885】 灭顶之灾
传送门 Description 请将题目名称的首字母连起来读 Scarlet有一张$n*m$的神秘表格.现在Scarlet向表格中填数字,她会从第一行中的某个格子起,按照从左往右,从上往下的顺序依次填 ...
- [Jenkins 新插件] 兼容阿里开发手册 (P3C) 的火线插件安装使用教程
一.前言 火线(Fireline)的Jenkins官方插件已经上线,目前火线不仅能检查出安卓代码中的安全类问题和内存泄露问题,还兼容了阿里开源的Java开发规约(P3C项目),本文将以教程的形式帮助大 ...
- 【poj3522-苗条树】最大边与最小边差值最小的生成树,并查集
题意:求最大边与最小边差值最小的生成树.n<=100,m<=n*(n-1)/2,没有重边和自环. 题解: m^2的做法就不说了. 时间复杂度O(n*m)的做法: 按边排序,枚举当前最大的边 ...
- 【BZOJ1598】牛跑步 [A*搜索]
牛跑步 Time Limit: 10 Sec Memory Limit: 162 MB[Submit][Status][Discuss] Description BESSIE准备用从牛棚跑到池塘的方 ...