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 ...
随机推荐
- performSelector 多个参数
[self performSelector:@selector(callFooWithArray) withObject:[NSArray arrayWithObjects:@"first& ...
- vmware目录2
http://www.globalknowledge.com/training/course.asp?pageid=9&courseid=17880&country=United+St ...
- 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 ...
- .NET MVC中登陆授权过滤器的使用
1.写个类LoginAuthorityAttribute,继承自AuthorizeAttribute using System; using System.Collections.Generic; u ...
- Go语言中异常处理painc()和recover()的用法
Go语言中异常处理painc()和recover()的用法 1.Painc用法是:用于抛出错误.Recover()用法是:将Recover()写在defer中,并且在可能发生panic的地方之前,先调 ...
- Oracle 定时任务使用
1:首先创建存储过程 create or replace procedure pro_rqsl_hmd is rsCursor sys_refcursor; rqslid ); nsrsbh ); h ...
- Spring 开发环境搭建(二)
为了方面,直接使用eclipse,创建maven工程,创建成功之后 一.修改pom.xml,为了方面我就把Spring相关的jar包都引用了 <project xmlns="http: ...
- 〖Linux〗使用纯命令行来操作VBOX(宿主机不需要X11 Server)
1. Linux安装vbox,略过 2. 查看已安装扩展插件 VBoxManage list extpacks 3. 创建一个vm: VBoxManage createvm --name " ...
- Knockout学习之表单绑定器(上)
表单绑定器 “click”绑定 Click 绑定器可以将javascript函数绑定到指定的dom元素,并且再该元素被点击时将触发绑定的函数,大多数情况下都会使用button.input和a元素,当然 ...
- Aggressive cows
总时间限制: 1000ms 内存限制: 65536kB 描述 Farmer John has built a new long barn, with N (2 <= N <= 100,00 ...