[codeforces] 449C Jzzhu and Apples】的更多相关文章

Jzzhu and Apples 从大的质因子开始贪心, 如果有偶数个则直接组合, 如果是奇数个留下那个质数的两倍, 其余两两组合. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair&l…
原题 质因数分解后贪心即可(最后贪2) #include<cstdio> #include<vector> #include<stack> #include<vector> #include<cstring> #define N 100010 using namespace std; bool is[N],mk[N]; int prime[N],num=1,cnt,n,a,b; stack <int> ans; vector <…
E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to…
C. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to…
E. Jzzhu and Apples time limit per test: 1 seconds memory limit per test: 256 megabytes input: standard input output: standard output Jzzhu has picked \(n\) apples from his big apple tree. All the apples are numbered from \(1\) to \(n\). Now he wants…
Codeforces Round #257 (Div. 1) C Codeforces Round #257 (Div. 1) E CF450E C. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tre…
/* http://codeforces.com/problemset/problem/449/C cf 449 C. Jzzhu and Apples 数论+素数+贪心 */ #include <cstdio> #include <algorithm> using namespace std; ; int is_prime[Nmax]; int book[Nmax]; int cnt[Nmax]; int n,ans; void get__prime() { ;i<=n;i…
CodeForces 450B Jzzhu and Sequences (矩阵优化) Description Jzzhu has invented a kind of sequences, they meet the following property: \[f_1=x\] \[f_2=y\] \[f_i=f_{i-1}+f_{i+1}\text {(i>2)}\] You are given x and y, please calculate fn modulo 1000000007 (10…
E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to…
题目描述: Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of…
大意: 求从[1,n]范围选择尽量多的数对, 使得每对数的gcd>1 考虑所有除2以外且不超过n/2的素数p, 若p倍数可以选择的有偶数个, 直接全部划分即可 有奇数个的话, 余下一个2*p不划分, 其余全部划分 最后再将2的倍数全部划分一下即可 #include <iostream> #include <math.h> #include <string.h> #include <algorithm> #include <cstdio> #…
题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的个数是最多的,所以最后处理.然后处理3,5,7,11...的倍数的数,之前已经挑过的就不能再选了.要是一个素数p的倍数个数是奇数,就把2*p给2 的倍数.这样可以满足p倍数搭配的对数是最优的.最后处理2的倍数就行了. #include <bits/stdc++.h> using namespace…
http://codeforces.com/contest/450/problem/C 题意:一个n×m的矩形,然后可以通过横着切竖着切,求切完k次之后最小矩形面积的最大值. 思路:设k1为横着切的次数,k2为竖着切的次数,最后的面积的大小为s=n/(k1+1)*(m/(k2+1)); 只有(k1+1)*(k2+1)的最小时,s最大. #include <cstdio> #include <iostream> #include <cstring> #include &l…
http://codeforces.com/problemset/problem/449/D 题意:给n个数,求and起来最后为0的集合方案数有多少 思路:考虑容斥,ans=(-1)^k*num(k),num(k)代表至少有k个数字and起来为1的方案数,那么怎么求num呢? 考虑and起来至少为x的方案数:那么一定是2^y-1,其中y代表有多少个数&x==x,问题就变成有多少数"包含"了某个数(二进制下),用dp解决这个问题:如果某一位数字是1,那么它一定能转移到它不是1的那…
[题目链接] http://codeforces.com/problemset/problem/449/D [题目大意] 给出一些数字,问其选出一些数字作or为0的方案数有多少 [题解] 题目等价于给出一些集合,问其交集为空集的方案数, 我们先求交集为S的方案数,记为dp[S],发现处理起来还是比较麻烦, 我们放缩一下条件,求出交集包含S的方案数,记为dp[S], 我们发现dp[S],是以其为子集的方案的高维前缀和, 我们逆序求高维前缀和即可,之后考虑容斥,求出交集为0的情况, 我们发现这个容斥…
Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, please calculate fn modulo 1000000007 (109 + 7). Input The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single i…
题目链接:https://vjudge.net/problem/CodeForces-450B B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has invented a kind of sequences, they meet the following proper…
题目链接:http://codeforces.com/contest/450/problem/C 题目意思:给出一个 n * m 大小的chocolate bar,你需要在这个bar上切 k 刀,使得最小的部分面积尽可能大,求出这个被划分后的最小部分面积最大可以为多少.如果这个chocolate bar 不能切成 k 部分,则输出-1.注意,每一刀需要符合3个条件:1.打横切或者打竖切: 2.每一刀只能经过unit square(即1*1的单元bar)的边,也就是说不能把一个单元bar损坏,要完…
题目链接:http://codeforces.com/problemset/problem/450/B 题目意思:给出 f1 和 f2 的值,以及n,根据公式:fi = fi-1 + fi+1,求出fn是多少. 这题通过手工模拟,可以发现它有一个周期的:以6为周期! f1 = f1,   f2 = f2,   f3 = f2 - f1 f4 = -f1,  f5 = -f2,  f6 = -f2 + f1 以前从来不知道负数的模怎么求,这题刚好考到!其实根据第二个test约莫猜到,就是要加上要m…
[题目链接] https://codeforces.com/contest/449/problem/B [算法] 最短路 时间复杂度 : O(N ^ 2) [代码] #include<bits/stdc++.h> using namespace std; ; const int INF = 2e9; int n , m , k; int mark[MAXN]; long long dist[MAXN]; bool inq[MAXN]; vector< pair<int,int>…
输入一个无向图<V,E>    V<=1e5, E<=3e5 现在另外给k条边(u=1,v=s[k],w=y[k]) 问在不影响从结点1出发到所有结点的最短路的前提下,最多可以删除k条边的多少条 跑最短路的时候维护或者统计就好了 一开始用spfa.然后TLE 45...好久没写  Dij+堆优化   ... p.s.优先队列默认大顶堆 Dij+堆优化   264ms #include <cstdio> #include <cstring> #include…
#include<bits/stdc++.h> #define MAXN 100050 #define MAXM 900000 using namespace std; struct st { int id; long long dis; st(int a,long long b) { id=a; dis=b; } st(){}; }; struct edge{ bool im; int id; long long w; edge *next; }; edge *adj[MAXN]; edge…
题目:Click here 题意:给定数列满足求f(n)mod(1e9+7). 分析:规律题,找规律,特别注意负数取mod. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; ; ; int x, y, n; ]; int main() { while( ~scanf…
矩阵快速幂. 首先得到公式 然后构造矩阵,用矩阵加速 取模函数需要自己写一下,是数论中的取模. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<algorithm> using namespace std; ; long long x, y; int n; long long mod(long long a, long long b) { )…
题意简述 给出正整数n,你要把1-n之间的正整数分成尽可能多组,使得每一组两个数的最大公约数大于1;输出能分成最多组的个数,并按任意顺序输出每组的两个数. 很妙的一道题. 首先我们考虑去处理每个质数的倍数,那么这个质数一定是小于等于 n/2 的,不然它在 n 的范围内是不会有倍数的. 那么我们先把 $1~n/2$ 范围内的所有质数筛出来. 枚举质数 然后我们要怎么用质数去处理答案呢? 首先我们从大到小枚举这些质数,然后去枚举它的倍数. 然鹅这样复杂度不会炸么?不会. $O(\sigma_{i=2…
题目链接 \(Description\) 给定\(n\)个正整数\(a_i\).求有多少个子序列\(a_{i_1},a_{i_2},...,a_{i_k}\),满足\(a_{i_1},a_{i_2},...,a_{i_k}\) \(and\)起来为\(0\). \(n\leq10^6,\quad 0\leq a_i\leq10^6\). \(Solution\) 这个数据范围..考虑按位容斥: 令\(g_x\)表示\(x\)的二进制表示中\(1\)的个数,\(f_x\)表示有多少个\(a_i\)…
思路: 之前那篇完全没想清楚,给删了,下午一上班突然想明白了. 讲一下这道题的大概思路,应该就明白矩阵快速幂是怎么回事了. 我们首先可以推导出 学过矩阵的都应该看得懂,我们把它简写成T*A(n-1)=A(n),是不是有点像等比?然后我们得到T^(n-1)*A(1)=A(n),所以我们可以通过矩阵快速幂快速计算左边的T^n-1这个式子,最后再和A1相乘,那么第一个数字就是答案了. 代码: #include<set> #include<cstring> #include<cstd…
https://vjudge.net/problem/CodeForces-449C 题目大意:1-n编号的苹果两两一对,他们的最大公约数不为1,求这些对的最大匹配. ———————————————————————————————— 我们显然先把素数筛出来. 然后我们从后往前循环素数p,然后p,2p,3p(取过的自动不要)……这些数两两都可以成一对. 但是如果是奇数个,我们就抛掉2p,因为2p一定可以与其他2的倍数一对. 不知道怎么证明…… #include<cstdio> #include&…
嘟嘟嘟 这道题正解是怎么对的其实我也不清楚,总之靠感性理解吧. 首先当然要把1到n / 2的素数都筛出来,因为两两能配对的数一定都是这些素数的倍数.这也就说明对于(n / 2, n]的素数,他们一定不能配对,所以就不用筛他们了. 筛完后我们考虑怎么配对,对于一个素数的所有倍数xi,他们任意两个都可以配对,但是可能配对完后得到的总配对数会减少.因此我们从最大的素数开始两两配对,感性理解就是越大的素数的倍数就越少,因此先尽量满足配对方案少的素数,然后再处理配对方案多的素数. 还有一点,就是当xi的倍…
codeforces 627 D. Preorder Test 二分 + 树dp 做logn次树dp codeforces 578D.LCS Again 给出一个字符串str,长度n<=10^6,由m种字符组成,问有多少个长度为n,与str的LCS 为 n-1的字符串t 这道题可以用dp套dp,但是我不会阿 可以找规律统计,考虑: 1.取哪个位置 2.放在哪个位置 3.放什么字符 可以知道,如果str分成了block份,每一份的字符相同,则 ans = block * n * (m - 1) 但…