Codeforces Round #207 (Div. 1) B. Xenia and Hamming(gcd的运用)
题目链接: 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的运用)的更多相关文章
- 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...
- Codeforces Round #207 (Div. 1) B (gcd的巧妙运用)
比赛的时候不知道怎么写... 太弱了. 看了别人的代码,觉得这个是个经典的知识点吧. gcd的巧妙运用 自己想的时候苦苦思考怎么用dp求解. 无奈字符串太长而想不出好的算法. 其实在把a和b字符串都分 ...
- 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 ...
- 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 ...
- 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所 ...
- Codeforces Round #207 (Div. 1) A. Knight Tournament(STL)
脑子又卡了...来一发set的,STL真心不熟. #include <stdio.h> #include <string.h> #include <iostream> ...
- Codeforces Round #199 (Div. 2) E. Xenia and Tree
题目链接 2了,差点就A了...这题真心不难,开始想的就是暴力spfa就可以,直接来了一次询问,就来一次的那种,TLE了,想了想,存到栈里会更快,交又TLE了..无奈C又被cha了,我忙着看C去了.. ...
- Codeforces Round #207 (Div. 2) A. Group of Students
#include <iostream> #include <vector> using namespace std; int main(){ ; cin >> m ...
- 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 ...
随机推荐
- Android Studio 之 环境搭建
从网上整理的安装步骤及初次使用问题解决. 一.安装步骤 1.安装前确认JDK已经安装并配置好环境变量(要求JDK1.7以上的版本). 2.官网下载Windows安装包,网上下载的版本是android- ...
- 實戰ESXi 5設置MPIO 打造IP-SAN負載平衡容錯
http://www.netadmin.com.tw/article_content.aspx?sn=1305100002 測試MPIO負載平衡及容錯移轉機制VMware vSphere ESXi主機 ...
- 默认的Sublime 3中没有Package Control
https://packagecontrol.io/installation#st3 (官方) 原来Subl3安装Package Control很麻烦,现在简单的方法来了 一.简单的安装方法 使用Ct ...
- 安装 mysql-5.6.4-m7
1.首先下载:http://cdn1.mydown.yesky.com/soft/201403/mysql-5.6.4-m7.tar.gz 2.解压,进入目录,执行cmake ./(如果没有cmake ...
- 超具体Windows版本号编译执行React Native官方实例UIExplorer项目(多图慎入)
),React Native技术交流4群(458982758).请不要反复加群! 欢迎各位大牛,React Native技术爱好者加入交流!同一时候博客右側欢迎微信扫描关注订阅号,移动技术干货,精彩文 ...
- Container [pid=6263,containerID=container_1494900155967_0001_02_000001] is running beyond virtual memory limits
以Spark-Client模式运行,Spark-Submit时出现了下面的错误: User: hadoop Name: Spark Pi Application Type: SPARK Applica ...
- unable to find the sources of your current Linux kernel.
运行 sh ./VBoxLinuxAdditions.run 时FAILED,查看日志: /tmp/vbox.0/Makefile.include.header:97: *** Error: unab ...
- SpringMVC学习笔记六:使用 hibernate-validator注解式数据校验
对客户端传过来的参数,在使用前一般需要进行校验. SpringMVC框架内置了Validator验证接口,但是实现起来太麻烦.我们一般使用 hibernate-validator进行数据校验. 1:j ...
- Oracle---->Join
最近使用ODI,其中有一个JOIN组件涉及到常见的几种JOIN类型,因此整理了下交叉连接和自然连接的区别. 一.概述 两个表的连接,是通过将一个表中的一列或者多列同另一个表中的列链接而建立起来的.用来 ...
- Oracle Data Integrator 12cR1 (12.1.3.0.0)安装过程
Oracle Data Integrator 12cR1 (12.1.3.0.0)安装过程 下载安装文件 Oracle Data Integrator 12cR1 (12.1.3.0.0) http: ...