D. Maximum Diameter Graph 题目链接:https://codeforces.com/contest/1082/problem/D 题意: 给出n个点的最大入度数,要求添加边构成一个无环无向无重边的图,并且最大化图中的最短路径. 题解: 要求最短路径最大,我们会想到把每一个允许入度可以大于1的点先连起来,形成一个”链“,当前肯定满足条件,并且两端点的最短路径长度是所有情况中最大的. 然后对于入度为1的点,先尽量考虑放在链的两端,然后再在中间随便插入. 代码如下: 先附上自己…
E. Increasing Frequency 题目链接:https://codeforces.com/contest/1082/problem/E 题意: 给出n个数以及一个c,现在可以对一个区间上的数同时加上或减去一个值,问最后c的最多数量为多少. 题解: 这题挺有意思的,我们通过分析题目可以发现,对于每一个d,如果把[l,r]里面的d都变为c,则最后c的数量为cnt(c,1,l-1)+cnt(c,r+1,n)+cnt(d,l,r). 这个式子变化一下,有:cnt(c,1,n)+cnt(d,…
C. Multi-Subject Competition 题目链接:https://codeforces.com/contest/1082/problem/C 题意: 给出n个信息,每个信息包含专业编号以及对应权值,先要求选出一些数量相等的专业(每种专业选的个数相等,不要求每种专业都要选),使对应权值最大. 题解: 一开始想的是枚举选的数量,然后再枚举每种专业从大到小贪心地选,但是时间超了... 其实还有更巧妙地方法,直接考虑每种专业选的个数从1到x对答案的贡献,用一个数组保存这一个贡献就好了.…
题目链接:http://codeforces.com/contest/1009/problem/D 解题心得: 题意就是给你n个点编号1-n,要你建立m条无向边在两个互质的点之间,最后所有点形成一个连通图. 首先要明白n个点要形成连通图至少需要n-1条边,然后就是找边了,看了一下n和m的范围都是1e5,总感觉自己暴力能过,写了暴力过了,迷茫..... #include <bits/stdc++.h> using namespace std; ; vector <pair<int,i…
题:https://codeforces.com/contest/1082/problem/E 题意:给出n个数和一个数c,只能操作一次将[L,R]之间的数+任意数,问最后该序列中能存在最多多少个c 分析:考虑dp,dp[i]表示将该位置染成c的答案,那么将该颜色染成c肯定要和其他和这个位置值相同的位置尝试染一染,这个尝试就是dp的取max值,这里采用的是遍历到某一个值就查询之前出现的最近的位置,然后尝试,因为往后递推这样的关系就会被连起来,接着就是预处理一下前后缀c的个数. #include<…
传送门:http://codeforces.com/contest/1082/problem/C C. Multi-Subject Competition time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A multi-subject competition is coming! The competition has mm …
http://codeforces.com/contest/1082/problem/A WA数发,因为默认为x<y = = 分情况讨论,直达 or x->1->y  or  x->n->y  取最小值. #include<bits/stdc++.h> using namespace std; #define LL long long #define inf 0x3f3f3f3f #define mp make_pair #define pb push_back…
传送门:http://codeforces.com/contest/1082/problem/B B. Vova and Trophies time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vova has won nn trophies in different competitions. Each trophy is eit…
C. Multi-Subject Competition time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A multi-subject competition is coming! The competition has mm different subjects participants can choose from.…
A. Vasya and Book time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya is reading a e-book. The file of the book consists of nn pages, numbered from 11 to nn. The screen is currently disp…
D. Maximum Diameter Graph 题意 给出每个点的最大度,构造直径尽可能长的树 思路 让度数大于$1$的点构成链,考虑是否能在链的两端加度为$1$的点 代码 #include <bits/stdc++.h> #define DBG(x) cerr << #x << " = " << x << endl; const int maxn = 1e3+5; using namespace std; typedef…
传送门 https://www.cnblogs.com/violet-acmer/p/10035971.html 题意: Vova有n个奖杯,这n个奖杯全部是金奖或银奖,Vova将所有奖杯排成一排,你最多可以交换其中两个奖杯,求最大的连续的金奖杯个数. 题解: 思路: 求出连续的金奖杯位置,找出每两个相邻的连续的金奖杯所能够形成的最大的连续的金奖杯的个数,输出最大值. 相关变量解释: int n; char trophy[maxn]; struct Node { int l,r;//连续金奖杯包…
传送门 https://www.cnblogs.com/violet-acmer/p/10035971.html 题意: 一本书有n页,每次只能翻 d 页,问从x页到y页需要翻动几次? 注意:往前翻最少翻到第1页,往后翻最多翻到n页. 题解: 一开始想找规律来着,emmmm,直接用广搜,当时竟然过了,第二天,加数据了,直接就TLE了. 然后,今天下午,mxl给我和lk讲了一下ta的做法,找的规律,啊啊啊,我竟然没想到. 规律: (1):如果abs(x-y)%d == 0,那么,那么直接输出abs…
https://codeforc.es/contest/1082/problem/C 题目大意:有m个类型,n个人,每个人有一个所属类型k和一个能力v,要求所选的类型的人个数相等并且使v总和最大(n,m<=1e5) 题解:用vector存下每种类型的各个v并且每种类型根据v按从大到小排序,然后处理出每种类型的前缀和,然后扫每种类型的所有前缀和,如果该类型在i处的前缀和大于0,则相应的ans[i]加上这个类型在i处的前缀和,最后求出max(ans[i])(1<=i<=n)即可. 注意:这题…
A. Vasya and Book Solved. 三种方式取$Min$ #include <bits/stdc++.h> using namespace std; #define ll long long #define INF 0x3f3f3f3f3f3f3f3f int t; ll n, x, y, d; ll calc(ll x) { ? x / d : x / d + ; } int main() { scanf("%d", &t); while (t--…
D. Maximum Diameter Graph time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Graph constructive problems are back! This time the graph you are asked to build should match the following proper…
B. Vova and Trophies time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vova has won nn trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged i…
D. Maximum Diameter Graph time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Graph constructive problems are back! This time the graph you are asked to build should match the following properties…
C. Multi-Subject Competition time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output A multi-subject competition is coming! The competition has m different subjects participants can choose from. That'…
B. Vova and Trophies time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Vova has won n trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a r…
题目链接:http://codeforces.com/contest/1009/problem/E 解题心得: 一个比较简单的组合数学,还需要找一些规律,自己把方向想得差不多了但是硬是找不到规律,还是看了大佬博客才知道的规律.这个题要预先处理2的n次方,不然快速幂也会TLE. 推荐两个大佬的博客: https://blog.csdn.net/u010746456/article/details/81057082 https://blog.csdn.net/hyp1231/article/deta…
题目链接:http://codeforces.com/contest/1009/problem/C 解题心得: 题意就是一个初始全为0长度为n的数列,m此操作,每次给你两个数x.d,你需要在数列中选一个位置pos,然后对于每一个位置i的数num[i]-x+d*dis(i,pos).最后要求这个数列平均值最大. 其实不需要记录这个数列中的每个数是多少,只需要记录总和就行了.如果d为正数pos选在数列越中间的位置最后的总和越大.所以需要分类讨论d的正负和数列长度的奇偶,然后用等差通项求和公式就行了.…
题目链接:http://codeforces.com/contest/1009/problem/B 解题心得: 题意就是给你一个只包含012三个字符的字符串,位置并且逻辑相邻的字符可以相互交换位置,就是相邻的01交换,12交换,不可以02交换.最后需要输出字典序最小的字符串. 其实想想就很容易明白在字符串中1是可以随便移动的,所以可以把字符串中的1全删除,就只剩下02两种字符,这两种字符的相对位置不可以改变.然后把所有的1插在第一个02之间. #include <bits/stdc++.h>…
题目链接:http://codeforces.com/contest/1009/problem/A 解题心得: 题意就是给你两个数列c,a,你需要从c中选择一个子串从a头开始匹配,要求子串中的连续的前k个数都要比对应的a中数小,问k最大是多少. 大比赛的时候自己在枚举题意,搞了好久心态差点崩了. #include <bits/stdc++.h> using namespace std; ; int n,m; int a[maxn],c[maxn]; void init() { scanf(&q…
Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec Problem Description Input Output The only line should contain the minimal number of days required for the ship to reach the point (x2,y2)(x2,y2). If it…
Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec Problem Description Input The input contains a single line consisting of 2 integers N and M (1≤N≤10^18, 2≤M≤100). Output Print one integer, the total n…
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include<bits/stdc++.h> using namespace std; #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 #define IT set<ll>::iterator #define sqr(x)…
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include<bits/stdc++.h> using namespace std; #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 #define IT set<ll>::iterator #define sqr(…
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://codeforces.com/contest/985/problem/F Description You are given a string s of length n consisting of lowercase English letters. For two given strings s an…
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w…