思路:枚举换的位置i,j 然后我们要先判断改序列能否完全匹配 如果可以 那我们就需要把差值最大的位置换过来 然后直接判断就行…
思路:枚举换的位置i,j 然后我们要先判断改序列能否完全匹配 如果可以 那我们就需要把差值最大的位置换过来 然后直接判断就行…
D2. The World Is Just a Programming Task (Hard Version) This is a harder version of the problem. In this version,…
D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single soluti…
任意门:http://codeforces.com/contest/1118/problem/D1 D1. Coffee and Coursework (Easy version) time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The only difference between easy and hard versions…
传送门:http://codeforces.com/contest/1092/problem/D1 D1. Great Vova Wall (Version 1) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vova's family is building the Great Vova Wall (named by Vo…
链接:https://codeforces.com/contest/1130/problem/D1 题意: 给n个车站练成圈,给m个糖果,在车站上,要被运往某个位置,每到一个车站只能装一个糖果. 求从每个位置开车的最小的时间. 思路: vector记录每个位置运送完拥有糖果的时间消耗,为糖果数-1 * n 加上消耗最少时间的糖果. 对每个起点进行运算,取所有点中的最大值. 代码: #include <bits/stdc++.h> using namespace std; typedef lon…
D1. Magic Powder - 1 time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraint…
D1. RGB Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output The only difference between easy and hard versions is the size of the input. You are given a string s consistin…
一.题目 D1. Submarine in the Rybinsk Sea (easy edition) 二.分析 简单版本的话,因为给定的a的长度都是定的,那么我们就无需去考虑其他的,只用计算ai的值在每个位置的贡献即可. 因为长度是定的,如果ai在前,那么对所有的a的贡献就是在偶数位的贡献值然后乘以n即可. 如果ai在后,那么对所有ai的贡献就是在奇数位的贡献值然后乘以n. 将两种情况合并,其实就是求ai在每个位置下的贡献,然后乘以n. 时间复杂度是$O(n)$ 三.AC代码 1 #incl…
传送门 C. Ivan the Fool and the Probability Theory 题意: 给出一个\(n*m\)的方格,现在要给方格中的元素黑白染色,要求任一颜色最多有一个颜色相同的格子和它相邻.问多少种方案. 思路: 观察到若第一行含有两个相同的颜色相邻,那么之后所有格子的状态都可以确定: 若第一行不含有两个相同的颜色相邻,那么下一行至多有两种状态. 根据这两个观察,可以发现状态数其实不多,我们再推导一下: 对于第一种情况,假设第一个格子为白色,第二个格子有黑白两种选择:若选择白…
D. Catowice City In the Catowice city next weekend the cat contest will be held. However, the jury members and the contestants haven't been selected yet. There are…
B. Grow The Tree Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wan…
A. Integer Points DLS and JLS are bored with a Math lesson. In order to entertain themselves, DLS took a sheet of paper and drew…
A. Ivan the Fool and the Probability Theory Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area. To p…
Preface 这场CF真是细节多的爆炸,B,C,F都是大细节题,每道题都写了好久的说 CSP前的打的最后一场比赛了吧,瞬间凉意满满 希望CSP可以狗住冬令营啊(再狗不住真没了) A. Ivan the Fool and the Probability Theory 原谅我脑子不如陈指导好想不出来正解,然后打了个暴力3min找到规律做掉了... 然后讲一下正确的做法(陈指导教我的): 考虑我们用DP做出\(1\times m\)的矩阵的答案记为\(f_m\),考虑用它填了第一行 然后我们考虑第一…
Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher’s Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree…
A. Integer PointsDescription DLS and JLS are bored with a Math lesson. In order to entertain themselves, DLS took a sheet of paper and drew n distinct lines, given by equations y=x+pi for some distinct p1,p2,…,pn. Then JLS drew on the same paper shee…
题意:给n*m的网格涂黑白两种颜色,保证每个格子上下左右的四个格子中最多只有一个格子与自己颜色相同,问有多少种涂法?结果$mod1000000007$ 思路:先只考虑一行有多少种涂法 $dp[i][0]$表示第$i$个格子与第$i-1$个格子颜色不一样,那么第$i-1$与第$i-2$个格子颜色可以不同也可以相同,所以$dp[i][0]=dp[i-1][1]+dp[i-1][0]$ $dp[i][1]$表示第$i$个格子与第$i-1$个格子颜色相同,那么第$i-1$与第$i-2$格子颜色只能不相同…
题意:给你一个NxM的图,让你求有多少符合 “一个格子最多只有一个同颜色邻居”的图? 题解:首先我们可以分析一维,很容易就可以知道这是一个斐波那契计数 因为dp[1][m]可以是dp[1][m-1]添加一个和结尾不同颜色的块,或者dp[1][m-2]加上两个和结尾不同颜色的块 为什么dp[1][m-1]不可以添加一个和结尾颜色相同的块呢?因为这样情况就和dp[1][m-2]重叠了. 接着我们再分析多维情况 假设我们有一个3x6的图 第一种情况: 第一行中有相邻同色块,例如 100101 那么很明…
题意:给你一个\(n\)x\(m\)的矩阵,需要在这些矩阵中涂色,每个格子可以涂成黑色或者白色,一个格子四周最多只能有\(2\)个和它颜色相同的,问最多有多少种涂色方案. 题解:首先我们考虑一维的情况,一个格子的方案数是\(2\),两个格子的方案数是\(4\),我们记\(f[1]=2\),\(f[2]=4\),然后我们考虑三个格子的情况,假如我们最后两个格子涂成一样的颜色,那么情况数就是\(f[1]\),若最后两个两个格子的颜色不一样,那么我们可以看成在\(f[2]\)的基础上涂第三个格子,这样…
D. Wizards and Roads 题目连接: http://www.codeforces.com/contest/167/problem/D Description In some country live wizards. They love to build cities and roads. The country used to have k cities, the j-th city (1 ≤ j ≤ k) was located at a point (xj, yj). It…
题意 求一个生成树,使得任意点到源点的最短路等于原图中的最短路.再让这个生成树边权和最小. http://codeforces.com/contest/545/problem/E 思路 先Dijkstra一下,再对每个点连的边判断是不是最短路上的边,如果是那再贪心取最小的边即可. 代码 #include<bits/stdc++.h> using namespace std; #define ll long long const ll inf=1e18; const int N=6e5+5; s…
题意 给出n个pair (a,b) 把它放在线性序列上 1--n 上 使得  sum(a*(j-1)+b*(n-j))  最小 思路 :对式子进行合并 同类项 有:    j*(a-b)+  (-a+b*n) 可以发现   只和第一项有关  所以把a-b小的和大的j 结合即可 比赛的时候被B搞得心态爆炸就开始乱搞了 实际上已经试过a-b 了但是不知道为啥没有过样例 也怪自己不冷静 冷静一推也就是半分钟的事情 #include<bits/stdc++.h> #define FOR(i,f_sta…
题意:你在一家公司工作\(t\)天,负责给饮水机灌水,饮水机最初有\(k\)升水,水的范围必须要在\([l,r]\)内,同事每天白天都会喝\(x\)升水,你在每天大清早可以给饮水机灌\(y\)升水,问你在公司工作的这几天内,饮水机会不会发生故障. 题解:假如\(x>=y\),那么,我们贪心的思路一定是每天让水减的尽可能少,所以每天都要加水,这里要注意第一天的情况,如果第一天加水后大于\(r\)话,那么第一天大清早是不能加水的,这里我们要特判一下,接下来用if判断就行了. 假如\(x < y\)…
Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意:  Akshat and Malvika两人玩一个游戏,横竖n,m根木棒排成#型,每次取走一个交点,交点相关的横竖两条木棒要去掉,Akshat先手,给出n,m问谁赢. 分析:  水题,非常明显无论拿掉哪个点剩下的都是(n-1,m-1),最后状态是(0,x)或(x,0),也就是拿了min(n,m)-…
Codeforces Round #552 (Div. 3) 题目链接 A. Restoring Three Numbers 给出 \(a+b\),\(b+c\),\(a+c\) 以及 \(a+b+c\) 这四个数,输出一种合法的 \(a,b,c\).   可以发现,前面的两个数加起来减去最后的 \(a+b+c\),答案就出来一个.最后这样求出\(a,b,c\)即可. 代码如下: Code #include <bits/stdc++.h> using namespace std; typede…
//在我对着D题发呆的时候,柴神秒掉了D题并说:这个D感觉比C题简单呀!,,我:[哭.jpg](逃 Codeforces Round #435 (Div. 2) codeforces 862 A. Mahmoud and Ehab and the MEX[水] 题意:定义一个集合的MEX为其中的最小的不在集合里的非负整数,现在给一个大小为N的集合和X,每次操作可以向其中加入一个非负整数或删除一个数,问最小的操作次数,使得这个集合的MEX为X. #include<cstdio> #include…
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入n,k,n表示字符串的长度,k表示从1-k的小写字符(1即是a),现在要求最大化最少字符的数量. 题解: 贪心搞一搞就行了. 代码如下: #include <bits/stdc++.h> using namespace std; int T; int n,k; int main(){ cin>…