codeforces #305 C Mike and Foam】的更多相关文章

首先我们注意到ai<=50w 因为2*3*5*7*11*13*17=510510 所以其最多含有6个质因子 我们将每个数的贡献分离, 添加就等于加上了跟这个数相关的互素对 删除就等于减去了跟这个数相关的互素对 问题转化为了求跟某个数相关的互素对的数目 我们可以用容斥来解决 即加上至少跟这个数有0个公共质因子的数 减去至少跟这个数有1个公共质因子的数 加上至少跟这个数又2个公共质因子的数…… 这样我们就可以在2^6的时间算出答案了 #include<cstdio> #include<…
目录 Codeforces 547C/548E - Mike and Foam 题解 前置芝士 - 容斥原理 题意 想法(口胡) 做法 程序 感谢 Codeforces 547C/548E - Mike and Foam 题解 前置芝士 - 容斥原理 容斥原理是简单的小学奥数求多个集合的并集的算法,最基本的思想大概是如下内容: 这是一道简单例题:有\(10\)个学生喜欢唱歌,有\(15\)个学生喜欢跳舞,有\(5\)个学生两种活动都喜欢,没有不喜欢前述两种活动的学生,那么一共有多少个学生呢? 相…
挺简单的题目,但是有一堆恶心的边界 在刨去恶心的边界之后: 假定我们知道两边的循环节为b1,b2 其中h第一次到达目标的时间为a1,a2 又知道对于答案t t=a1+b1*t1=a2+b2*t2 不妨枚举t1,判断是否存在可行解即可 又因为LCM(b1,b2)就开始循环了 且b1*b2<=b1*mod 所以我们枚举t1的范围在[0,mod]即可 如果在这个范围内无解,则一定无解 #include<cstdio> #include<cstdlib> #include<cs…
跟之前做过的51Nod的移数博弈是一样的QAQ 我们考虑每个数的贡献 定义其左边第一个比他小的数的位置为L 定义其右边第一个比他小的数的位置为R 这个可以用排序+链表 或者 单调队列 搞定 那么对于区间长度1->(R-L-1),该数都可以作为最小值出现 我们在R-L-1上打上标记,最后从后往前来更新答案即可 至此问题得解 #include<cstdio> #include<cstring> #include<iostream> #include<algori…
正解貌似是大暴搜? 首先我们考虑这是一个二分图,建立网络流模型后很容易得出一个算法 S->行 容量为Num[X]/2; 行->列 容量为1 且要求(x,y)这个点存在 列->T 容量为Num[Y]/2 这样子跑网络流之后我们就得到了一组解 但是我们考虑输出方案 对于每一行,如果Num[X]为偶数,那么显然输出方案是正确的 但是如果Num[x]为奇数,多出的那个显然既有可能是红的也可能是蓝的 但关键是我们不能确定他是红的或者蓝的,因为他的状态也会影响对应的列 同样,列的考虑也是同理 所以我…
原问题可以转化为:给定第k个字符串,求它在L-R的字符串里作为子串出现了多少次 定义子串为字符串的某个前缀的某个后缀(废话) 等价于我们把一个字符串插入到trie里,其过程中每个经过的节点和其向上的fail链上的点都是该字符串的子串 又因为对于一条fail链,u向上能访问到v当前仅当u在v的子树内 那么原问题又变成了: 将L-R个字符串按照上述方法插入到trie中并将经过的节点的val值增加 求第k个字符串对应的单词节点在fail树上的子树的权值和 又因为查询的信息满足区间可减性,所以我们可以建…
hdu4135 求[L,R]范围内与N互质的数的个数. 分别求[1,L]和[1,R]和n互质的个数,求差. 利用容斥原理求解. 二进制枚举每一种质数的组合,奇加偶减. #include <bits/stdc++.h> using namespace std; typedef long long ll; ; int fac[N], cnt; void factor(int n) { cnt = ; int limit = sqrt(n); ; i <= limit; ++i) { ) fa…
C. Mike and Foam time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike is a bartender at Rico's bar. At Rico's, they put beer glasses in a special shelf. There are n kinds of beer at Rico's…
E. Mike and Foam Mike is a bartender at Rico's bar. At Rico's, they put beer glasses in a special shelf. There are n kinds of beer at Rico's numbered from 1 to n. i-th kind of beer has ai milliliters of foam on it. Maxim is Mike's boss. Today he told…
题意:给出数组arr和一个空数组dst.从arr中取出一个元素到dst为一次操作.问每次操作后dst数组中gcd等于1的组合数.由于数据都小于10^6,先将10^6以下的数分解质因数.具体来说从2开始,将2的倍数全部加2因子(用的vector),3的倍数加3因子.4不是质数,它的倍数不加因子. 还要一个cnt数组记录dst中有几个数是数组下标的倍数. 在放入元素x到dst数组,对于它的每个质因数及质因数间的乘积,看cnt中的量.组合数的增量为dst的sz(size)-(cnt[x的质因数])(即…
题面 链接:CF548E Description Mike is a bartender at Rico's bar. At Rico's, they put beer glasses in a special shelf. There are n kinds of beer at Rico's numbered from 1 to n. i-th kind of beer has *a**i* milliliters of foam on it. Maxim is Mike's boss. T…
题目链接 \(Description\) 给定n个数(\(1\leq a_i\leq 5*10^5\)),每次从这n个数中选一个,如果当前集合中没有就加入集合,有就从集合中删去.每次操作后输出集合中互质的数对个数. \(Solution1\) 考虑暴力一点,对于要修改的数分解质因数,集合中与它互质的数的个数就是 n-(有1个公共质因数)+(有2个公共质因数)-... 维护一下每种因子(可以是多个因数的积)对应集合中的多少个数就行. 真的好暴力..但是一个数的质因子大多也就4.5个,so是没问题的…
http://codeforces.com/problemset/problem/548/B Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column n…
Mike is a bartender at Rico's bar. At Rico's, they put beer glasses in a special shelf. There are n kinds of beer at Rico's numbered from 1to n. i-th kind of beer has ai milliliters of foam on it. Maxim is Mike's boss. Today he told Mike to perform q…
English reading: bartender == barmaid:酒吧女招待 milliliter:毫升:千分之一毫升 foam:泡沫 a glass of beer with a good head of foam:上面有厚厚一层泡沫的一杯啤酒 the greenness of the countryside:乡村的青葱翠绿 geek 题目:https://vjudge.net/contest/238720#problem/A 解析:http://codeforces.com/blo…
原题: Description Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1 to be the number of integer points in the segment [l, r] with l ≤ r (say that ). Y…
原题: Description While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, loc…
原题: Description Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of n intersections numbered from 1 to n. Mike starts walking from his house locate…
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   Description Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible! Aside from loving sweet things, thieves from this…
D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it…
好久好久好久之前的一个题,今天翻cf,发现这个题没过,补一下. B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one…
What-The-Fatherland is a strange country! All phone numbers there are strings consisting of lowercase English letters. What is double strange that a phone number can be associated with several bears! In that country there is a rock band called CF con…
http://codeforces.com/problemset/problem/548/E 这题是询问id,如果这个id不在,就插入这个id,然后求a[id1] ,  a[id2]互质的对数. 询问有多少个互质这个套路出了很多次,这次是在线 首先维护当前的ans,可以知道每一步的ans,都是由于上一步的ans递推过来的.就是小答案可以由大答案推过来. 就是现在数组是a[] = 1, 2, 3,维护一个ans表示有多少对gcd等于1,然后添加一个4,只需要询问4在a[] = {1, 2, 3}中…
题目链接: E. Mike and Geometry Problem time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geomet…
题目链接: C. Mike and Chocolate Thieves time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrib…
题目链接: B. Mike and Shortcuts time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some…
题目链接: A. Mike and Cellphone time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he…
[题目链接]:http://codeforces.com/contest/798/problem/A [题意] 让你严格改变一个字符,使得改变后的字符串为一个回文串; 让你输出可不可能; [题解] 直接无脑暴力改就好; 或者按照回文串的规则; 如果a[i]和a[n-i+1]不同则cnt++ 然后看看最后cnt是不是恰好为1,或者为0然后字符串长度为奇数(那样中间那个字符可以任意改) [Number Of WA] 0 [完整代码] #include <bits/stdc++.h> using n…
[题目链接]:http://codeforces.com/contest/798/problem/B [题意] 给你n个字符串; 每次操作,你可以把字符串的每个元素整体左移(最左边那个字符跑到最后面去了) 问你最少经过多少次操作可以使得所有字符串都相同; [题解] 枚举最后每个字符串都变成了哪一个字符串; 然后每个字符串都模拟一下左移的过程;直到相等记录总的移动次数; 或者左移超过了长度的次数;输出不可能能和目标串一样; 记录最小的移动次数就好; [Number Of WA] 0 [完整代码]…
[题目链接]:http://codeforces.com/contest/798/problem/C [题意] 给你n个数字; 要求你进行若干次操作; 每次操作对第i和第i+1个位置的数字进行; 将 a[i]变为a[i]-a[i+1],a[i+1]变为a[i]+a[i+1]; 然后问你能不能通过以上变换使得最后所有元素的gcd>1 [题解] 答案总是存在的; 因为把这个操作进行两次可以得到-2*a[i+1],2*a[i] 也就是如果对每相邻的元素进行操作,最后都能使得这两个元素都变成偶数; 最后…