http://codeforces.com/contest/357/problem/D

题意:给你两个数n和m,表示两个字符串的循环次数,然后给出两个字符串,求出其相同位置字符不同的个数。

先求出两个字符串长度的最大公约数和最小公倍数,然后求出在最小公倍数范围内的不同字符的个数,后面的和前面的一样,最终的个数也就求出了。

     #include <cstdio>
#include <cstring>
#include <algorithm>
#define LL __int64
using namespace std;
char s1[],s2[]; int count1[][]; LL GCD(LL a,LL b)
{
return b==?a:GCD(b,a%b);
} int main()
{
LL n,m;
while(scanf("%I64d%I64d",&n,&m)!=EOF)
{
scanf("%s",s1);
scanf("%s",s2);
LL k1=(LL)strlen(s1);
LL k2=(LL)strlen(s2);
LL c=GCD(k1,k2);
LL m=k1*k2/c;
LL m1=m;
for(int i=; i<k1; i++)
{
count1[i%c][s1[i]-'a']++;
}
for(int j=; j<k2; j++)
{
m-=count1[j%c][s2[j]-'a'];
}
printf("%I64d\n",m*((k1*n)/m1));
}
return ;
}

cf D. Xenia and Hamming的更多相关文章

  1. Codeforces Round #207 (Div. 1) B. Xenia and Hamming(gcd的运用)

    题目链接: B. Xenia and Hamming 题意: 要求找到复制后的两个字符串中不同样的字符 思路: 子问题: 在两串长度是最大公倍数的情况下, 求出一个串在还有一个串中反复字符的个数 CO ...

  2. CodeForces - 357D - Xenia and Hamming

    先上题目: D. Xenia and Hamming time limit per test 1 second memory limit per test 256 megabytes input st ...

  3. 【CF】207 Div.1 B.Xenia and Hamming

    这题目一看很牛逼,其实非常easy.求求最小公倍数,最大公约数,均摊复杂度其实就是O(n). /* 356B */ #include <iostream> #include <str ...

  4. CF #635D Xenia and Colorful Gems 枚举+二分

    Xenia and Colorful Gems 题意 给出三个数组,在每个数组中选择一个数字x,y,z,,使得\((x-y)^2+(y-z)^2+(x-z)^2\)最小. 思路 我们假设x<=y ...

  5. CF A. Xenia and Divisors

    题目大意: n(为三的倍数)个数的一个序列(每个数均不大于7),找出a,b,c a能被b整除,b能被c整除,序列中的每个数都被用到. 1 2 3 4 5 6 7 只有 1 2 4 1 2 6 1 3 ...

  6. cf C. Xenia and Weights

    http://codeforces.com/contest/339/problem/C #include <cstdio> #include <cstring> #includ ...

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

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

  8. CF&&CC百套计划2 CodeChef December Challenge 2017 Chef and Hamming Distance of arrays

    https://www.codechef.com/DEC17/problems/CHEFHAM #include<cstdio> #include<cstring> #incl ...

  9. CF R 635 div2 1337D Xenia and Colorful Gems 贪心 二分 双指针

    LINK:Xenia and Colorful Gems 考试的时候没想到一个很好的做法. 赛后也有一个想法. 可以考虑答案的样子 x,y,z 可以发现 一共有 x<=y<=z,z< ...

随机推荐

  1. 转自http://blog.sina.com.cn/daylive——C++ STL set&multiset

    C++ STL set和multiset的使用 1,set的含义是集合,它是一个有序的容器,里面的元素都是排序好的,支持插入,删除,查找等操作,就  像一个集合一样.所有的操作的都是严格在logn时间 ...

  2. CF- Day at the Beach

    C. Day at the Beach time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. linux内存管理--slab及其代码解析

    Linux内核使用了源自于 Solaris 的一种方法,但是这种方法在嵌入式系统中已经使用了很长时间了,它是将内存作为对象按照大小进行分配,被称为slab高速缓存. 内存管理的目标是提供一种方法,为实 ...

  4. hdu 4585 Shaolin(STL map)

    Problem Description Shaolin temple is very famous for its Kongfu monks.A lot of young men go to Shao ...

  5. ajax返回json数组遍历添加到html

    大致需求为类型限制根据类型获取不同结果列表,再根据模糊查询搜索出结果,效果如下:

  6. MongoDB每64位版本下载

    MongoDB每64位版本下载: http://dl.mongodb.org/dl/win32/x86_64 版权声明:本文博主原创文章,博客,未经同意不得转载.

  7. 忘记mysql 5.7的密码

    for windows: http://blog.chinaunix.net/uid-27570589-id-3511820.html 一.将net stop mysql; 二.在命令行中 C:\Us ...

  8. css让div水平垂直居中

    示例1: .div1{ width:200px; height:300px; border:1px solid #000; position: relative; } .div2{ width: 40 ...

  9. rsync在windows和linux同步数据的配置过程

    centos7.0安装rsync3.0.9-17.el7 yum install rsync ===================================================== ...

  10. Combo( 自定义下拉框) 组件

    本节课重点了解 EasyUI 中 Combo(自定义下拉框)组件的使用方法,这个组件依赖于ValidateBox(验证框)组件 一. 加载方式自定义下拉框不能通过标签的方式进行创建.<input ...