Codeforces 803C. Maximal GCD 二分】的更多相关文章

C. Maximal GCD time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: standard output You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2,…
Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个数,满足一下条件: ①这k个数之和等于n ②每个满足①条件的数列有最大公约数q,输出q最大的数列. 思路: 我们只需要找出这个最大的q是什么.q满足: ①q是n的 公约数 ②n/q>=(1+2+3+···+k) ③q是满足①②中的最大的 只需要通过for(long long i=1;i<sqrt(…
You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2, ..., ak, that their sum is equal to n and greatest common divisor is maximal. Greatest common divisor of sequence is maximum of…
题目链接:http://codeforces.com/contest/803/problem/C 中了若干trick之后才过... k个数的严格递增序列最小权值和就是${n*(n+1)/2}$,枚举这些数字增加的倍数x,使得序列变成${x,2x,3x...kx}$,然后再使最后一个数字变大满足要求就可以了,枚举的复杂度是根号$n$的. 要注意枚举倍数$x$的时候还要顺便枚举了$n/x$,然后${n*(n+1)/2}$这个东西是会爆long long的. #include<iostream> #…
题目描述: H. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a…
枚举. 枚举$gcd$,然后计算剩下的那个数能不能分成$k$个递增的数. #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <queue> #include <stack> #include <vector> #include <map> #incl…
http://codeforces.com/contest/803/problem/C [题意] 给定两个数n,k(1 ≤ n, k ≤ 10^10) 要你输出k个数,满足以下条件: ①这k个数之和等于n ②严格递增 ②输出的这k个数的最大公约数q尽可能大. [思路] 因为是严格递增,所以sum[k]>=k(k+1)/2,而n<=1e10,所以k应该在1e5多一点. 可以找出最大的满足n<=1e10的k,给定的k超出这个直接输出-1. 然后接下来考虑怎么使最大公约数最大: 因为q肯定也是…
803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于10^5时直接-1就好: 我们可以构造出gcd为1的序列为 1,2,3,4……n-k+1: 然后一个个枚举n的因子p: 1*p,2*p,3*p……(n-k+1)*p: 当枚举的p使得序列不满足于严格递增时,结束,输出合法答案: 来,上代码: #include <cmath> #include &l…
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2, ...…
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2, ...…
Maximal GCD CodeForces - 803C 现在给定一个正整数 n.你需要找到 k 个严格递增的正整数 a1, a2, ..., ak,满足他们的和等于 n 并且他们的最大公因数尽量大. 如果不可能请输出 -1. 这k个数的gcd的必定是n的因数,于是变成枚举n的因数,可以知道只需要枚举 1~sqrt(n) 范围内满足 n%i==0 的因数就行,复杂度就变成10的5次方了.然后贪心,要使得递增序列的公因子最大,先从大到小枚举因数 n/i ,没找到满足的因数再从小到大枚举因数 i.…
[Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r.每次操作的代价为改变数的个数.问:要让操作后序列里不同数的个数\(k\)满足$n \lceil \log _2 k\rceil \leq 8I $,操作的最小代价 分析 首先把a离散化,这样[l,r]都在\(10^5\)的级别.枚举l,发现r显然有单调性.操作后不同数的个数随r的增大而减小(考虑极端情况l=…
[题目链接]:http://codeforces.com/contest/803/problem/C [题意] 给你一个数字n;一个数字k; 让你找一个长度为k的序列; 要求这个长度为k的序列的所有数字的和为n; 且这k个数字的最大公因数最大; [题解] key:这个最大公因数一定是n的因子! /* 设最后选出来的k个数字为 a[1],a[2]...a[k]; 这些数字的最大公因数为g g*b[1],g*b[2],...g*b[k] n=g*b[1]+g*b[2]+...+g*b[k]; 这里g…
You are given positive integer number n. You should create such strictly increasingsequence of k positive numbers a1, a2, ..., ak, that their sum is equal to n and greatest common divisor is maximal. Greatest common divisor of sequence is maximum of…
今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1   This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you fin…
codeforces 895B XK Segments 题目大意: 寻找符合要求的\((i,j)\)对,有:\[a_i \le a_j \] 同时存在\(k\),且\(k\)能够被\(x\)整除,\(k\)满足:\[a_i \le k \le a_j\] 思路: 整体数组排序,对于当前\(a_i\)寻找符合条件的\(a_j\)的最大值和最小值 有:\[(a_i-1)/x+k=a_j/x\] 所以可以通过二分查找获得,这里我寻找\(((a_i-1)/x+k)*x\)为下界,\(((a_i-1)/x…
C. Block Towers time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top…
Magazine Ad 题目链接:http://codeforces.com/contest/803/problem/D ——每天在线,欢迎留言谈论. 题目大意: 给你一个数字k,和一行字符 例: garage for sa-le 其中这行字符串能够在 ' '与'-'的后面分割.例如分割为:(点代表空格) garage. for. sa- le 求:分割成不超过k行的情况下的最小宽度.(宽度:最大行的字符个数) 思路: 答案一定在 到 所给字符串长度 之间. ①通过二分宽度 来逼近最小宽度. 判…
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite ratio…
题目链接:https://codeforces.com/contest/1132/problem/D 题意: 有 $n$ 个学生,他们的电脑有初始电量 $a[1 \sim n]$,他们的电脑每分钟会耗电 $b[1 \sim n]$,现在有一场比赛持续 $k$ 分钟. 要你买一个充电器,使得每个学生的电脑在比赛期间的任何时候的电量都不会低于 $0$(可以等于 $0$),你要求出这个充电器每分钟充电量最少是多少. 题解: 看到这种题目,应当条件反射想到二分. 假设我们现在知道充电器每分钟的充电量是…
题目链接:http://codeforces.com/problemset/problem/1114/E 题意: 交互题,有一个 $n$ 个整数的打乱顺序后的等差数列 $a[1 \sim n]$,保证公差为正整数,你可以询问不超过 $60$ 次来找到该等差数列的首项和公差. 你可以做的询问有两种: 1.询问是否存在某个数字大于 $x$. 2.询问序列中第 $i$ 个数是多少. 题解: 首先可以用二分的方式找到这个等差数列的最大值,由于 $a[i] \in [0,1e9]$,所以最多 $30$ 次…
题目链接:http://codeforces.com/problemset/problem/660/C 题意: 给你一个长度为 $n$ 的 $01$ 串 $a$,记 $f(a)$ 表示其中最长的一段连续 $1$ 的长度. 现在你最多可以将串中的 $k$ 个 $0$ 变成 $1$,求操作后的 $f(a)$. 题解: (说实话这道题不看tag我不一定能想得出来……) 首先考虑二分枚举答案,对于一个假定的 $f(a)=x$,我们需要判断能不能满足: 用 $dp[i]$ 表示 $a[i-x+1], \c…
You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power store…
D. String Game time limit per test:2 seconds memory limit per test:512 megabytes input:standard input output:standard output Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty…
https://codeforces.com/contest/1132/problem/D 二分 + 线段树(弃用结构体型线段树) 题意 有n台电脑,只有一个充电器,每台电脑一开始有a[i]电量,每秒消耗b[i]电量,充电器每秒可以给一台电脑充x电,假如有一台电脑在某一秒末电量<0,则会关机,问最小的x使得在k秒内没有任何电脑关机 题解 二分答案x,线段树维护区间[1,n]最小天数,枚举k天每天单点修改天数最小的点 代码 #include<bits/stdc++.h> #define M…
http://codeforces.com/problemset/problem/338/D 题意: 有一张n*m的表格,其中第i行第j列的数为gcd(i,j) 给出k个数 问在这张表格中是否 有某一行中连续的某一部分 就是 这k个数 题意转化: 是否存在 一对i,j 满足gcd(i,j)=a1,gcd(i,j+1)=a2,…… gcd(i,j+k-1)=ak 直观上感觉: i要满足的必要条件是 i |  lcm(a1,a2……ak) j要满足的必要条件是 j= a1*k1,j+1=a2*k2……
大意:给定序列, 单点修改, 区间询问$[l,r]$内修改至多一个数后$gcd$能否为$x$ 这题比较有意思了, 要注意到询问等价于$[l,r]$内最多有1个数不为$x$的倍数 可以用线段树维护gcd, 询问操作每次二分找第一个不为$x$的倍数的数, 若找到两个直接返回, 是$O(logn)$的 单点更新要大量计算gcd, 是$O(log^2n)$的 #include <iostream> #include <algorithm> #include <cstdio> #…
题目链接:http://codeforces.com/problemset/problem/807/C 题目大意:给你T组数据,每组有x,y,p,q四个数,x/y是你当前提交正确率,让你求出最少需要再提交几次可以达到目标正确率p/q; 解题思路:假设提交B次,正确A次,那么可以得到(x+A)/(y+B)=p/q,可以推出x+A=k*p,y+B=k*q.那么A=k*p-x,B=K*q-y; 这样我们只需要二分枚举k,判断A,B是否满足(0<=A<=B)即可. #include<iostre…
题目链接:http://codeforces.com/contest/801/problem/C 题目大意:给你一些电器以及他们的功率,还有一个功率一定的充电器可以给这些电器中的任意一个充电,并且不计切换充电器的时间,问你最多能够同时使用这些充电器多久,如果可以一直用下去就返回-1.要求时间误差不能超过10^-4. 思路:开始没就见过这种类型的题目傻傻地一点一点把时间加上去....后来知道这是用了二分枚举,首先定义一个右边界(r=1e11根据提目应该大于1e10多一点)和左边界(l=0),然后不…
传送门: http://codeforces.com/problemset/problem/348/A A. Mafia time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day n friends gathered together to play "Mafia". During each round of…