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 ...
随机推荐
- Apple - Hdu5160
Problem Description We are going to distribute apples to n children. Every child has his/her desired ...
- [牛客Wannafly挑战赛27D]绿魔法师
description newcoder 给你一个空的可重集合\(S\). \(n\)次操作,每次操作给出\(x\),\(k\),\(p\),执行以下操作: \(opt\ 1\):在S中加入x. \( ...
- [洛谷P4345][SHOI2015]超能粒子炮·改
题目大意:给你$n,k$,求:$$\sum\limits_{i=0}^k\binom n i\pmod{2333}$$题解:令$p=2333,f(n,k)\equiv\sum\limits_{i=0} ...
- redux的一些插件总结(redux-actions,reselect)
redux本身还是过于简单,实际使用的时候需要配合许多插件. 下面是一些插件与vuex的功能对比 redux-actions <=> vuex的mutation的写法 reselect & ...
- LOJ 模拟赛
1.LOJ 507 接竹竿 link dp[i]表示前i个的最大分数,所以dp[i]=max(dp[i-1],dp[j-1]+sum[i]-sum[j-1]) (color i ==color j ...
- JavaScript中Unicode值转字符
在JavaScript中,将Unicode值转字符的方法: <!DOCTYPE html> <html> <head> <meta charset=" ...
- 使用html5的Geolocation API实现定位
公司有个需求,需要获取用户的位置,所以看了下html5的Geolocation 这个新东西,发现挺好用的. <!DOCTYPE html> <html> <body> ...
- Data Mining的十种分析方法——摘自《市场研究网络版》谢邦昌教授
Data Mining的十种分析方法: 记忆基础推理法(Memory-Based Reasoning:MBR) 记忆基础推理法最主要的概念是用已知的案例(case)来预测未来案例的一些属 ...
- jenkins Process leaked file descriptors
https://stackoverflow.com/questions/17024441/process-leaked-file-descriptors-error-on-jenkins 1. BUI ...
- 【转载】Quick-Cocos2d-x文件结构分析
在上一章我们讲过了Quick-Cocos2d-x中的环境搭建,这章我们分析下quick中的文件结构吧!打开quick的文件夹,可以看到如下的这些目录和文件: bin:存放各种与引擎相关的脚本 comp ...