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\)比这个外卖时间小的在这个外卖送到时必然都能送到,所以我们可以对外卖时间进行排序,然后枚举每份午餐,每次让枚举位置和之前的位置用外卖送,枚举位…
题意:给你一个\(01\)串,需要将所有的\(1\)给炸掉,每次炸都可以将一整个\(1\)的联通块炸掉,每炸一次消耗\(a\),可以将\(0\)转化为\(1\),消耗\(b\),问将所有\(1\)都炸掉的最小花费. 题解:贪心,如果\(1\)存在,那么我们至少要炸一次,然后可以枚举统计两个连通块之间的\(0\)的个数,判断是将这些\(0\)变为\(1\)然后炸一次的花费小,还是炸掉\(2\)个连通块的花费小,思路就是这样,具体实现见代码. 代码: int t; int a,b; string s…
题意:给你一个正整数\(n\),在\([1,4n]\)中找出\(n\)个数,使得这\(n\)个数中的任意两个数不互质且不能两两整除. 题解:这题我是找的规律,从\(4n\)开始,往前取\(n\)个偶数就好了. 代码: int t; int n; int cnt; int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>t; while(t--){ cin>>n; cnt=0; for(int i=4…
Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A. Single Wildcard Pattern Matching 题意就是匹配字符的题目,打比赛的时候没有看到只有一个" * ",然后就写挫了,被hack了,被hack的点就是判一下只有一个" * ". 代码: //A #include<iostream> #include<cstdio>…
Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 全场题解 菜鸡只会A+B+C,呈上题解: A. Bear and Big Brother 题意:我也没看太清,就是给你两个10以内的数a,b.a每天乘以3,b每天乘以2,求多少天后a大于b. 思路:应该是有公式的,不过看到数据这么小直接暴力乘求解.官方题解貌似就是这样,数据小就是水题. const int N=1e3+10; int main() { int a…
A. Vicious Keyboard time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string s with only t…
A. Vicious Keyboard 题意:给你一个字符串,里面只会包含VK,这两种字符,然后你可以改变一个字符,你要求VK这个字串出现的次数最多. 题解:数据范围很小,暴力枚举改变哪个字符,然后check就好. #include<bits/stdc++.h> using namespace std; int main(){ string s; cin>>s; int ans = 0; for(int i=0;i<s.size();i++){ if(s[i]=='V'){…
C. Bear and Different Names 题目连接: http://codeforces.com/contest/791/problem/C Description In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should s…
B. Bear and Friendship Condition 题目连接: http://codeforces.com/contest/791/problem/B Description Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pic…
http://codeforces.com/contest/1025/problem/D 树 dp 优化 f[x][y][0]=f[x][z][1] & f[z+1][y][0] ( gcd(a[x-1],a[z])<>0 ) f[x][y][1]=f[x][z][1] & f[z+1][y][0] ( gcd(a[z],a[y+1])<>0 ) #include <cstdio> #include <cstdlib> #include &l…
http://codeforces.com/contest/967/problem/F 题目大意: 有n个点,n*(n-1)/2条边的无向图,其中有m条路目前开启(即能走),剩下的都是关闭状态 定义:从x走到y(即x->y)后,和x所连接的边的所有状态都反转(即开启->关闭,关闭->开启) 问,从起点1走到终点n,最少需要经过几步,并且输出这个路径(如果存在多挑最短路径,输出任意一条) 如果不存在,则输出-1 思路: 其实这道题第一眼看过去就是bfs,不过,由于每个状态都在改变,那要怎么…
http://codeforces.com/contest/967/problem/E 题目大意: 给你一个数组a,a的长度为n 定义:b(i) = a(1)^a(2)^......^a(i), 问,是否存在一种情况,使得a(i)重新排列以后以后,满足b(i)是严格单调递增的. 思路: 对于二进制位操作来说,如果异或后值增加,即 p^q > p,必然满足两种情况(假定一个为p,一个为q) ①q的最高位>p的最高位 ②q的最高位(假定第k为最高) < p的最高位,但是p的第k位为0 这样,…
http://codeforces.com/contest/1023/problem/E 交互题 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <time.h> #include <string> #include <set> #include <map> #include <list&g…
http://codeforces.com/contest/967/problem/D 题目大意: 有n个服务器,标号为1~n,每个服务器有C[i]个资源.现在,有两个任务需要同时进行,令他为x1,x2. 运行任务的条件: ①每个服务器只能同时运行一个任务 ②任务可以同时分配到多个服务器中执行.假设任务x1分配到a个服务器中,则每个服务器都需要使用x1/a的资源(该资源可以为小数) 问能否满足以上条件,使得x1,x2同时在服务器中运行? 思路: 将所有服务器按照资源增序排列,定义dp(i)表示从…
A. Vicious Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string s with only t…
地址:http://codeforces.com/contest/801/problem/D 题目: D. Volatile Kite time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a convex polygon P with n distinct vertices p1, p2, ..., p…
地址:http://codeforces.com/contest/801/problem/C 题目: C. Voltage Keepsake time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You have n devices that you want to use simultaneously. The i-th devi…
我们要统计的答案是sigma([L/K]),L为路径的长度,中括号表示上取整. [L/K]化简一下就是(L+f(L,K))/K,f(L,K)表示长度为L的路径要想达到K的整数倍,还要加上多少. 于是,我们现在只需要统计sigma((L+f(L,K))),最后除以K即可. 统计sigma(L)时,我们考虑计算每条边出现在了几条路径中,设u为edgei的子节点,那么这条边对答案的贡献就是siz(u)*(n-siz(u)),siz(u)为u的子树大小. 统计sigma(f(L,K))时,我们需要dp出…
B. Weakened Common Divisor time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output During the research on properties of the greatest common divisor (GCD) of a set of numbers, Ildar, a famous mat…
Description Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to re…
http://codeforces.com/contest/948/problem/A   A. Protect Sheep Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his she…