poj3535 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 = P1P2…Pn and Q = Q1Q2…Qn 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 = ‹V1, V2, …, 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 T0, T1, …, 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 V1, V2, …, Vk.
The last two lines contain strings A and B of length n. All strings Vj, A 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
| #1 | 2 2 ac ad bb bb |
|---|---|
| #2 | 2 1 yy zz zz |
Sample Output
| #1 | be |
|---|---|
| #2 | zx |
题意:题意蛋疼。。 给出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=<<;
const double eps=1e-;
const int N = ;
char s[N],a[N],b[N],c[N];
bool vis[N][];
int n,k,cnt[N];
void rev(char *s)
{
int l=,r=n-;
for(;l<r;l++,r--)
swap(s[l],s[r]);
}
void read()
{
memset(vis,,sizeof(vis));
memset(cnt,,sizeof(cnt));
while(k--)
{
scanf("%s",s);
rev(s);
for(int i=;i<n;++i)
vis[i][s[i]-'a']=;
}
for(int i=;i<n;++i)
for(int j=;j<;++j)
if(!vis[i][j])
cnt[i]++;
}
int ctoint(int idx,char c)
{
c = c-'a';
int res=;
for(int i=;i<c;++i)
if(!vis[idx][i])
res++;
return res;
}
char inttoc(int idx,int x)
{
int i;
for(i=;;i++)
if(!vis[idx][i] && (x--)==)
break;
return i+'a';
}
void run()
{
read();
scanf("%s%s",a,b);
rev(a);
rev(b);
int rem=,tmp;
for(int i=;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=;i<n;++i)
c[i] = inttoc(i,c[i]);
for(int i=n-;i>=;--i)
putchar(c[i]);
puts("");
} int main()
{
freopen("case.txt","r",stdin);
while(scanf("%d%d",&n,&k)!=EOF)
run();
return ;
}
poj3535 A+B (大数加法)的更多相关文章
- 51nod 1005 大数加法
#include<iostream> #include<string> using namespace std; #define MAXN 10001 },b[MAXN]={} ...
- c#大数加法
在C#中,我们经常需要表示整数.但是,c#的基本数据类型中,最大的long也只能表示-9,223,372,036,854,775,808 到 9,223,372,036,854,775,807之间的数 ...
- 玲珑杯1007-A 八进制大数加法(实现逻辑陷阱与题目套路)
题目连接:http://www.ifrog.cc/acm/problem/1056 DESCRIPTION Two octal number integers a, b are given, and ...
- Leetcode 67 Add Binary 大数加法+字符串处理
题意:两个二进制数相加,大数加法的变形 大数加法流程: 1.倒置两个大数,这一步能使所有大数对齐 2.逐位相加,同时进位 3.倒置两个大数的和作为输出 class Solution { public: ...
- HDU1002大数加法
大数加法 c++版: #include <map> #include <set> #include <stack> #include <queue> # ...
- java实现大数加法、乘法(BigDecimal)
之前写过用vector.string实现大数加法,现在用java的BigDecimal类,代码简单很多.但是在online-judge上,java的代码运行时间和内存大得多. java大数加法:求a+ ...
- vector、string实现大数加法乘法
理解 vector 是一个容器,是一个数据集,里边装了很多个元素.与数组最大的不同是 vector 可以动态增长. 用 vector 实现大数运算的关键是,以 string 的方式读入一个大数,然后将 ...
- 【大数加法】POJ-1503、NYOJ-103
1503:Integer Inquiry 总时间限制: 1000ms 内存限制: 65536kB 描述 One of the first users of BIT's new supercompu ...
- A + B Problem II 大数加法
题目描述: Input The first line of the input contains an integer T(1<=T<=20) which means the number ...
随机推荐
- EasyPlayerPro windows播放器本地配置文件配置方法介绍
需求背景 应EasyPlayerPro某客户需求,在EasyPlayerPro启动时,自动播放指定的url源, 不需要每次都去手动填写, 且实现自动播放,不需要手动的单击播放按钮: 为响应该需求,特增 ...
- Webpack探索【16】--- 懒加载构建原理详解(模块如何被组建&如何加载)&源码解读
本文主要说明Webpack懒加载构建和加载的原理,对构建后的源码进行分析. 一 说明 本文以一个简单的示例,通过对构建好的bundle.js源码进行分析,说明Webpack懒加载构建原理. 本文使用的 ...
- ABAP 数值转换大写
转自:http://www.dasunny.com/wordpress/sapnotes/2015113091.htmlSAP标准的数值转换函数 SPELL_AMOUNT, 仅对整数部分进行了处理,小 ...
- Gemini.Workflow 双子工作流入门教程四:流程应用
简介: Gemini.Workflow 双子工作流,是一套功能强大,使用简单的工作流,简称双子流,目前配套集成在Aries框架中. 下面介绍本篇教程:定义流程:流程应用. 流程应用: 流程图设计好后, ...
- SpringBoot学习笔记(8):事物处理
SpringBoot学习笔记(8):事物处理 快速入门 在传统的JDBC事务代码开发过程中,业务代码只有一部分,大部分都是与JDBC有关的功能代码,比如数据库的获取与关闭以及事务的提交与回滚.大量的t ...
- ListView多选和单选模式重新整理
超简单的单选和多选ListView 在开发过程中,我们经常会使用ListView去呈现列表数据,比如商品列表,通话记录,联系人列表等等,在一些情况下,我们还需要去选择其中的一些列表数据进行编辑.以前, ...
- Codeforces Round #551 (Div. 2) A~E题解
突然发现上一场没有写,那就补补吧 本来这场应该5题的,结果一念之差E fail了 A. Serval and Bus 基本数学不解释,假如你没有+1 -1真的不好意思见人了 #include<c ...
- BZOJ 1680 [Usaco2005 Mar]Yogurt factory:贪心【只用考虑上一个】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1680 题意: 在接下来的n周内,第i周生产一吨酸奶的成本为c[i],订单为y[i]吨酸奶. ...
- 分享知识-快乐自己:SpringMVC 结合使用拦截器(判断是否用户是否已登陆)
基础拦截器操作: 拦截器是一种AOP操作实现,那么在AOP之中用户一定不需要去关注拦截器的存在,用户只需要按照自己已经习惯的处理方式进行代码的编写即可. 首先我们先创建一个自定义的拦截器: packa ...
- Multiple webcams on ZoneMinder
Monitoring a 3D Printer I have tidied my new workshop and I am starting to play with 3d-printing aga ...