【CF】207 Div.1 B.Xenia and Hamming
这题目一看很牛逼,其实非常easy。求求最小公倍数,最大公约数,均摊复杂度其实就是O(n)。
/* 356B */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const int maxn = 1e6+;
char s[maxn], d[maxn];
int cs[];
int cd[]; int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif __int64 n, m; scanf("%I64d %I64d", &n, &m);
scanf("%s %s", s, d);
int slen = strlen(s);
int dlen = strlen(d); int g = __gcd(slen, dlen);
__int64 lcm = 1LL * slen / g * dlen;
__int64 n_ = lcm / slen;
__int64 m_ = lcm / dlen; #ifndef ONLINE_JUDGE
printf("n_ = %I64d, m_ = %I64d\n", n_, m_);
#endif __int64 t = n / n_;
__int64 tot; __int64 ans = ;
int i, j, k; for (i=; i<g; ++i) {
// count s
memset(cs, , sizeof(cs));
for (j=i,tot=; j<slen; j+=g,++tot) {
++cs[s[j]-'a'];
}
for (j=i; j<dlen; j+=g) {
ans += (tot - cs[d[j]-'a']);
}
} ans *= t;
printf("%I64d\n", ans); #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}
【CF】207 Div.1 B.Xenia and Hamming的更多相关文章
- Codeforces Round #207 (Div. 1) B. Xenia and Hamming(gcd的运用)
题目链接: B. Xenia and Hamming 题意: 要求找到复制后的两个字符串中不同样的字符 思路: 子问题: 在两串长度是最大公倍数的情况下, 求出一个串在还有一个串中反复字符的个数 CO ...
- 【CF】121 Div.1 C. Fools and Roads
题意是给定一棵树.同时,给定如下k个查询: 给出任意两点u,v,对u到v的路径所经过的边进行加计数. k个查询后,分别输出各边的计数之和. 思路利用LCA,对cnt[u]++, cnt[v]++,并对 ...
- 【CF】310 Div.1 C. Case of Chocolate
线段树的简单题目,做一个离散化,O(lgn)可以找到id.RE了一晚上,额,后来找到了原因. /* 555C */ #include <iostream> #include <str ...
- 【CF】110 Div.1 B. Suspects
这题目乍眼一看还以为是2-sat.其实很水的,O(n)就解了.枚举每个人,假设其作为凶手.观察是否满足条件.然后再对满足的数目分类讨论,进行求解. /* 156B */ #include <io ...
- 【CF】222 Div.1 B Preparing for the Contest
这样类似的题目不少,很多都是一堆优化条件求最优解,这个题的策略就是二分+贪心.对时间二分, 对费用采用贪心. /* 377B */ #include <iostream> #include ...
- 【CF】142 Div.1 B. Planes
SPFA.注意状态转移条件,ans的求解需要在bfs中间求解.因为只要到了地点n,则无需等待其他tourist.还是蛮简单的,注意细节. /* 229B */ #include <iostrea ...
- 【CF】196 Div.2 D. Book of Evil
显然这个图是一课树,看着题目首先联想到LCA(肯定是可以解的).但是看了一下数据大小,应该会TLE.然后,忽然想到一个前面做过的题目,大概是在一定条件下树中某结点旋转成为根后查询最长路径.结果灵感就来 ...
- 【CF】223 Div.1 C Sereja and Brackets
水线段树. /* 380C */ #include <iostream> #include <string> #include <map> #include < ...
- 【CF】259 Div.1 B Little Pony and Harmony Chest
还蛮有趣的一道状态DP的题目. /* 435B */ #include <iostream> #include <string> #include <map> #i ...
随机推荐
- 20160406javaweb JDBC 实例工具类
一.建立静态的数据库配置文件: config.properties driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/datab ...
- ASP.NET MVC5总结(三)登陆中常用技术解析之session与cookie
1.session机制 session机制是在服务器端保持状态的方案,在做系统登陆时,我们往往会用到session来存储一些用户登录的重要信息,而这些信息是不能存在cookie中的. 当访问量增多时, ...
- UVA 11991 Easy Problem from Rujia Liu?(vector map)
Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...
- 使用GitHub For Windows托管Visual Studio项目
本文写得比较早,更新的在VS上使用GitHub的文章请移步:Visual Stuido 2015 Community 使用 GitHub 插件 因为最近同时再看很多技术方面的书,书上的例子有很多自己想 ...
- HTML知识点纲要(1)
什么是 HTML?HTML,全称是Hyper Text Markup Language,即超文本标记语言.是用来描述网页的一种标记语言. HTML 标签HTML标签是由尖括号包围的关键词,通常成对出现 ...
- go build 时报错 cc1.exe: sorry, unimplemented: 64-bit mode not compiled in
最近在玩Go win下尝试编译Go的时候遇到了下面提示(可能是gorocksdb用到了gcc) gcc也需要64位的 最后找到了个帖子: https://github.com/mattn/go-sql ...
- ubuntu server 安装
http://tigerlchen.iteye.com/blog/1765765 解决CDROM找不到的bug
- jQuery EasyUI tree中state属性慎用
EasyUI 1.4.4 tree控件中,如果是叶子节点,切忌把state设置为closed,否则该节点会加载整个tree,形成死循环 例如: json入下: [ { "checked&qu ...
- Chrome浏览器报错:Origin null is not allowed by Access-Control-Allow-Origin.
问题:Chrome浏览器报错:Origin null is not allowed by Access-Control-Allow-Origin. 原因:.js文件中使用load()方法,而Chrom ...
- node论坛练手
当时学node,自己写了个论坛练手,现在看还是有很多问题,有时间好好改改 https://github.com/hitbs228/countdown