Codeforces 1154B Make Them Equal】的更多相关文章

题目链接:http://codeforces.com/problemset/problem/1154/B 题意:给定数组,可以给任意的的元素加上D 或者 减去D,如果能 使数组元素都相等,输出最小的D,不能输出-1. 思路:若要相等,唯有种类数小于3的才可以. AC代码: #include<bits/stdc++.h> using namespace std; int main() { int n; ]; int x,y,z; set<int> st; cin >> n…
C. Not Equal on a Segment time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi. For th…
题意:n个塔,第i个塔由$h_i$个cube组成,每次可以切去某高度h以上的最多k个cube,问你最少切多少次,可以让所有塔高度相等 k>=n, n<=2e5 思路:差分统计每个高度i有的方块数nh[i],然后从高到低贪心的切就行了 代码: #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include…
A - Restoring Three Numbers CodeForces - 1154A Polycarp has guessed three positive integers aa, bb and cc. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum o…
C. Not Equal on a Segment 题目连接: http://www.codeforces.com/contest/622/problem/C Description You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi. For the i-th query find any position pi (li ≤ pi …
B. Queries about less or equal elements Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/problem/B Description You are given two arrays of integers a and b. For each element of the second array bj you should find the num…
传送:http://codeforces.com/gym/101612 题意:给出一个大小为n的序列a[i],每次选其中一个数乘以一个正整数,问进行k步操作后最少剩下多少种数字,输出0≤k≤n,所有的k的答案. 注意这k步不一定是连续的. 分析: 对于每个数,可以有两种操作: 1. 先将有倍数的数变成它们的最大倍数,而且按照出现次数比较少的先变. 2. 将所有数都变成lcm,而且按照出现次数比较少的先变. 数组f[i]代表,操作i次的最小种类数.对于每一次操作,取min. #include<bi…
传送门: http://codeforces.com/problemset/problem/600/B Queries about less or equal elements time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given two arrays of integers a and b. For e…
http://codeforces.com/contest/1029/problem/A You are given a string tt consisting of nn lowercase Latin letters and an integer number kk. Let's define a substring of some string ss with indices from ll to rr as s[l…r]s[l…r]. Your task is to construct…
Description You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array athat are less than or equal to the value bj. Input The first line contains two integers n, m (1 ≤ n, m …
B. Queries about less or equal elements time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given two arrays of integers a and b. For each element of the second array bj you should fin…
题目地址:http://codeforces.com/contest/977/problem/C 题解:给一串数组,是否找到一个数x,找到k个数字<=x,找到输出x,不能输出-1.例如第二组,要找到两个数字,排序后出现1,3,3,会出现三个数字小于等于3,所以不能找到. 一个坑点,k=0的时候需要分类讨论,如果发现最小的数字是1的话,不能输出0,因为要求输出1~1e9之间的数,否则输出a[0]-1就可以啦~ 方法:排序以后分类判断即可. #include<cstdio> #include…
C. Equal Sums time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given kk sequences of integers. The length of the ii-th sequence equals to nini. You have to choose exactly two sequen…
You are given a sequence of integers of length nn and integer number kk. You should print any integer number xx in the range of [1;109][1;109] (i.e. 1≤x≤1091≤x≤109) such that exactly kk elements of given sequence are less than or equal to xx. Note th…
题目链接 \(Description\) 给定\(n\)个数,每次可以将任意一个数乘上任意一个正整数. 求\(k\)次操作后,数列中数的种类最少可以是多少.对每个\(0\leq k\leq n\)输出答案. \(n\leq 3\times10^5,a_i\leq10^6\). \(Solution\) 有两种贪心策略,一是每次找一个出现次数最少的数,把它变成所有数的LCM:二是找一个出现次数最少,且它的某个倍数存在于原数列里的数,将它变成它的这个倍数. 对两种情况取\(\min\)即可. //9…
You are given two arrays of integers a and b. For each element of the second arraybj you should find the number of elements in array a that are less than or equal to the value bj. Input The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — t…
题目链接: http://codeforces.com/problemset/problem/622/C 题意: 给定序列,若干查询,每个查询给定区间和t,输出区间内任意一个不等于t的元素的位置. 分析: 最初没看样例直接钦定输出每个不等于t的元素位置,结果怎么想都是n2复杂度的,后来看了样例才发现是输出任意一个.. 对于一个区间,如果区间最大值和最小值相等,那么该区间元素值全部相同,那么我们维护区间的最大最小值,然后判断是否均等于t,若不等,输出最大值或最小值的位置即可,若相等, 则该区间所有…
题意:给你个序列,你可以给某个数加上2的幂次,问最少多少次可以让所有的数相等. 思路(官方题解):我们先给序列排序,假设bit(c)为c的二进制数中1的个数,假设所有的数最后都成为了x, 显然x >= a[n],那么最后的总花费为Σbit(x - a[i]).不妨假设x = t + a[n], b[i] = a[n] - a[i], 那么问题转化为了求Σbit(t + b[i])的最小值.我们假设最后取得最小值的数是x.我们假设已经知道了填充x的低k - 1位的最小花费,我们来考虑填充第k位.我…
题目链接:http://codeforces.com/contest/1206/problem/C 题解 : 观察可以发现当n为偶数时,1 - 2n是不满足题意的,可以举例n = 2,n = 4试一试.那么当n为奇数时,则满足题意,通过n = 3和n = 5的情况可以发现一个规律,当a[ 1 ] = 1时候,a[ n + 1] = 2 ,a[ 2 ] =  4,此时 a[ n + 1]  = 3,a[ 3 ] = 5,则a[ n+ 3] = 6,发现a[ i ] 和a[ i + n] 是连续的两…
Equal Rectangles time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given 4n4n sticks, the length of the ii-th stick is aiai. You have to create nn rectangles, each rectangle will con…
题目链接:https://codeforces.com/contest/1417/problem/D 题意 给出一个大小为 $n$ 的正整数数组 $a$ ,每次操作如下: 选择 $i,j$ 和 $x$,$(1 \le i, j \le n,\ 0 \le x \le 10^9)$ 令 $a_i - x \cdot i,\ a_j + x \cdot i$ 要求过程中不能有负数产生,问能否在 $3n$ 次操作内使数组中的每个元素相等,如果可以给出操作次数和过程. 题解 把每个 $a_i$ 变为 $…
B Equal Rectangles 题意: 给你4*n个数,让你判断能不能用这个4*n个数为边凑成n个矩形,使的每个矩形面积相等 题解: 原本是想着用二分来找出来那个最终的面积,但是仔细想一想,那个面积只能是给出的4*n个数中的最小值和最大值的乘积,如果这两个长度不凑成一个矩形,那么肯定全部矩形的面积会出现不一致的 代码: 1 //The idea was to use dichotomies to find that area, and then use that area to figur…
Codeforces 题目传送门 & 洛谷题目传送门 首先我们考虑枚举最后这 \(n\) 个数变成的值 \(v\),那么需要的操作次数即为 \(\sum\limits_{i=1}^n\text{bitcnt}(v-a_i)\),其中 \(\text{bitcnt}(x)\) 为 \(x\) 二进制中 \(1\) 的个数. 这样似乎不太好直接求,不过不难发现这个 \(v\) 一定是 \(\ge\max\{a_i\}\) 的,因此我们考虑转而枚举 \(x=v-\max\{a_i\}\),我们记 \(…
C. Not Equal on a Segment time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi. For th…
预处理p[i],p[i]表示:[p[i],i]这段闭区间上所有数字都是a[i] 询问的时候,如果xi==a[ri]并且p[ri]<=li,一定无解 剩下的情况都是有解的,如果xi!=a[ri],那么输出ri,否则输出p[ri]-1. 另外,看到有大牛博客说可以用线段树,大致是这样的: 线段树保存区间最大值与最小值, 如果询问的区间上最小值==最大值,那么无解: 剩下的情况都是有解:如果xi不等于最小值,那么输出最小值位置:如果xi不等于最大值,那么输出最大值位置. #include <stdi…
打开题目连接 题意:给2个数组(无序的)啊a,b,判断b数组中的每一个元素大于a数组中个数. ACcode: #include <iostream> #include <vector> #include <algorithm> #include <cstdio> using namespace std; vector<int> v; int main() { int x, n, m; scanf("%d%d",&n,&…
题目大意 题目看样例也能猜到就是输出最短的循环串. 吐槽 明明是div3第一题为啥子还会用到kmp的知识? 解法 这个题仔细看发现是求最长可去除的后缀,也就是说去除跟下一个相同的字符串还能连接起来.这个不就是next数组的功能吗?最长公共前后缀. 公式:len-next[len] 我们把前k-1个字符串只输出前面的部分最后加上一个完整的字符串即可 完整代码 #include <bits/stdc++.h> using namespace std; char a[500]; int nex[50…
传送门 •题意 给k个数列,从中k个数列中找出任意2个数列 i ,j 使得数列i删除第x个数,和数列j删除第y个数的和相等 若存在,输出 i ,x 和 j,y •思路 每个数列之间的联系为数列的和之间的差det 如果开二维数组记录每个数列之间的det的话,显然是不可行的_(:з」∠)_ 这里用map<x ,pair<i ,j > >mp表示序列 i 删除第 j 个数后的总和为 x: 如果某两个序列各删除一个数,得到的总和相等, 也就是后一个序列得到的总和已存在(被前一个所记录)的话…
题目大意:有n座塔,塔高h[i],每次给定高度H对他们进行削切,要求每次削掉的所有格子数不能超过k个,输出最少削几次才能使所有塔的高度相同. 思路一:差分+贪心 对于每一个高度h,用一个数组让1~h的数,每一个都加一.用差分求一下后缀和可以完成. AC code: #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ll arr[N]; int main() { ll n,k; cin>>n>…
题意:有一个长度为\(n\)的序列,要求在\([1,10^9]\)中找一个\(x\),使得序列中恰好\(k\)个数满足\(\le x\).如果找不到\(x\),输出\(-1\). 题解:先对这个序列排个序,然后首先要注意\(k=0\)的情况 如果\(k=0\)并且序列中含有\(1\),那么我们无论如何都找不到比\(1\)小的数,输出\(-1\),如果不含\(1\),那么只要输出\(a[1]-1\)即可. 如果\(k\ne 0\),那么我们要找前\(k\)个小的数(连续相等的数也算),所以我需要用…