题目链接: 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. performSelector 多个参数

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

  2. Java并发编程 - 基本概念

    在开始我们的并发编程前,我们必须预热一下,一些基本概念必须了解. 1. 同步(Synchronous) / 异步(Asynchronous) 同步和异步都指一次方法调用. 同步:方法开始后,调用者必须 ...

  3. Android Studio 之 打包项目生成APK

    本文以使用Android Studio打包第一个apk的角度说明,打包APK分为两步:1生成 jks 密钥:2打包生成APK. 选择“ Build ”→选择“ Generate Signed APK. ...

  4. 创建一个入门的JAVA WEB站点(REST JERSEY)

    最近一直在看TOMCAT,想要自己创建一个小WEB站点,有不想要部署在其他的容器内这是一个不错的学习对象. 一.选择合适的模版 mvn archetype:generate -DarchetypeCa ...

  5. Objecttive-C各种问题

    1.invalid argument type 'void' to unary expression @try{ if (![mJQFMDB open]) { NSLog(@"Could n ...

  6. oracle数据库,怎么给已有数据的表添加自增字段

    场景:数据仓库,ODI为使用Oracle Incremental Update IKM,需要对一事实表增加主键. 思想:基于老表创建新表,添加自增字段(序列+触发器实现),把老数据导入新表,删除老表, ...

  7. dom4j 输出UTF-8 XML时中文乱码

    使用DOM4J的XMLWriter输出UTF-8编码的XML文件时,出现乱码 public static void writToXml(Document document) throws IOExce ...

  8. Vacuum tube 真空管/电子管

    真空管/电子管的发明 1904, John Ambrose Fleming invented the two-electrode vacuum-tube rectifier, which he cal ...

  9. Android中为图标加上数字

    Android中为图标加上数字--用于未读短信数提醒,待更新应用数提醒等 http://flysnow.iteye.com/blog/906770

  10. JavaScript 风格指南

    来源于: https://github.com/alivebao/clean-code-js 目录 介绍 变量 函数 对象和数据结构 类 测试 并发 错误处理 格式化 注释 介绍 作者根据 Rober ...