VK news recommendation system daily selects interesting publications of one of n disjoint categories for each user. Each publication belongs to exactly one category. For each category i batch algorithm selects ai publications. The latest A/B test sug…
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; pair<]; bool cmp(pair<int,int>a,pair<int,int>b){ if(a.second!=b.second) return a.second>b.second;//按照时间从大到小排序 return a.first<b.first; } map<int,int>…
A. Dead Pixel(思路) 思路 题意:给我们一个m*n的表格,又给了我们表格中的一个点a,其坐标为(x, y),问在这个表格中选择一个不包括改点a的最大面积的矩形,输出这个最大面积 分析:很明显这个点 可以将 m*n的表格分成四份,而每一份又可以分成 举行的长或宽不被点a影响的两小份,接下来就是比较讨论了 代码 #include<iostream> #include<cstdio> #include<cstring> #include<cmath>…
C. Restoring Permutation time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output You are given a sequence b1,b2,-,bn. Find the lexicographically minimal permutation a1,a2,-,a2n such that bi=min(a2i−1,a…
After a long party Petya decided to return home, but he turned out to be at the opposite end of the town from his home. There are n crossroads in the line in the town, and there is either the bus or the tram station at each crossroad. The crossroads…
讨论坏点的左右上下的矩形大小. #include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long a, b, x, y; cin >> a >> b >> x >> y; // cout<<a<<" "<<b<<" "…
比赛链接:https://codeforces.com/contest/1443 A. Kids Seating 题意 构造一个大小为 \(n\) 的数组使得任意两个数既不互质也不相互整除,要求所有数小于 \(4n\) . 题解 因为不互质所以 \(gcd\) 至少为 \(2\),又为了避免相互整除,可以从倒着较大的 \(4n\) 开始构造. 代码 #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with…
题意:给你一组不重复的序列\(a\),每次可以选择一个数删除它左边或右边的一个数,并将选择的数append到数组\(b\)中,现在给你数组\(b\),问有多少种方案数得到\(b\). 题解:我们可以记录\(b_i\)在\(a_i\)中的位置,然后枚举\(b_i\),取它在\(a_i\)的位置,然后看\(a_{i-1}\)和\(a_{i+1}\)的情况,因为我们append之后必须要删除\(a_{i-1}\)和\(a_{i+1}\)中的一个,并且所有元素都是不重复的,所以\(a_{i-1}\)和\…
题意:有一个长度为\(n\)的序列,可以任意取\(k(1\le k\le n)\),对序列前\(k\)项或者后\(k\)减\(1\),可以进行任意次操作,问是否可以使所有元素都变成\(0\). 题解:贪心,我们优先考虑从左边减,如果当前项比后一项大\(a_i>a_{i+1}\),那么我们一定可以从左边减,使得这个区间变为\(0\),否则,光从左边减是不能使后一项元素变为\(0\)的,此时我们就要从右边减,即某尾到这项这段区间减去差值\(a_{i+1}-a_i\),我们可以直接累加这些差值,如果遍…
题意:你要买\(n\)份午饭,你可以选择自己去买,或者叫外卖,每份午饭\(i\)自己去买需要消耗时间\(b_i\),叫外卖需要\(a_i\),外卖可以同时送,自己只能买完一份后回家再去买下一份,问最少花多少时间能使午餐到家. 题解:我们可以用结构体记录每份午餐的外卖所需时间和自己拿的时间,然后贪心,对于某一份午餐,如果我们选择用外卖送,那么所有\(a_i\)比这个外卖时间小的在这个外卖送到时必然都能送到,所以我们可以对外卖时间进行排序,然后枚举每份午餐,每次让枚举位置和之前的位置用外卖送,枚举位…