题目链接: B. Xenia and Hamming

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

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

CODE:

  1. #include <iostream>
  2. #include<stdio.h>
  3. #include<string>
  4. #include<string.h>
  5. using namespace std;
  6. #define M 1000006
  7. int com[M][26];
  8. int gcd(int a,int b)
  9. {
  10. return b==0?
  11.  
  12. a:gcd(b,a%b);
  13. }
  14. int main()
  15. {
  16. long long n,m;
  17. string x,y;
  18. while(~scanf("%I64d%I64d",&n,&m))
  19. {
  20. cin>>x>>y;
  21. memset(com,0,sizeof(com));
  22. int lenx=x.size(),leny=y.size();
  23. long long g=gcd(lenx,leny);
  24. long long ans=lenx/g*leny;
  25. long long a=ans;
  26. for(int i=0;i<lenx;i++) //巧妙的处理~将两串中反复的字符储存起来
  27. com[i%g][x[i]-'a']++;
  28. for(int i=0;i<leny;i++)
  29. ans-=com[i%g][y[i]-'a'];
  30. printf("%I64d\n",ans*(n*lenx/a));
  31. }
  32. return 0;
  33. }

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. performSelector 多个参数

    [self performSelector:@selector(callFooWithArray) withObject:[NSArray arrayWithObjects:@"first& ...

  2. vmware目录2

    http://www.globalknowledge.com/training/course.asp?pageid=9&courseid=17880&country=United+St ...

  3. VMware Lab setup - A virtualized lab for testing HA and DRS

    https://www.simple-talk.com/sysadmin/virtualization/vmware-lab-setup---a-virtualized-lab-for-testing ...

  4. .NET MVC中登陆授权过滤器的使用

    1.写个类LoginAuthorityAttribute,继承自AuthorizeAttribute using System; using System.Collections.Generic; u ...

  5. Go语言中异常处理painc()和recover()的用法

    Go语言中异常处理painc()和recover()的用法 1.Painc用法是:用于抛出错误.Recover()用法是:将Recover()写在defer中,并且在可能发生panic的地方之前,先调 ...

  6. Oracle 定时任务使用

    1:首先创建存储过程 create or replace procedure pro_rqsl_hmd is rsCursor sys_refcursor; rqslid ); nsrsbh ); h ...

  7. Spring 开发环境搭建(二)

    为了方面,直接使用eclipse,创建maven工程,创建成功之后 一.修改pom.xml,为了方面我就把Spring相关的jar包都引用了 <project xmlns="http: ...

  8. 〖Linux〗使用纯命令行来操作VBOX(宿主机不需要X11 Server)

    1. Linux安装vbox,略过 2. 查看已安装扩展插件 VBoxManage list extpacks 3. 创建一个vm: VBoxManage createvm --name " ...

  9. Knockout学习之表单绑定器(上)

    表单绑定器 “click”绑定 Click 绑定器可以将javascript函数绑定到指定的dom元素,并且再该元素被点击时将触发绑定的函数,大多数情况下都会使用button.input和a元素,当然 ...

  10. Aggressive cows

    总时间限制: 1000ms 内存限制: 65536kB 描述 Farmer John has built a new long barn, with N (2 <= N <= 100,00 ...