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 ...
随机推荐
- ThreadLocal与Synchronized
package com.demo; import org.hibernate.HibernateException; import org.hibernate.classic.Session; imp ...
- ldd 以及 ld-linux.so.2
最近跟编译工具干上了,可能是问题积累集中爆发的结果. 今天对 ld-linux.so.x 有很大兴趣,想对它多些了解,遂百度之.发现了指令 ldd. 关于 ldd 其实 ldd 是一个脚本,并不是一个 ...
- Mysql查询优化之 触发器加中间表 方法优化count()统计大数据量总数问题
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6138288.html 在上一篇博文我们提到,分页有三种方法.其中,第三种是我们最常用的.然而,在实际应用过程中 ...
- OdiSendMail
在Package中使用ODI自带的发送邮件OdiSendMail,生成的场景迁移到正式环境中,提示 javax.mail.AuthenticationFailedException: failed t ...
- 【Windows】XShell中使用小键盘和ALT键(作Meta键),使BackSpace正常
小键盘: 打开终端的Session属性,VT模式,初始数字键盘模式,设置为普通 ALT键: 打开终端的Session属性,元(Meta)键仿真,将ALT用作Meta键 BackSpace: 打开终端的 ...
- java第三节 面向对象(上)
//第三讲 //面向对象(上) /* 理解面向对象的概念 面向过程 在一个结构体中定义窗体的大小,位置,颜色,背景等属性,对窗口操作的函数窗口本身的定义没有任何关系 如HideWindow, Move ...
- NTCPMSG 开源高性能TCP消息发送组件
https://www.cnblogs.com/eaglet/archive/2013/01/07/2849010.html 目前的.net 架构下缺乏高效的TCP消息发送组件,而这种组件是构建高性能 ...
- 进程间通过intent传递数据失败
<activity android:name=".activity.CreateMessageActivity" android:pr ...
- selectAll, unSelectAll两个操作的实现
private void updateBatchSelectionStatus() { ContactListAdapter.ViewHolder viewHolder = null; ...
- django日志使用TimeRotateFileHandler
如果使用django的settings.py设置日志会产生一些问题. 问题描述 报错信息如下: Traceback (most recent call last): File "C:\Pyt ...