题目链接: B. Xenia and Hamming

题意: 要求找到复制后的两个字符串中不同样的字符

思路: 子问题: 在两串长度是最大公倍数的情况下, 求出一个串在还有一个串中反复字符的个数

CODE:

#include <iostream>
#include<stdio.h>
#include<string>
#include<string.h>
using namespace std;
#define M 1000006
int com[M][26];
int gcd(int a,int b)
{
return b==0? a:gcd(b,a%b);
}
int main()
{
long long n,m;
string x,y;
while(~scanf("%I64d%I64d",&n,&m))
{
cin>>x>>y;
memset(com,0,sizeof(com));
int lenx=x.size(),leny=y.size();
long long g=gcd(lenx,leny);
long long ans=lenx/g*leny;
long long a=ans;
for(int i=0;i<lenx;i++) //巧妙的处理~将两串中反复的字符储存起来
com[i%g][x[i]-'a']++;
for(int i=0;i<leny;i++)
ans-=com[i%g][y[i]-'a'];
printf("%I64d\n",ans*(n*lenx/a));
}
return 0;
}

Codeforces Round #207 (Div. 1) B. Xenia and Hamming(gcd的运用)的更多相关文章

  1. 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...

  2. Codeforces Round #207 (Div. 1) B (gcd的巧妙运用)

    比赛的时候不知道怎么写... 太弱了. 看了别人的代码,觉得这个是个经典的知识点吧. gcd的巧妙运用 自己想的时候苦苦思考怎么用dp求解. 无奈字符串太长而想不出好的算法. 其实在把a和b字符串都分 ...

  3. Codeforces Round #199 (Div. 2) B. Xenia and Spies

    B. Xenia and Spies time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    D. Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input ...

  5. Codeforces Round #207 (Div. 1) A. Knight Tournament (线段树离线)

    题目:http://codeforces.com/problemset/problem/356/A 题意:首先给你n,m,代表有n个人还有m次描述,下面m行,每行l,r,x,代表l到r这个区间都被x所 ...

  6. Codeforces Round #207 (Div. 1) A. Knight Tournament(STL)

    脑子又卡了...来一发set的,STL真心不熟. #include <stdio.h> #include <string.h> #include <iostream> ...

  7. Codeforces Round #199 (Div. 2) E. Xenia and Tree

    题目链接 2了,差点就A了...这题真心不难,开始想的就是暴力spfa就可以,直接来了一次询问,就来一次的那种,TLE了,想了想,存到栈里会更快,交又TLE了..无奈C又被cha了,我忙着看C去了.. ...

  8. Codeforces Round #207 (Div. 2) A. Group of Students

    #include <iostream> #include <vector> using namespace std; int main(){ ; cin >> m ...

  9. Codeforces Round #199 (Div. 2) A Xenia and Divisors

    注意题目的数字最大是7 而能整除的只有 1,2,3,4,6,故构成的组合只能是1,2,4 或1,2,6或1,3,6,故分别统计1,2,3,4,6的个数,然后再分配 #include <iostr ...

随机推荐

  1. Bootstrap相关网站中简单的等待提醒

    一.在页面中加入如下代码 <div class="modal fade" tabindex="-1" role="dialog" id ...

  2. 1064: 不明飞行物(ufo)

    #include<iostream> #include<string> using namespace std; int main(){ string a,b ; long m ...

  3. 使用fuel6.0自己主动安装openstack-juno版本号(2)

    上篇中fuel_master已经安装完毕.接下来我们介绍怎样新建一个openstack环境. 1,在web界面中新建openstack环境: 点击主界面的加入button,新建openstack环境. ...

  4. 〖Linux〗Kubuntu, the application 'Google Chrome' has requested to open the wallet 'kdewallet'解决方法

    每次打开Google都提示: the application 'Google Chrome' has requested to open the wallet 'kdewallet'... 原来是Go ...

  5. 【DB2】慎用nickname,可能会引起效率较低

    在使用db2的时候,在A库建立了nickname,指向B库的物理表(数据量800多万),现在使用程序(JDBC)连接数据库,并计算指标,但是发现效率很低. 解决办法: 删除A库中的nickname,在 ...

  6. 【DB2】清理日志文件db2diag.log

    在数据库运行过程中,会产生很多的日志,进而使日志文件db2diag.log变大 当占用磁盘空间太大的时候,应该怎么处理呢? 方法一: db2inst1@Linux:/db2home/db2inst1/ ...

  7. jqPlot图表插件学习之阴阳烛图

    一.准备工作 首先我们需要到官网下载所需的文件: 官网下载(笔者选择的是jquery.jqplot.1.0.8r1250.zip这个版本) 然后读者需要根据自己的情况新建一个项目并且按照如下的方式加载 ...

  8. 7、java5线程池之单一线程池newSingleThreadExecutor

    JDK文档说明: 创建一个使用单个 worker 线程的 Executor,以无界队列方式来运行该线程.(注意,如果因为在关闭前的执行期间出现失败而终止了此单个线程,那么如果需要,一个新线程将代替它执 ...

  9. Axure 富文本框

    百度网盘:http://pan.baidu.com/s/1c1ZjUPq

  10. 合并果子(NOIP2004)

    合并果子(NOIP2004)[问题描述]在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.多多决定把所有的果子合成一堆.每一次合并,多多可以把两堆果子合并到一起,消耗的体 ...