HDU1930 And Now, a Remainder from Our Sponsor

本文探讨了IBM编码算法的原理及其应用,包括如何将文本转换为编码信息,并通过中国余数定理进行解码。重点介绍了算法实现过程及注意事项。

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


Source
2007 East Central North America


被这题的输出坑出翔了。。。结尾最后不能有空格,测试数据里结尾有很多个空格的。。

题意:给n串密码,再给4个被取余的数,要求恢复成原来的一串数组(字符)。

分析:中国余数定理。定理里面涉及到了扩展欧几里得。 我的处理方法是从一串数的后面开始取出这些取余剩下的数,然后用中国余数定理处理下求出原来的那个串并记录下来,最后输入字符,也是从后面开始取出数字(这样可以不要管一个数前面的0),但是这样输出的顺序就反了,很简单,用个栈就可以了(先进后出)。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define LL __int64
using namespace std;
void exgcd(LL a,LL b,LL &d,LL &x,LL &y)
{
    if(!b)
        d=a,x=1,y=0;
    else
    {
        exgcd(b,a%b,d,y,x);
        y-=(a/b)*x;
    }
}
char mark[30]="AABCDEFGHIJKLMNOPQRSTUVWXYZ ";
char s[200];
LL aa[5],bb[5],n,c[55],m1;
LL reminder()
{
    LL m2,r1,r2,c,t,d,x,y;
    m1=aa[0],r1=bb[0];
    for(int i=1;i<4;i++)
    {
        m2=aa[i],r2=bb[i];
        exgcd(m1,m2,d,x,y);
        c=r2-r1;
        t=m2/d;
        x=(c/d*x%t+t)%t;
        r1=m1*x+r1;
        m1=m1*m2/d;
    }
    return r1;
}
int main()
{
    LL temp;
    int i,t,j;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%I64d",&n);
        for(i=0;i<4;i++)
            scanf("%I64d",&aa[i]);
        for(i=0;i<n;i++)
        {
            scanf("%I64d",&temp);
            for(j=3;j>=0;j--)
            {
                bb[j]=temp%100;
                temp/=100;
            }
            int x=reminder();
            c[i]=x;
        }
        int len=0;
        for(i=0;i<n;i++)
        {
            vector<int> q;
            temp=c[i];
            while(temp)
            {
                q.push_back(temp%100);
                temp/=100;
            }
            while(!q.empty())
            {
                temp=q.back();
                q.pop_back();
                s[len++]=mark[temp];
            }
        }
        while(s[len-1]==' ')
            len--;
        for(i=0;i<len;i++)
        printf("%c",s[i]);
        printf("\n");
    }
    return 0;
}


先展示下效果 https://pan.quark.cn/s/e81b877737c1 Node.js 是一种基于 Chrome V8 引擎的 JavaScript 执行环境,它使开发者能够在服务器端执行 JavaScript 编程,显著促进了全栈开发的应用普及。 在 Node.js 的开发流程中,`node_modules` 文件夹用于存储所有依赖的模块,随着项目的进展,该文件夹可能会变得异常庞大,其中包含了众多可能已不再需要的文件和文件夹,这不仅会消耗大量的硬盘空间,还可能减慢项目的加载时间。 `ModClean 2.0` 正是为了应对这一挑战而设计的工具。 `ModClean` 是一款用于清理 `node_modules` 的软件,其核心功能是移除那些不再被使用的文件和文件夹,从而确保项目的整洁性和运行效率。 `ModClean 2.0` 是此工具的改进版本,在原有功能上增加了更多特性,从而提高了清理工作的效率和精确度。 在 `ModClean 2.0` 中,用户可以设置清理规则,例如排除特定的模块或文件类型,以防止误删重要文件。 该工具通常会保留项目所依赖的核心模块,但会移除测试、文档、示例代码等非运行时必需的部分。 通过这种方式,`ModClean` 能够协助开发者优化项目结构,减少不必要的依赖,加快项目的构建速度。 使用 `ModClean` 的步骤大致如下:1. 需要先安装 `ModClean`,在项目的根目录中执行以下命令: ``` npm install modclean -g ```2. 创建配置文件 `.modcleanrc.json` 或 `.modcleanrc.js`,设定希望清理的规则。 比如,可能需要忽略 `LICENSE` 文件或整个 `docs`...
2026最新微信在线AI客服系统源码 微信客服AI系统是一款基于PHP开发的智能客服解决方案,完美集成企业微信客服,为企业提供7×24小时智能客服服务。系统支持文本对话、图片分析、视频分析等多种交互方式,并具备完善的对话管理、人工转接、咨询提醒等高级功能。 核心功能 ### 1.  智能AI客服 #### 自动回复 - **上下文理解**:系统自动保存用户对话历史,AI能够理解上下文,提供连贯的对话体验 - **个性化配置**:可自定义系统提示词、最大输出长度等AI参数 #### 产品知识库集成 - **公司信息**:支持配置公司简介、官网、竞争对手等信息 - **产品列表**:可添加多个产品,包括产品名称、配置、价格、适用人群、特点等 - **常见问题FAQ**:预设常见问题及答案,AI优先使用知识库内容回答 - **促销活动**:支持配置当前优惠活动,AI会自动向用户推荐 ### 2. 多媒体支持 #### 图片分析 - 支持用户发送图片,AI自动分析图片内容 - 可结合文字描述,提供更精准的分析结果 - 支持常见图片格式:JPG、PNG、GIF、WebP等 #### 视频分析 - 支持用户发送视频,AI自动分析视频内容 - 视频文件自动保存到服务器,提供公网访问 - 支持常见视频格式:MP4、等 ### 3.  人工客服转接 #### 关键词触发 - **自定义关键词**:可配置多个转人工触发关键词(如:人工、客服、转人工等) - **自动转接**:用户消息包含关键词时,自动转接给指定人工客服 - **友好提示**:转接前向用户发送提示消息,提升用户体验 #### 一键介入功能 - **后台管理**:管理员可在对话管理页面查看所有对话记录 - **快速转接**:点击"一键介入"按钮,立即将用户转接给人工客服
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值