poj3535 A+B (大数加法)

A+B
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 811 Accepted: 371

Description

The Research Institute of Given Strings (RIGS) is a well-known place where people investigate anything about strings. Peter works in the department of string operations of RIGS. His department invents different ways to add, multiply, divide strings and even to take a logarithm of a string based on another one.

Now Peter is involved in the new project concerning orthogonal strings. Peter proposed that two strings P = P1P2Pn and Q = Q1Q2Qn of equal length n are called orthogonal, if Pi ≠ Qi for each i in the range 1..n. String S of length n is called orthogonal to set of strings V = ‹V1V2, …, Vm› (each of length n too) if S is orthogonal to Vj for any j in range 1..m.

Peter’s task is to invent the operation of orthogonal sum of two given strings. The current Peter’s proposal allows to add only strings on a basis of some set, if they are orthogonal to this set. To do this, Peter selects an arbitrary set of strings V such that all strings in V have the same length n. Then Peter takes all strings of length n orthogonal to V over a fixed alphabet and sorts them, thus obtaining a sorted sequence of strings T. Let’s denote the length of sequence T as M, and enumerate the elements of this sequence as T0T1, …, TM−1. Now Peter says that the orthogonal sum of two strings A = Ta and B = Tb is a string C = Tc where c = (a + b) modM.

Your task is to find the orthogonal sum of two given strings A and B on the basis of a given set V over the alphabet of small English letters.

Input

The first line of the input file contains two integers: n — the length of each string (1 ≤ n ≤ 100 000) and k — the cardinality of V (1 ≤ n ⋅ k ≤ 100 000). The next k lines contains strings V1V2, …, Vk.

The last two lines contain strings A and B of length n. All strings VjA and B consist of small letters of English alphabet. It is guaranteed that A and B are orthogonal to V.

Output

Output the orthogonal sum of strings A and B on the basis V.

Sample Input

#12 2
ac
ad
bb
bb
#22 1
yy
zz
zz

Sample Output

 

#1be
#2zx

 

 

题意:题意蛋疼。。 给出k个长度为n的字符串集合,再给出两个长度也是n的字符串AB。然后构建一个新的集合,要求集合里的每一个字符串都和原集合里每一个字符串正交,这里正交的意思是,对字符串P和Q的每一个位置有Pi 不等于 Qi 。新集合排序后,从0到M-1编号,然后就可以得到A、B在新集合的下标(数据保证A、B与原集合正交),把下标相加对M求余,得到新下标,此下标对应字符串为题目所求

思路:把k条字符串每一个位置上出现过的字母记录下来,统计这个位置上还有多少个字母没出现过,那这个数字就是这个位置上的进制了,对A、B转换为进制数,然后就是进行一次大数加法了。例如题目给ac/ae,那数目分别为25/24,那么bb对应的数字就是01,bb+bb=01+01=02=be

 

代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <utility>
#include <queue>
#include <stack>
using namespace std;
typedef pair<int,int> pii;
const int INF=1<<30;
const double eps=1e-6;
const int N = 100010;
char s[N],a[N],b[N],c[N];
bool vis[N][30];
int n,k,cnt[N];
void rev(char *s)
{
    int l=0,r=n-1;
    for(;l<r;l++,r--)
        swap(s[l],s[r]);
}
void read()
{
    memset(vis,0,sizeof(vis));
    memset(cnt,0,sizeof(cnt));
    while(k--)
    {
        scanf("%s",s);
        rev(s);
        for(int i=0;i<n;++i)
            vis[i][s[i]-'a']=1;
    }
    for(int i=0;i<n;++i)
        for(int j=0;j<26;++j)
            if(!vis[i][j])
                cnt[i]++;
}
int ctoint(int idx,char c)
{
    c = c-'a';
    int res=0;
    for(int i=0;i<c;++i)
        if(!vis[idx][i])
            res++;
    return res;
}
char inttoc(int idx,int x)
{
    int i;
    for(i=0;;i++)
        if(!vis[idx][i] && (x--)==0)
            break;
    return i+'a';
}
void run()
{
    read();
    scanf("%s%s",a,b);
    rev(a);
    rev(b);
    int rem=0,tmp;
    for(int i=0;i<n;++i)
    {
        tmp = rem + ctoint(i,a[i]) + ctoint(i,b[i]);
        c[i] = tmp%cnt[i];
        rem = tmp/cnt[i];
    }
    for(int i=0;i<n;++i)
        c[i] = inttoc(i,c[i]);
    for(int i=n-1;i>=0;--i)
        putchar(c[i]);
    puts("");
}

int main()
{
    freopen("case.txt","r",stdin);
    while(scanf("%d%d",&n,&k)!=EOF)
        run();
    return 0;
}

 

转载于:https://www.cnblogs.com/someblue/p/3932506.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的体育馆管理系统,源码+数据库+毕业论文+视频演示 现代经济快节奏发展以及不断完善升级的信息化技术,让传统数据信息的管理升级为软件存储,归纳,集中处理数据信息的管理方式。本体育馆管理系统就是在这样的大环境下诞生,其可以帮助管理者在短时间内处理完毕庞大的数据信息,使用这种软件工具可以帮助管理人员提高事务处理效率,达到事半功倍的效果。此体育馆管理系统利用当下成熟完善的SpringBoot框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的Mysql数据库进行程序开发。实现了用户在线选择试题并完成答题,在线查看考核分数。管理员管理收货地址管理、购物车管理、场地管理、场地订单管理、字典管理、赛事管理、赛事收藏管理、赛事评价管理、赛事订单管理、商品管理、商品收藏管理、商品评价管理、商品订单管理、用户管理、管理员管理等功能。体育馆管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 关键词:体育馆管理系统;SpringBoot框架;Mysql;自动化
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值