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 ...
随机推荐
- Using a Microsoft Account to Logon and Resulting Internet Communication in Windows 8
Using a Microsoft Account to Logon and Resulting Internet Communication in Windows 8 此主题尚未评级 - 评价此主题 ...
- 第六周 Word目录和索引
第六周 Word目录和索引 教学时间 2013-4-2 教学课时 2 教案序号 5 教学目标 能正确使用索引.目录等 教学过程: 复习提问 1.脚注和尾注的区别是什么?2.如何插入脚注和尾注?3.如何 ...
- Vue - 起手式
0x00:前言 这次前言不想扯太多. 本文主要是记录一下自己的学习历程,顺带做一个总结. 当中有參考 Vue.js 的中文文档,也有去查看其它大大们给出的总结. 最后也是一个期盼,希望能够帮助到其它有 ...
- 最好使的歌词编辑工具--Beslyric
https://www.cnblogs.com/BensonLaur/p/6262565.html 感谢开发这么好的工具! 下载地址:http://beslyric.320.io/BesBlog/ ...
- [转发]jquery获取当前页面的URL信息
以前在做网站的时候,经常会遇到当前页的分类高亮显示,以便让用户了解当前处于哪个页面.之前一直是在每个不同页面写方法.工程量大,也不便于修改.一直在想有什么简便的方法实现.后来在网上查到可以用获取当前U ...
- [nQSError: 37001]Could not connect to the Oracle BI Server Instance
[nQSError: 37001]Could not connect to the Oracle BI Server Instance 使用本机的OBIEE Client 的Oracle BI管理工具 ...
- 一个封装的使用Apache HttpClient进行Http请求(GET、POST、PUT等)的类。
一个封装的使用Apache HttpClient进行Http请求(GET.POST.PUT等)的类. import com.qunar.payment.gateway.front.channel.mp ...
- excel单元格对齐方式
需要注意下面几点: 1.强制换行,ctrl+回车 2.快速设置缩进,当我们选择需要调整缩进的单元格之后,点击格式---单元格格式---选择水平对齐方式之后,可以选择缩进. 3.注意跨行居中功能,尤其是 ...
- python模块之importlib(py3中功能有明显加强)
# -*- coding: utf-8 -*-#python 27#xiaodeng#python模块之importlib(py3中功能有明显加强)
- codevs 2010 求后序遍历
时间限制: 1 s空间限制: 64000 KB题目描述 Description输入一棵二叉树的先序和中序遍历序列,输出其后序遍历序列.输入描述 Input Description共两行,第一行一个字符 ...