题意:给你一组数\(a\)和一个数\(T\),将这组数分为两组\(c\)和\(d\),定义\(f(x)\)为数组\(x\)中任意两个不同元素的和为\(T\)的个数,问为了使\(min(f(c)+f(d))\),应该怎样对\(a\)分组. 题解:我们可以分成三种情况,假如一组数中所有元素都\(< \frac{T}{2}\),或者\(>\frac{T}{2}\),那么它们的\(f(x)\)都为\(0\),然而对于\(a[i]=\frac {T}{2}\)的情况,我们将其交叉放在两组即可. 代码:…
题目链接:https://codeforces.com/contest/1417/problem/B 题意 定义 $f(a)$ 为数组 $a$ 中满足: $i < j$ $a_i + a_j = T$ 的二元组 $(i,j)$ 的个数. 试将一个大小为 $n$ 的数组 $a$ 划分为 $b,c$ 两组,使得 $f(b) + f(c)$ 最小. 题解 两数之和为 $T$ 有两种情况: 一个数小于 $T$,一个数大于 $T$,此时以 $\frac{T}{2}$ 为分界线分到两组即可 两个数都等于 $…
题目链接:https://codeforces.com/contest/1417/problem/A 题意 给出一个大小为 $n$ 的数组 $a$,每次操作可以选择两个数,然后将一个数加到另一个数上,要求操作后的数不能大于 $k$,问最多可以操作多少次. 题解 除一个最小值外,给每个数一直加最小值. 证明 操作的本质是留下哪一个数,明显留下较小的数更优. 代码 #include <bits/stdc++.h> using namespace std; int main() { ios::syn…
[Codeforces Round #673 (Div. 2) ] 题目链接# A. Copy-paste 思路: 贪心的策略.每次只加上最小的就可以了 #include<bits/stdc++.h> using namespace std; const int INF=0x3f3f3f3f; typedef long long ll; ll a[1010]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);…
B. GCD Arrays 题源:https://codeforces.com/contest/1629/problem/B 题目大意 给出一段区间[l, r],可以进行操作(把任意两个数拿出来,把他俩乘积放回去),如果经过 k 次该操作后,能找到两个数a, b, 使得 gcd(a, b) > 1,就输出"YES",否则输出"NO" 思路 如果要使得整个数组的GCD大于 1,每个元素都必须具有一个共同的质因数,因而很容易得出 2 是最常见的质因数. 又因为偶数…
题目链接:https://codeforces.com/contest/1417/problem/C 题意 给出一个大小为 $n$ 的数组 $a$,计算当 $k$ 从 $1$ 到 $n$ 取值时在所有 $k$ 长区间中出现的数的最小值. 题解 记录一个值两两间的最大距离,该距离的 $k$ 长区间及之后更长的区间都可能以该值为最小值. Tips 注意两端的处理. 代码一 #include <bits/stdc++.h> using namespace std; int main() { ios:…
题目链接: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$ 变为 $…
题意:有一组数,分别用长度从\([1,n]\)的区间去取子数组,要求取到的所有子数组中必须有共同的数,如果满足条件数组共同的数中最小的数,否则输出\(-1\). 题解:我们先从后面确定每两个相同数之间的距离,然后维护每个\(i\)位置上的数到后面所有相同数的最大距离,然后我们就可以dp来搞了,我从\(1\)开始遍历,如果\(a[i]\)后面的所有相同数间隔的最大距离不大于\(k\),那么说明这个数是满足长度为\(i\)的区间的,我们更新状态\(dp[i]=min(a[i],dp[i])\),否则…
B. Sort the Array 题目连接: http://codeforces.com/contest/451/problem/B Description Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers. Unfortunately, the size of a is to…
D. Fish Weight 题目连接: http://www.codeforces.com/contest/298/problem/D Description It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number.…
A. Snow Footprints 题目连接: http://www.codeforces.com/contest/298/problem/A Description There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th blo…
C. Alternative Thinking Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/problem/C Description Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary…
A. Bits Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/problem/A Description Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer x. You are given multiple queries…
题目链接: http://codeforces.com/contest/606/problem/D D. Lazy Student time limit per test2 secondsmemory limit per test256 megabytes 问题描述 Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange…
任意门:http://codeforces.com/contest/1066/problem/B B. Heaters time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vova's house is an array consisting of nn elements (yeah, this is the first probl…
题目链接:http://codeforces.com/contest/719/problem/B B. Anatoly and Cockroaches time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Anatoly lives in the university dorm as many other students do. A…
链接: https://codeforces.com/contest/1272/problem/A 题意: outputstandard output Three friends are going to meet each other. Initially, the first friend stays at the position x=a, the second friend stays at the position x=b and the third friend stays at t…
题目链接:https://codeforces.com/contest/1369/problem/E 题意 Lee 有 $n$ 种不同种类的食物和 $m$ 个朋友,每种食物有 $w_i$ 个,每个朋友喜欢吃两种食物 $x_i, y_i$,如果一个朋友被叫去厨房时一个喜欢吃的食物也没有,他就会吃掉 Lee,否则对还有的他喜欢吃的食物一种吃掉一个,问是否存在一个叫朋友去厨房的顺序保证 Lee 不会被吃掉. 题解 设 $s_i$ 为第 $i$ 种食物共需要多少个,若 $w_i \ge s_i$,则喜欢…
题目链接:https://codeforces.com/contest/1369/problem/C 题意 将 $n$ 个数分给 $k$ 个人,每个人分 $w_i$ 个数($\sum_{i = 1}^{k}w_i = n$),每个人的快乐值为分到数的最小值和最大值之和,计算所有人快乐值之和的最大值. 题解 将 $n$ 个数从小到大排序后从两边加起,利用较大的 $w_i$ 跳过尽可能多的较小值. 代码 #include <bits/stdc++.h> using ll = long long;…
C. Recycling Bottles   It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bott…
D. Lazy Student   Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to…
题目:Click here #include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; +; int n, m; int main() { while( ~scanf("%d %d", &n, &m ) ) { ) { printf("1\n"); continue; } ) printf( ); else…
题目链接 给你一个n∗m的矩阵res,让你输出一个n∗m的矩阵a,这个矩阵满足:给你一个n*m的矩阵res,让你输出一个n*m的矩阵a,这个矩阵满足:给你一个n∗m的矩阵res,让你输出一个n∗m的矩阵a,这个矩阵满足: ai,j代表第i行第j列的元素,通过减小res之后,使得第i行,第j列的所有元素的最大值a_{i,j}代表第i行第j列的元素,通过减小res之后,使得第i行,第j列的所有元素的最大值ai,j​代表第i行第j列的元素,通过减小res之后,使得第i行,第j列的所有元素的最大值 最小…
B. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as f…
E. Distributing Parts time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are an assistant director in a new musical play. The play consists of n musical parts, each part must be performed…
#include<bits/stdc++.h>using namespace std;int order[300007];long long t[300007],ans[300007];int main(){    int n;    long long m; scanf("%d%lld",&n,&m); for(int i=1;i<=n;i++)  scanf("%lld",&t[i]); t[n+1]=2e18; for…
Description Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day…
D. Minimization time limit per test  2 seconds memory limit per test  256 megabytes input  standard input  output  standard output You've got array A, consisting of n integers and a positive integer k. Array A is indexed by integers from 1 to n. You…
贪心,如果m分成的两个区间长度不相等,那么选长的那个区间最接近m的位置,否则选m-1位置,特判一下n等于1的情况 #include<bits/stdc++.h> using namespace std; int main() { int n,m; scanf("%d%d",&n,&m); ){ printf(; } , d2 = n-m; if(d1<d2){ printf(); }else { printf(); } ; }…
传送门 D. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated…