【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 ...
随机推荐
- HTML表单元素中disabled的元素的值不会提交到服务器
一.在HTMl页面的form表单中对disabled的元素的属性和值不会提交到服务器 实例1: <form action="#"> <input type=&qu ...
- C10K问题和Libevent库介绍
http://blog.chinaunix.net/uid-20761674-id-75056.html 一.C10K的问题 C10K的问题在上个世纪90年代就被提出来了.大概的意思是当用户数超过1万 ...
- Java线程间通信-回调的实现方式
Java线程间通信-回调的实现方式 Java线程间通信是非常复杂的问题的.线程间通信问题本质上是如何将与线程相关的变量或者对象传递给别的线程,从而实现交互. 比如举一个简单例子,有一个多线程的 ...
- java- 枚举的常见用法
用法一:常量 public enum MyColor{Red,Black,Blue} public enum Color { RED, GREEN, BLANK, YELLOW } enum为枚举类的 ...
- css滚动条样式
1.横向滚动条:(abeamScroll) <div style="width:400px;height:200px;overflow-x:auto;overflow-y:hidden ...
- scrapy, 自带命令行调用工具.
#-*- coding:utf-8 -*- from scrapy import cmdline cmdline.execute("scrapy crawl dmoz".split ...
- 用source code编译安装Xdebug
1. Unpack the tarball: tar -xzf xdebug-2.2.x.tgz. Note that you do not need to unpack the tarball i ...
- web前端工程师必须掌握的localStorage(二)
最近工作太忙了,回来后就很晚了,因为红牛喝太多都不想睡觉了(公司免费给的,好多箱o(╯□╰)o),睡不着就想着逛逛博客园,本人最近忙着做一个仿原生app的singlePage应用,话说最近后台那帮兄弟 ...
- JDK重要包和Java学习方法论
以下内容摘自:万能的林萧说:一篇文章教会你,如何做到简历中要求的“要有扎实的Java基础” 第一级别:精读源码 该级别包含的包如下: java.io java.lang java.util 第二 ...
- echo、print、print_r、printf、sprintf、var_dump的区别比较
一.echoecho() 实际上不是一个函数,是php语句,因此您无需对其使用括号.不过,如果您希望向 echo() 传递一个以上的参数,那么使用括号会发生解析错误.而且echo是返回void的,并不 ...