/**
* url : http://acm.hdu.edu.cn/showproblem.php?pid=1930
* stratege : 解一元线性同余方程组, 扩展欧几里得
* Author: johnsondu
* Status: johnsondu 0MS 284K 2207B C++ 2012-08-19 13:13:15
* Trick: There will be no blank in the end of the text
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstring>
#include <map>
#include <string>
#include <iomanip>
using namespace std;
const int N = 2005 ;
int key[N], num, n ;
int str[N] ;
int res[N] ;
int r[N] ;
void input ()
{
int i ;
scanf ("%d", &n) ;
memset (res, 0, sizeof (res)) ;
memset (str, 0, sizeof (str)) ;
memset (r, 0, sizeof (r)) ;
memset (key, 0, sizeof (key)) ;
num = 0 ;
for (i = 0; i < 4; i ++) // key
scanf ("%d", &key[i]) ;
for (i = 0; i < n; i ++) // the set of remainder
scanf ("%d", &str[i]) ;
}
void exGcd (int a, int b, int &d, int &x, int &y) // Extended_Euclid
{
if (b == 0)
{
d = a ;
x = 1 ;
y = 0 ;
return ;
}
exGcd (b, a%b, d, x, y) ;
int tmp = x ;
x = y ;
y = tmp - (a/b)*y ;
}
void getNum ()
{
int i, j ;
int a, b, c, d, x, y ;
for (i = 0; i < n; i ++)
{
r[3] = str[i] % 100 ; //transform the set of remainder into the
r[2] = (str[i]%10000)/100 ; //single remainder of the key
r[1] = (str[i]%1000000)/ 10000 ;
r[0] = str[i]/1000000;
int ta = key[0] ;
int tr = r[0] ;
//mission: x = r1 (mod a1), x = r2 (mod a2), ..., find x ;
for (j = 1; j < 4; j ++) //a1, a2, ... are key[i], r1, r2, ... are r[i]
{ //find the str[i]'s value
a = ta, b = key[j] ;
c = r[j] - tr ;
exGcd (a, b, d, x, y) ;
int t = b/d ;
x = (x*(c/d)%t + t) % t ;
tr = ta*x + tr ;
ta = ta * (key[j]/d) ;
}
res[i] = tr ;
}
}
void output ()
{
int i ;
int a, b, c ;
char destr [10005] ;
int len = 0 ;
for (i = 0; i < n; i ++)
{
a = res[i] / 10000 ;
b = (res[i] % 10000) / 100 ;
c = res[i] % 100 ;
if (a != 27)
destr[len++] = 'A' + a - 1 ;
else destr[len++] = ' ' ;
if (b != 27)
destr[len++] = 'A' + b - 1 ;
else destr[len ++] = ' ' ;
if (c != 27)
destr[len++] = 'A' + c - 1 ;
else destr[len ++] = ' ' ;
}
while (destr[len-1] == ' ') //ignore the blank in the end of text.
{
len -- ;
}
for (i = 0; i < len; i ++)
printf ("%c", destr[i]) ;
printf ("\n") ;
}
int main ()
{
int tcase ;
scanf ("%d", &tcase) ;
while (tcase --)
{
input () ;
getNum () ;
output () ;
}
return 0 ;
}
相关推荐
MOOS-ivp 实验三 MOOS简介(1)
系列文章目录 提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加 例如:第一章 Python 机器学习入门之pandas的使用 提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录系列文章目录前言一、pandas是什么?二、使用步骤1.引入库2.读入数据总结 前言 提示:这里可以添加本文要记录的大概内容: 例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。 提示:以下是本篇文章正文内容,下面案例
hdu1930 And Now, a Remainder from Our Sponsor-----中国剩余定理
And Now, a Remainder from Our Sponsor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 380 Accepted Submission(s): 153 Problem Descrip
SpringBoot与锐浪报表服务器深度整合实战指南
本文详细介绍了SpringBoot与锐浪报表服务器的深度整合实战指南,包括环境准备、Windows/Linux系统配置、核心功能实现代码解析及常见问题解决方案。通过具体案例和代码示例,帮助开发者高效完成报表系统的集成与部署,提升企业级应用的报表处理能力。
HDU1930 And Now, a Remainder from Our Sponsor 解线性同余方程的应用
这道题过的人很少,原因肯定是因为英语,这题目意思i 我看了好久,英语太差了,题目的意思是: 先给你四个数,然后给你n个数,把n个数中的每一个数给拆成四个数,怎么拆按题目要求,拆出来的这四个数作为同余方程 x≡ai(mod ri) 中的 ri,最先给出的四个作为key的四个数,作为方程中的 ai,然后求出x, 总的意思就是先给你四个作为key的四个数, 给你n个数,把n个数中的每一个
动力锂电池-二阶RC模型等效电路-RLS参数辨识-Simulink
1.锂电池二阶RC等效电路模型
高质量水下垃圾数据集解析与应用实践
计算机视觉在环保领域的应用日益广泛,其中目标检测技术是关键支撑。通过深度学习模型对水下垃圾进行精准识别,需要高质量标注数据集作为基础。1962幅水下垃圾数据集采用专业预处理流程,包括色彩校正、去雾增强等技术,有效解决了水下图像的光照不均、水体浑浊等典型问题。该数据集覆盖12类常见海洋垃圾,标注错误率低于2%,显著提升了模型训练效果。在工程实践中,该数据集特别适合用于水下机器人实时检测系统和海洋垃圾分布热力图生成等场景,通过优化模型架构和数据增强策略,可实现更高效的环境监测与保护。
HDU - 1930 And Now, a Remainder from Our Sponsor (中国剩余定理)
IBM has decided that all messages sent to and from teams competing in the ACM programming contest should be encoded. They have decided that instead of sending the letters of a message, they will trans...
VSCode 1.85便携版安装与配置:解决远程服务器glibc版本过低报错的保姆级指南
本文详细介绍了如何通过VSCode 1.85便携版解决远程服务器glibc版本过低导致的兼容性问题。通过环境隔离和版本固化的方法,开发者可以在老旧服务器上稳定运行Remote-SSH插件,同时保留主力VSCode的配置。文章提供了从下载安装到深度配置的完整指南,帮助用户快速搭建稳定的开发环境。
hdu 1930 中国剩余定理(互质模板题)
And Now, a Remainder from Our Sponsor Time Limit : 5000/1000ms (Java/Other)Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 23Accepted Submission(s) : 13 Problem Description IB...
STM32 Modbus-RTU从零到实战:手把手教你用HAL库实现工业通信(附完整代码)
本文详细介绍了如何使用STM32 HAL库从零开始实现Modbus-RTU从机通信。内容涵盖RS485硬件设计、CubeMX串口与定时器配置、基于空闲中断的高效数据接收、协议栈状态机设计、CRC16校验实现以及常用功能码处理。文章提供了完整的代码框架和调试方法,帮助开发者快速构建稳定的工业通信节点。
基于python的超市历年数据可视化分析
包含:Order_Date Sales Quantity Profit year month。所有这些物品都在美国4个地区的49个州销售,来着793位客户的5009个订单。9994行,21列数据。
And Now, a Remainder from Our Sponsor (中国剩余定理互质情况)
And Now, a Remainder from Our Sponsor IBM has decided that all messages sent to and from teams competing in the ACM programming contest should be encoded. They have decided that instead of sending t...
导航系统 | 全球四大卫星导航系统(2025)核心能力对比分析
北斗系统通过GEO卫星(80°E、110.5°E、140°E)实现区域增强,其IGSO卫星在亚太地区形成"8"字形轨迹,使该区域可见卫星数量比GPS多4-6颗,显著提升复杂环境下的定位可用性[13]。北斗短报文功能在2025年云南地震救援中发挥关键作用,被困人员通过北斗终端发送120字求救信息,实现"位置+状态"一体化上报,救援响应时间缩短40%[15]。北斗通过三频信号(B1C/B2a/B3)消除电离层延迟误差,在城市峡谷环境下定位连续性达99.98%,优于GPS的99.95%[5]。
杭电DP题目(dynamic programming)
<br />这里集中了很多的动态规划题目,我也从这里开始突破啦<br />----------------------------------------------------------------------------------------------<br /> <br /> 记我今天开始,正式向ACM营地出发,努力搞好自己的CSDN博客<br /> <br /> turn potential to reality !<br />
老版QQ原生表情gif动态
这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。
jre9下载 jdk9
(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】
HDU 1312 Red and Black
看了好多天的DFS,基本上的程序都是要借助解题报告才可以实现 但是这一题,确实依照自己的思路,完全靠自己写出来的,或许比较简单吧,所以特此发表下文章,犒劳一下自己,再接再厉 http://acm.hdu.edu.cn/showproblem.php?pid=1312 Red
Statistics and Machine Learning Toolbox
Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具
杭电1051 经典贪心
这题真是抓狂,我已经提交了8次,还是没过,我都找不到任何错误数据了粘贴下别人的代码提交下,就是果断过。。。求大牛指点……/* title:Wooden Sticks url: http://acm.hdu.edu.cn/showproblem.php?pid=1051 我的做题思想: 主要是通过下表法,首先对数组的length按从小到大排序 然后,通过第一元素开始,进行比较,如果后面的任一 一组数据与当前数据进行比较,length和weight都比目前 length 和 weight 都小
Uva 10104 Euclid Problem |x|+|y|最小解 扩展欧几里得
/* * url: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1045 * stratege: 求ax+by=gcd(a,b), |x|+|y|的和的x,y,的解, 扩展欧几里得,分四种情况考虑 * status:10541367 1010
LightOj 1111 - Best Picnic Ever
/** * Author: johnsondu * time: 2013-4-11 * problem: LightOj 1111 - Best Picnic Ever * url: http://lightoj.com/volume_showproblem.php?problem=1111 * stratege: DFS, count the person who can r
POJ 3641 HDU 1905 Pseudoprime numbers 素数 模取幂
/* --------------------------------------------------- status : a312745658 3641 Accepted 328K 16MS C++ 1732B 2012-05-18 21:36:37 stratege : 快速模取幂,素数筛选, 判断一个大数是否为素数 URL: http:
HDU 1211 RSA 逆元 快速模取幂
/** * url: http://acm.hdu.edu.cn/showproblem.php?pid=1211 RSA * Author: Johnsondu * Time: 2012-7-28 18:00 around * Stratege: 逆元(扩展欧几里德) , 快速模取幂 * Status: 6364213 2012-07-28 18:12:54 Accepte
HDU 1010 Tempter of the Bone
关于DFS如何学好,先援引大牛的几点建议: (1)先理解搜索的原理,区别好bfs和dfs的优先搜索方向以及应用,例如bfs一般用来求最优解如最短路径. (2)掌握好所用的数据结构,特别是队列. (3)牢记dfs和bfs的常用模式,它是基本固定的,考试时信手拈来! (4)注
LightOj 1054 Efficient Pseudo Code
/* * Author: johnsondu * time: 2013-4-25 * meanning: 求出约数和n ^ m的约数和,快速模取幂,扩展欧几里德,素数筛选 * problem: LightOj 1054 * url: http://lightoj.com/volume_showproblem.php?problem=1054 * */ #include #i
uva 10830 A New Function
/* * Author: johnsondu * time: 2013-4-25 * problem: uva 10830 - A New Function * url: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1771 * so
Uva 11395 - Sigma Function 规律 对数
/* * 规律:通过打表后发现,在n的范围内,只有2^x 以及 平方数 和 平方数的2倍符合要求。 * 即:2^1, 2^2,... 1*1, 2*2,... 2*1*1, 2*2*2, 2*3*3... 等等,故只要去重就可以了 * url: http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_p
HDU 1559 最大子矩阵
/** * Author : johnsondu * time : 2013-4-7 * Type: DP, I want to really understand it * problem: 最大子矩阵 * url: http://acm.hdu.edu.cn/showproblem.php?pid=1559 */ #include #include #include
NYOJ38 布线问题 prim算法 kruscal算法
/* problem : NYOJ38 布线问题 stratege: kruscal algorithm URL :http://acm.nyist.net/JudgeOnline/problem.php?pid=38 status :166386 1006100213 布线问题 Accepted 76 4216 C/C++ 05-13 21:57:42 */
7439



被折叠的 条评论
为什么被折叠?



