And Now, a Remainder from Our Sponsor (中国剩余定理互质情况)

『杭电1930』And Now, a Remainder from Our Sponsor #include<iostream> #include<cstdio> #include<list> #include<algorithm> #include<cstring> #include<string> #include<queue> #include<stack> #include<map> #include<vector> #include<cmath> #i... 阅读详情

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 transmit their remainders relative to some secret keys which are four, two-digit integers that are pairwise relatively prime. For example, consider the message "THE CAT IN THE HAT". The letters of this message are first converted into numeric equivalents, where A=01, B=02, ..., Z=26 and a blank=27. Each group of 3 letters is then combined to create a 6 digit number. (If the last group does not contain 3 letters it is padded on the right with blanks and then transformed into a 6 digit number.) For example
THE CAT IN THE HAT → 200805 270301 202709 142720 080527 080120
Each six-digit integer is then encoded by replacing it with the remainders modulo the secret keys as follows: Each remainder should be padded with leading 0’s, if necessary, to make it two digits long. After this, the remainders are concatenated together and then any leading 0’s are removed. For example, if the secret keys are 34, 81, 65, and 43, then the first integer 200805 would have remainders 1, 6, 20 and 38. Following the rules above, these combine to get the encoding 1062038. The entire sample message above would be encoded as
1062038 1043103 1473907 22794503 15135731 16114011

Input
The input consists of multiple test cases. The first line of input consists of a single positive integer n indicating the number of test cases. The next 2n lines of the input consist of the test cases. The first line of each test case contains a positive integer (< 50) giving the number of groups in the encoded message. The second line of each test case consists of the four keys followed by the encoded message.
Each message group is separated with a space.
Output
For each test case write the decoded message. You should not print any trailing blanks.
Sample Input

2
6
34 81 65 43 1062038 1043103 1473907 22794503 15135731 16114011
3
20 31 53 39 5184133 14080210 7090922

Sample Output

THE CAT IN THE HAT
THE END

题意:

这是个非常有意思的破解密码的题目,给你已经加密的密文,用数字表示的,让你破译密文

题目告诉了具体生成的密码过程:

1)现将字母对应成2位数字,然后每三个字符合成一个6位数(当然了有前导零的计算时会去掉)

2)给了四个两位的数字,让每个六位数取模这四个数字得到四个值,四个两位数(可能有前导零)然后四个拼成一个数(最终会去掉前导零)

最终题目就给你四个取模的两位数,和每个取模后的结果合成的数

让我们破译密码

分析:

我们要破译密码肯定是要倒着求解,求出原来的数字是什么,然后对应回字母即可,这个过程很明显就是裸的中国剩余定理,并且题目告诉我们取模的数互质,因此就是直接套用一般情况的模板。

就是分解的过程恶心点,其他还倒好说,注意最后不能有空格

code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
ll a[10],m[10];
ll c[60];
char mark[30]="AABCDEFGHIJKLMNOPQRSTUVWXYZ ";
char s[200];
ll n;
ll ex_gcd(ll a,ll b,ll &x,ll &y){
    if(!b){
        x = 1;
        y = 0;
        return a;
    }
    ll g = ex_gcd(b,a%b,y,x);
    y -= a / b * x;
    return g;
}
ll CRT(){
    ll i,d,R,y,M,lcm = 1,sum = 0;
    for(int i = 0; i < 4; i++){
        lcm *= m[i];
    }
    for(int i = 0; i < 4; i++){
        M = lcm / m[i];
        d = ex_gcd(M,m[i],R,y);
        sum = (sum + R * M * a[i] % lcm) % lcm;
    }
    return (sum % lcm + lcm) % lcm;
}

int main(){
    ll tmp,T;
    scanf("%lld",&T);
    while(T--){
        scanf("%lld",&n);
        for(int i = 0; i < 4; i++){
            scanf("%lld",&m[i]);
        }
        for(int i = 0; i < n; i++){
            scanf("%lld",&tmp);
            for(int j = 3; j >= 0; j--){//将给定数字分成四个数即四个取模后的数
                a[j] = tmp % 100;
                tmp /= 100;
            }
            ll x = CRT();//利用中国剩余定理求出一个加密的六位数
            c[i] = x;
        }
        int len = 0;
        for(int i = 0; i < n; i++){
            vector<int>q;
            tmp = c[i];
            while(tmp){
                q.push_back(tmp%100);
                tmp /= 100;
            }//将得到的六位数两个两个分开
            while(!q.empty()){
                tmp = q.back();
                q.pop_back();
                s[len++] = mark[tmp];//然后一一对应到字母
            }
        }
        while(s[len-1] == ' ') len--;//除去末尾空格
        for(int i = 0; i < len; i++){//输出
            putchar(s[i]);
        }
        puts("");
    }
    return 0;
}
工业互联网工控安全与工业质检AI大模型建设方案.pptx 立即下载

相关推荐

毕设别再硬肝了:我用 GPT + Codex 做项目、写论文,效率直接起飞

这个也是神器。你项目做完之后,最怕的是老师一问就懵。这时候你直接把你的项目发给它,让它模拟老师提问。这是我的毕业设计题目和项目简介,请你站在答辩老师角度,提出20个高频问题,并给出简洁好背的回答。要求:问题尽量贴近计算机专业本科毕业答辩。为什么选这个题目?技术选型为什么这样定?你的创新点是什么?系统难点是什么?数据库怎么设计的?你的模型为什么选这个?如果继续优化,下一步怎么做?这个对答辩真的帮助很大。说实话,如果没有 GPT + Codex,

m0_74100417的博客 1841

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...

smilng的博客 213

标签传播算法LPA:半监督学习解决标注数据不足的完整实战指南

在机器学习实际工程中,标注数据稀缺往往是制约模型性能的核心瓶颈。半监督学习提供了一条利用海量未标注数据来增强模型泛化能力的有效路径,其中标签传播算法(Label Propagation Algorithm, LPA)因其直观的图结构和优雅的数学原理而备受关注。LPA通过将样本映射为图中的节点,以相似度作为边权重,让已知标签沿着图结构不断扩散,从而实现对未知样本的预测。其背后基于聚类假设与流形假设,能在低标注率场景下显著缓解过拟合问题,提升分类准确率。该技术在文本分类、金融风控、图像识别等存在大量无标注数据的

weixin_29056781的博客 239

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

Shirley 1692

Zynq裸机调试RTL8211FS网卡踩坑记:从ping不通到完美兼容的完整代码修改

本文详细记录了在Zynq平台上使用Xilinx SDK(XSDK)调试RTL8211FS网卡的完整过程,从最初的ping不通问题到最终实现完美兼容的解决方案。通过分析PHY芯片的寄存器配置差异,提供了关键代码修改和调试技巧,帮助开发者快速解决类似问题。

weixin_42550597的博客 418

零基础玩转NILM:用nilmtk提取UKDALE电器数据的保姆级教程

本文为零基础用户提供了一份详细的NILM入门指南,重点讲解如何使用nilmtk工具包从UKDALE数据集中提取电器级用电数据。教程涵盖环境搭建、核心概念解析、数据提取实战及常见问题排查,帮助读者快速掌握非侵入式负荷监测的数据预处理关键步骤。

rgv234567的博客 498

集训队专题(8)1004 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): 669    Accepted Submission(s): 288 Problem Descr

RaAlGhul的博客 769

Virtuoso集成HspiceD:打通模拟设计全流程的仿真与PEX实战

本文详细介绍了Virtuoso集成HspiceD在模拟设计全流程中的应用,包括仿真与PEX实战。通过无缝衔接Virtuoso和HspiceD,设计师可以在同一环境中完成从原理图设计到PEX后仿真的全流程,大幅提升工作效率。文章还提供了仿真环境配置、前仿真关键设置、PEX全流程详解以及性能调优等实用技巧。

weixin_29271263的博客 96

【HDU】 1930 And Now, a Remainder from Our Sponsor

And Now, a Remainder from Our Sponsor题目链接 And Now, a Remainder from Our Sponsor 题目大意    现在有4个互相互素的数m1,m2,m3,m4。而且有一句话需要你用这4个数去加密。加密方法:     01代表A,02代表B,03代表C…..26代表Z,27代表空格,每三个数组成一个六位数(或是五位数),然后对这4个数分别

S_Black的专栏 479

【DRAM存储器六十八】DDR5介绍--DQS Interval Oscillator—动态时序校准利器

DDR5内存采用DQS间隔振荡器(DQSIntervalOscillator)技术应对高速数据传输中的时序漂移问题。该技术通过测量DQS信号在可编程时间窗口内的振荡次数(16位计数值),动态监测温度/电压变化导致的DQS-DQ延迟偏移。控制器通过MPC命令启停振荡器,读取MR46/MR47寄存器获取计数值,并与基准值对比来调整DQS相位,确保数据采样窗口始终处于最佳位置。该机制使DDR5在8400MT/s高速率下仍能保持数据可靠性,有效补偿±0.48tCK的时序偏移。

highman110的博客 149

【推荐100个unity插件之7】使用BehaviorDesigner插件制作BOSS的AI行为树

Behavior Designer是一个行为树插件,是一款为了让策划,程序员,美术人员方便使用的可视化编辑器。Behavior Designer提供了强大的AP1可以让你轻松的创建tasks(任务),配合uScript和PlayMaker这样的插件,可以不费吹灰之力就能够创建出强大的Al系统,而无需写行代码。(不懂PlayMaker的,我后面在单独出文章介绍一下,可以期待一下)

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 6564

【数论】 HDOJ 1930 && ZOJ 2945 And Now, a Remainder from Our Sponsor

中国剩余定理的简单应用。。。给你

yysys 776

LDO参数解读、特性、参考设计

目录 一、工作原理 二、基本参数解释 三、LDO的一些特性 1、输出自放电 2、软启动 3、LDO效率 4、动态负载调整(∆VOUT) 5、线性瞬态响应 6、压差(Dropout Voltage) 四、参考设计 1、输入输出电容选择 2、Layout参考 一、工作原理 LDO是Low Dropout Regulator的缩写,意思是低压差线性稳压器,下面是LDO的内部框图,大致的工作原理就是:参考电压Vref和反馈电压FB(VOUT通过两个电阻分压)分别接在误差放大器的反向和正向

记得诚 1万+

SDUT 2222 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): 350Accepted Submission(s): 144 Problem Descrip...

weixin_30906701的博客 153

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

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): 479 Accepted Submission(s): 195 Problem Description

eeeaaaaa的专栏 602

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

#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): 950    Accepted Submission(s): 422 Problem Descripti

ElaineZXY的博客 426

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

HDU1930 And Now, a Remainder from Our Sponsor 解线性同余方程的应用

这道题过的人很少,原因肯定是因为英语,这题目意思i 我看了好久,英语太差了,题目的意思是: 先给你四个数,然后给你n个数,把n个数中的每一个数给拆成四个数,怎么拆按题目要求,拆出来的这四个数作为同余方程   x≡ai(mod ri) 中的 ri,最先给出的四个作为key的四个数,作为方程中的 ai,然后求出x, 总的意思就是先给你四个作为key的四个数, 给你n个数,把n个数中的每一个

shaonianguai 1307

【HDOJ】1930 And Now, a Remainder from Our Sponsor

简单字符串。 1 #include <stdio.h> 2 3 #define MAXLEN 160 4 5 char buf[MAXLEN]; 6 int keys[4], parts[4]; 7 8 void getpart(int x) { 9 int i; 10 for (i=3; i>=0; --i) { ...

weixin_33885253的博客 83

sdut newoj 2222 And Now, a Remainder from Our Sponsor

http://acm.sdut.edu.cn/web/problem.php?action=showproblem&problemid=2222 不算一个难题,就是刚一开始读题的时候感觉,题目真的好绕啊。题目的意思就是给你 一串字符串,三个一组(空格也算一个字符)的分开,按照它给的标准把这些字符串变成六位数一组的串,如果某个字符串最后不足三个,那么就用空格填充。然后呢,题目的输入是任意给...

weixin_30410119的博客 107

hdu 1930 And Now, a Remainder from Our Sponsor 扩展欧几里得 解一元线性同余方程组

/** * 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 n

小do在努力 2038

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...

weixin_30883777的博客 197

[SinGuLaRiTy] 数论题目复习

【SinGuLaRiTy-1020】 Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. [CQBZOJ 1464] Hankson 题目描述 Hanks博士是BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫Hankson。现在,刚刚放学回家的Hankson正在思考一个有趣的问题。 今天在课堂上,老师讲解了如何求两个正整...

weixin_34214500的博客 437

【莫队】BZOJ4542 [Hnoi2016] 大数

【前言】 我的莫队又没排序 【题目】 BZOJ 给定一个长度为nnn的字符串SSS以及一个模数PPP。QQQ次询问SSS的一个子串S[l…r]S[l\dots r]S[l…r]中有多少个子串表示的数字(去掉前导零后)是PPP的倍数。 n,m≤105,Pn,m\leq 10^5,Pn,m≤105,P是一个素数。 【解题思路】 首先我们不妨求出每个后缀所代表的数字对PPP取模的余数,设为cic_ici...

MEET YOU FIRST TIME 232

浙南联合训练赛20180214

这场比赛题目还行,但是被一道数学题卡了 A - Supermarket CodeForces - 919A We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, whe...

weixin_33810006的博客 200
上一篇: X问题(中国剩余定理不互质情况)
下一篇: 2^x mod n = 1(暴力或欧拉函数)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值