Codeforces 920G - List Of Integers】的更多相关文章

920G - List Of Integers 思路:容斥+二分 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) vector<int>p; ll ans=; void dfs(int k,int cnt,ll s,ll r){ if(k==p.size()){ )ans-…
题目链接 题意 给定 \(x,p,k\),求大于 \(x\) 的第 \(k\) 个与 \(p\) 互质的数. 思路 参考 蒟蒻JHY. 二分答案 \(y\),再去 \(check\) 在 \([x,y]\) 区间中是否有 \(k\) 个与 \(p\) 互质的数. \(check\) 采用容斥,将 \(p\) 质因数分解,用这些质数组合成的数在 \([1,y]\) 范围内 容斥. Code #include <bits/stdc++.h> using namespace std; typedef…
E. K Integers 题目连接:https://codeforces.com/contest/1269/problem/E 题意 给了一个排列p,你每次操作可以交换两个相邻的元素,现在问你最少操作多少次可以形成一个形如1,2,3,4..k 这样的子段 k从1~n 题解: 都在期末考试了,这题解出的也太慢了,我来水一发 首先根据题意可得,要得到一个排好序的子段 对于k=1时,答案必为0 对于k=n时,肯定是将排列p排成1,2,3,...n的最少操作次数 那么当k在1~n之间时,最少操作次数应…
题意: 定义F(x,p)表示的是一个数列{y},其中gcd(y,p)=1且y>x 给出x,p,k,求出F(x,p)的第k项 x,p,k<=10^6 分析: 很容易想到先二分,再做差 然后问题就变成了[1,x]内有多少个数是和p互质的 我们可以先将p质因数分解,然后用这些数组合去在[1,x]容斥就行了 long long cal(long long x) { int n=f.size(); ; ;i<(<<n);++i) { ; ; ;j<n;++j) <<j…
Solved   CodeForces 920A Water The Garden   Solved   CodeForces 920B Tea Queue   Solved   CodeForces 920C Swap Adjacent Elements       CodeForces 920D Tanks       CodeForces 920E Connected Components?       CodeForces 920F SUM and REPLACE       CodeF…
A. Comparing Two Long Integers 题目连接: http://www.codeforces.com/contest/616/problem/A Description You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal.…
A. Search for Pretty Integers [题目链接]:http://codeforces.com/contest/872/problem/A time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given two lists of non-zero digits. Let's call an in…
G. List Of Integers time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output Let's denote as L(x, p) an infinite sequence of integers y such that gcd(p, y) = 1 and y > x (where gcd is the greatest…
题目链接:http://codeforces.com/problemset/problem/616/A 题目意思:顾名思义,就是比较两个长度不超过 1e6 的字符串的大小 模拟即可.提供两个版本,数组版本 & 指针版本. (1)数组版本(短的字符串从高位处补0,直到跟长的字符串长度相同) #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> using…
A. Comparing Two Long Integers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b i…
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11672&courseid=0 题目大意: 给定任意一个N,(N<=109)求斐波那契—卢卡斯数列的前两项A和B.(先满足B最小再满足A最小,A<=B) 斐波那契—卢卡斯数列是斐波那契数列的推广,斐波那契数列f[0]=0,f[1]=1,斐波那契—卢卡斯数列f[0]=A,f[…
Recently you have received two positive integer numbers xx and yy. You forgot them, but you remembered a shuffled list containing all divisors of xx (including 11 and xx) and all divisors of yy (including 11 and yy). If dd is a divisor of both number…
一.题目 二.题目链接 http://codeforces.com/contest/920/problem/G 三.题意 给定一个$t$,表示有t次查询.每次查询给定一个$x$, $p$, $k$,需要输出一个大于$x$.与$p$互质.第$k$大的数字.如样例1所示,比$7$大.与$22$互质.第$1$大的数字是$9$,第$2$大的数字是$13$,第$3$大的数字是$15$. 四.思路 二分+容斥原理. 二分一个数字$mid$,看看$[x+1,mid]$之间与$p$互质的数的个数.需要注意的是,…
1051E. Vasya and Big Integers 题意 给出三个大整数\(a,l,r\),定义\(a\)的一种合法的拆分为把\(a\)表示成若干个字符串首位相连,且每个字符串的大小在\(l,r\)之间,求每个字符串不能有前导零,求\(a\)有多少种合法的拆分方案. 题解 不难想到\(dp\),设\(dp_i\)表示前\(i\)个数有多少种合法的拆分方案. \(dp_i=\sum_{j=1}^i dp_{j-1}\)(从\(j+1~i\)拆分的数在\(l,r\)之间) 直接转移是\(O(…
D. Fun with Integers 题目链接:https://codeforc.es/contest/1062/problem/D 题意: 给定一个n,对于任意2<=|a|,|b|<=n,如果a->b,则存在一个x,使得x*a=b 或者 x*b=a,那么最终答案就是|x|的总和.相同的a,b不能被重复转化. 题解: 哎,这个复制过来格式各种错误,还是就这样吧... 我们发现当a->b时,-a->b,-a->-b,a->-b中的x对答案的贡献都是一样的,所以我…
题目描述 Let's denote as L(x,p)L(x,p) an infinite sequence of integers yy such that gcd(p,y)=1gcd(p,y)=1 and y>xy>x (where gcdgcd is the greatest common divisor of two integer numbers), sorted in ascending order. The elements of L(x,p)L(x,p) are 11 -ind…
链接:https://codeforces.com/contest/1269/problem/E 题意:给一个序列P1,P2,P3,P4....Pi,每次可以交换两个相邻的元素,执行最小次数的交换移动,使得最后存在一个子段1,2,…,k,这是题目所定义的f(k),题目要求求出所有的f(n),并依次输出. 思路:首先考虑逆序对问题,比如3 2 1 4这个序列,要使其变为1 2 3 4,最小的移动次数是这个序列中逆序对之和,2+1 = 3,逆序对是(3,2) (3,1)(2,1),但是在比如序列3…
You are given three integers a≤b≤ca≤b≤c . In one move, you can add +1+1 or −1−1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this ope…
水题 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; +; char s1[maxn],s2[maxn]; int a[maxn],b[maxn]; int lena,lenb; int c; int main() { scanf("%s%s",s1,s2); lena=strlen(s1); lenb=strlen(s2); c=; ;i>…
题意:给你N个点M条边,M-N<=20,有1e5个询问,询问两点的最短距离.保证没有自环和重边. 题解:连题目都在提示你这个20很有用,所以如果是颗树的话那任意两点的最短距离就是求一下lca搞一搞的问题.所以可以先求出最小生成树,那么会剩下最多42个点,我们知道非树边可能更优,所以对于每条非树边对应的两个点跑一遍dij,尝试更新答案ans=min(ans,dis[i][u]+dis[i][v]).正确性:可能通过多条非树边?在跑dij时其实已经处理出了最短的路,如果是通过多条非树边更优,那么它记…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 先枚举一个数字的情况. 再枚举两个数的情况就好. [代码] #include <bits/stdc++.h> #define ll long long using namespace std; const int N = 20; int a[N],b[N],n,m; int main() { //freopen("F:\\rush.txt","r",stdin); scanf("…
题意:给定字符串S,A,B.现在让你对S进行切割,使得每个切割出来的部分在[A,B]范围内,问方案数. 思路:有方程,dp[i]=Σ dp[j]   (S[j+1,i]在合法范围内).    假设M和N的最长公共前缀为长度是LCP,那么字符串M>=字符串N的条件是  LCP=|N|或者(LCP<|N|&&M[lcp+1]>N[lca+1]): 小于同理. 求出范围就可以用前缀和 O(N)求DP了. 而LCP显然可以用exkmp求. 最近发现Z算法比较好写.  尝试了一下.…
题意: a<=b<=c 输出A,B,C要求B是A的倍数,C是B的倍数,并且输出a,b,c变成A,B,C需要的最小次数. 题解:写了半天的二分,后来发现思路错了,,,暴力就能过.. 三层for,第二层是第一层的倍数,第三层是第二层的倍数.... #include<bits/stdc++.h> using namespace std; typedef long long ll; const ll N=1e4; ; struct stu { ll a,b,c; }x; void solv…
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of bconsecutive cells. No cell can be part of two ships, however, the shi…
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's…
codeforces 459E E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he…
 cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....       其实这个应该是昨天就写完的,不过没时间了,就留到了今天.. 地址:http://codeforces.com/contest/651/problem/A A. Joysticks time limit per test 1 second memory limit per test 256…
Mike and Feet Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 548D Appoint description:  Description Mike is the president of country What-The-Fatherland. There are n bears living in thi…
Codeforces #261 D D. Pashmak and Parmida's problem time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Parmida is a clever girl and she wants to participate in Olympiads this year. Of course s…
Codeforces#262_1002 B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him…