G. Fence Divercity 题目连接: http://www.codeforces.com/contest/659/problem/G Description Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of n consecutively fastened vertical boards of centimeter widt…
题意:给你一组数,问你最少删去多少数,使得剩下的数,每个数都能整除数组中其它某个数或被数组中其它某个数整除. 题解:我们直接枚举所有因子,\(dp[i]\)表示\(i\)在数组中所含的最大因子数(当我们枚举到\(i\)时),然后用\(dp[i]\)更新以\(i\)作为因子的更大的数,注意,更新的时候\(dp[j]=max(dp[i],dp[j])\),而不是\(dp[j]+=dp[i]\),因为这样会把之前的因子重复计算. 代码: #include <bits/stdc++.h> #defin…
Codeforces Round #346 (Div. 2)---E. New Reform E. New Reform time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Berland has n cities connected by m bidirectional roads. No road connects a city…
Codeforces Round #582 (Div. 3)-G. Path Queries-并查集 [Problem Description] 给你一棵树,求有多少条简单路径\((u,v)\),满足\(u\)到\(v\)这条路径上的最大值不超过\(k\).\(q\)次查询. [Solution] 并查集 将所有边按权值从小到大排序,查询值\(k_i\)也从小到大排序.对于每次查询的值\(k_i\),将边权小于等于\(k_i\)的边通过并查集合并在一起.对于合并后的联通块,每个联通块对答案的贡献…
题目链接: G. Fence Divercity time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of n consecu…
https://codeforces.com/contest/1141/problem/G 题意 在一棵有n个点的树上给边染色,连在同一个点上的边颜色不能相同,除非舍弃掉这个点,问最少需要多少种颜色来染一棵树 题解 选择弃掉度数最高的k个点,然后第k+1个点的度数就是答案 代码 #include<bits/stdc++.h> #define N 200005 #define pb push_back using namespace std; int n,k,u,v,in[N],c[N],m,i…
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(abs(i-j)<h[i]\),那么向j方向推倒i,j也会倒,问选择任意数量骨牌向任意方向推到,使得全部骨牌都倒下的代价最小 题解 连锁反应可以用单调栈或者链表模拟 定义dp[i]为推倒a[i,m]的最小代价 对于每个i,有两种选择: 向左推:\(dp[l[i]+1]=min(dp[l[i]+1],dp[…
http://codeforces.com/contest/978/problem/G 感冒是真的受不了...敲代码都没力气... 题目大意: 期末复习周,一共持续n天,有m场考试 每场考试有如下信息: ①si表示知道第i门课的考试时间是在第si天的时候 ②di表示第i门课的考试时间 ③ci表示准备第i门课需要ci天的复习 在考试的那一天不能复习. 问n天中每一天都需要干啥? 三种情况,休息(输出0),复习(输出复习那一门科目的id),考试(输出m+1) 思路:按照di排序(即按照截止时间),然…
题目链接:https://codeforces.com/contest/1433/problem/G 题解 跑 \(n\) 遍 \(dijkstra\) 得到任意两点间的距离,然后枚举哪一条边权为 \(0\) 即可. 代码 #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, k; cin >> n >…
题目链接: http://codeforces.com/problemset/problem/650/C C. Table Compression time limit per test4 secondsmemory limit per test256 megabytes 问题描述 Little Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorithms and m…
E https://codeforces.com/contest/1154/problem/E 题意 一个大小为n(1e6)的数组\(a[i]\)(n),两个人轮流选数,先找到当前数组中最大的数然后选择以这个数为半径k的所有数,问两个人的选数情况 题解 set维护剩下数的最大 链表维护左右第一个存在的数的位置 代码 #include<bits/stdc++.h> #define MAXN 200005 using namespace std; int n,k,a[MAXN],p[MAXN],L…
题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记忆化搜索记忆,vis数组标记那些已经访问过的状态. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define REP(i, a, b) for (i…
D. Valid Sets   As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it. We call a set S of tree nodes valid …
A. Round House 题目链接http://codeforces.com/contest/659/problem/A Description Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent. Today Vasya got bored and decided t…
A. Round House 题目连接: http://www.codeforces.com/contest/659/problem/A Description Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent. Today Vasya got bored and dec…
前三题水 A #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 + 5; int main() { int n, a, b; std::cin >> n >> a >> b; int bb = b; if (b < 0) bb = -b; while (bb--) { if (b < 0) { a--; } else { a++; } if (a == 0) { a…
题目链接: 题目 E. New Reform time limit per test 1 second memory limit per test 256 megabytes inputstandard input outputstandard output 问题描述 Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities…
D. Bicycle Race 题目链接http://codeforces.com/contest/659/problem/D Description Maria participates in a bicycle race. The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straigh…
C. Tanya and Toys 题目链接http://codeforces.com/contest/659/problem/C Description In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collectio…
B. Qualifying Contest 题目链接http://codeforces.com/contest/659/problem/B Description Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The q…
F. Polycarp and Hay 题目连接: http://www.codeforces.com/contest/659/problem/F Description The farmer Polycarp has a warehouse with hay, which can be represented as an n × m rectangular table, where n is the number of rows, and m is the number of columns…
E. New Reform 题目连接: http://www.codeforces.com/contest/659/problem/E Description Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guara…
D. Bicycle Race 题目连接: http://www.codeforces.com/contest/659/problem/D Description Maria participates in a bicycle race. The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of s…
C. Tanya and Toys 题目连接: http://www.codeforces.com/contest/659/problem/C Description In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new col…
B. Qualifying Contest 题目连接: http://www.codeforces.com/contest/659/problem/B Description Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad.…
这次的题目相对容易 但是智商依旧不够用 原因有三点 1.英文水平堪忧 2 逻辑不严密 3 细节掌握不够好 传送门 http://codeforces.com/contest/659 A 题目大意 圆环上有n个点 人从a位置出发 走b步 正负代表方向 (a+b%n+n)%n 需要特判 避免走到 0位置 观察数据范围 只需要(100*n+a+b-1)%n+1 还省去了特判 B 题目大意 有n个人的数据  m个地区 每个地区最少参赛2人 晋级2人 出线则输出 需要加赛 如第二个人和第三个人成绩一样 …
题目链接:G. New Roads 题意:给出n个结点,t层深度,每层有a[i]个结点,总共有k个叶子结点,构造一棵树. 分析: 考虑一颗树,如果满足每层深度上有a[i]结点,最多能有多少叶子结点 那么答案很简单,就是对(a[i]-1)求和再加1(每一层的结点都集中在上一层的一个结点上)   同理,我们考虑最少能有多少叶子结点,就是把上一个的答案再减去min(a[i]-1, a[i-1]-1)的求和,就是每一层的结点都尽可能的分散在上一层的结点 根据这个,那么如果要求有k个叶子节点,k在最大值与…
B. Fence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from lef…
A. Round House Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance a and he…
淦,最后一道题没写出来,...还是我太菜了,不过这个题确实比较有趣. G. Minimal Coverage 简化题意:就是你处在坐标轴的0点上,给你一个序列\(a_i\),每次你可以选择向左走\(a_i\),也可以选择向右走\(a_i\),求你走过的范围的最小值?(第一步必须向右走). 其实这个题想起来也没那么复杂,显然每一步在选择时,我们需要一下的信息:当前所处的位置,当前走到哪一步了,当前所走过的范围的左右边界.信息蛮多的,如果用DP的话,当前走到哪一步了,这个很好解决,剩下的三个信息:当…