E. Magic Stones time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Grigory has nn magic stones, conveniently numbered from 11 to nn. The charge of the ii-th stone is equal to cici. Sometimes G…
题面 传送门 分析 一开始考虑贪心和DP,发现不行 考虑差分: 设d[i]=c[i+1]-c[i] (i<n) 那么一次操作会如何影响差分数组呢? \(c[i]'=c[i+1]+c[i-1]-c[i]\) \(d'[i-1]=c[i]'-c[i-1]=c[i+1]-c[i]=d[i]\) \(d'[i]=c[i]-c[i-1]=d[i-1]\) 我们发现操作只是改变了差分数组中不同值的位置 因此,我们只要求出c,t对应的差分数组,并比较它们是否相同即可 注意由于c[1]和c[n]不能变,所以要判…
E. Magic Stones time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Grigory has nn magic stones, conveniently numbered from 11 to nn . The charge of the ii -th stone is equal to cici . Sometime…
题面 Grigory has n n magic stones, conveniently numbered from \(1\) to \(n\). The charge of the \(i\)-th stone is equal to \(c_i\). Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index \(i\), where \(2 \le i \le n-1…
E. Magic Stones 链接 题意: 给定两个数组,每次可以对一个数组选一个位置i($2 \leq i \leq n - 1$),让a[i]=a[i-1]+a[i+1]-a[i],或者b[i]=b[i-1]+b[i+1]-b[i].问进行一些操作后,a和b能否相同. 分析: 考虑一次操作会变成什么样子. a b c a a+c-b c 我们发现这些数字差分后是不变的.于是对两个数组差分后,排序,看是否一样即可.注意判一下1和n是否相等. 代码: #include<cstdio> #in…
Magic Numbers CodeForces - 628D dp函数中:pos表示当前处理到从前向后的第i位(从1开始编号),remain表示处理到当前位为止共产生了除以m的余数remain. 不一定要把a减一,也可以特判a自身,或者直接改记忆化搜索. #include<cstdio> #include<cstring> #define md 1000000007 typedef long long LL; LL m,d,ans1,ans2,len1; LL ans[][][]…
Dima and Magic Guitar CodeForces - 366E 题意: http://blog.csdn.net/u011026968/article/details/38716425http://vawait.com/2013/11/codeforces-366e/http://www.cnblogs.com/jianglangcaijin/archive/2013/11/25/3441319.html 对于s中任意相邻两个数x和y,都要求在矩形中找出任意两个分别等于x和y的点…
LZH的多重影分身 qduoj 思维 差分 原题链接:https://qduoj.com/problem/591 题意 在数轴上有\(n\)个点(可以重合)和\(m\)条线段(可以重叠),你可以同时平移这\(n\)个点,询问最多可以有多少个点在线段上,输出平移的距离\(d\),和最后的答案\(val\)(如果有多个\(d\)使得\(val\)最大,则输出最小的\(d\)). 解题思路 下面的题解是我们厉害的学长给的,真是太厉害了. 首先,我们用\(ans[i]\),来代表平移\(i - MAX\…
题目链接 听dalao说很nb,做做看(然而不小心知道题解了). \(Description\) 给定长为\(n\)的序列\(A_i\)和\(B_i\).你可以进行任意多次操作,每次操作任选一个\(i\in[2,n-1]\),把\(A_i\)变成\(A_{i-1}+A_{i+1}-A_i\). 求能否将序列\(A_i\)变成\(B_i\). \(n\leq10^5\). \(Solution\) \(A_i\to A_{i-1}+A_{i+1}-A_i\)这个形式很有趣,求出\(A_i\)的差分…
Codeforces 1110 E 题意:给定两个数组,从第一个数组开始,每次可以挑选一个数,把它变化成左右两数之和减去原来的数,问是否可以将第一个数组转化成第二个. 思路: 结论:两个数组可以互相转化的充要条件是它们差分后的数组排序后相同并且它们第一个数相同. 证明: 先证明一个引理. 引理:两个数组可以互相转化的必要条件是它们都能转化成同一个数组. 证明:假设A转化成B,C也转化成B,由于操作可逆,于是可以从A转化成B再转化成C.\(\square\) 证明原结论的充分性. 看某一次操作.…
传送门 将原数组差分一下,设\(d_i = c_{i+1} - c_i\) 考虑在\(i\)位置的一次操作会如何影响差分数组 \(d_{i+1}' = c_{i+1} - (c_{i+1} + c_{i-1} - c_i) = c_i - c_{i-1} = d_i\) \(d_i' = (c_{i+1} + c_{i-1} - c_i) - c_{i-1} = c_{i+1} - c_i = d_{i+1}\) 所以本质上一次操作交换了差分数组中的两个元素 所以只需要判断差分数组中的每一个元素…
[链接] 我是链接,点我呀:) [题意] 你可以把c[i]改成c[i+1]+c[i-1]-c[i] (2<=i<=n-1) 问你能不能把每一个c[i]都换成对应的t[i]; [题解] d[i] = c[i+1]-c[i]; (1<=i<=n-1) change c[i] c[i]' = c[i+1]+c[i-1]-c[i]; d[i-1] = c[i]'-c[i-1]; = c[i+1]+c[i-1]-c[i]-c[i-1] == c[i+1]-c[i] = d[i]; d[i]…
题意 给定两个数组c和t,可以对c数组中的任何元素变换\(c_i\)​成\(c_{i+1}+c_{i-1}-c_i\)​,问c数组在若干次变换后能否变换成t数组. 分析 这种魔法题目我是同样的没做过.Editorial里说用差分来能够看出思路.问题是,如何能够想到差分来做?因为它的变换就是相邻的数的加减法,那么想要找到思路的突破口必须也得从这里突破. 考虑变换前后的数组: 原来:\(a_{i-1}, a_i, a_{i+1}\) 之后:\(a_{i-1}, a_{i-1}+a_{i+1}-a_i…
Squats Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster e…
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the u…
https://codeforces.com/contest/1060/problem/E 题意 给一颗树,在原始的图中假如两个点连向同一个点,这两个点之间就可以连一条边,定义两点之间的长度为两点之间的最少边数,求加边之后任意两点长度之和 思路 一看到求任意两点,知道需要用每条边的贡献计算(每条边使用了多少次) 每条边的贡献等于边左边的点数*边右边的点数 然后就一直不知道怎么解决加边后的问题,不知道要标记哪些东西,怎么减去 单独看一条路径,加边之后, 假如边数是偶数的话,边数/2 假如边数是奇数…
这场CF怎么这么多构造题…… 题目链接:CF原网 洛谷 题目大意:给定两个长度为 $n$ 的序列 $c$ 和 $t$.每次我们可以对 $c_i(2\le i<n)$ 进行一次操作,也就是把 $c_i$ 变成 $c_i'=c_{i-1}+c_{i+1}-c_i$.问 $c$ 能否在若干次操作后变成 $t$. $1\le n\le 10^5,1\le c_i,t_i\le 2\times 10^9$. 很容易考虑差分.我们设 $d_i=c_i-c_{i-1},s_i=t_i-t_{i-1}(2\le…
https://codeforces.com/problemset/problem/353/D 大意:给定字符串, 每一秒, 若F在M的右侧, 则交换M与F, 求多少秒后F全在M左侧 $dp[i]$为位置$i$处的$F$复位所花费时间, 有 $dp[i] = max(dp[i-1]+1,cnt_i)$, $cnt_i$为前$i$位$M$的个数 $dp$最大值即为答案 #include <iostream> #include <algorithm> #include <cstd…
题目大意:有一个长度为$n(n\leqslant10^5)$的数列$c$,问是否可以经过若干次变换变成数列$t$,一次变换为$c'_i=c_{i+1}+c_{i-1}-c_i$ 题解:思考一次变换的本质,对$c$做差分,原差分为$c_i-c_{i-1},c_{i+1},c_i$:对$c_i$做一次变换后为:$c'_i-c_{i-1}=c_{i+1}+c_{i-1}-c_i-c_{i-1}=c_{i+1}-c_i,c_{i+1}-c'_i=c_{i+1}-(c_{i+1}+c_{i-1}-c_i)…
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fi…
https://codeforces.com/contest/965/problem/D 太神仙了...比E难啊.. 首先呢,根据题意,可以很容易的建出一个最大流模型 就是每个位置建一条边,容量限制为该位置石头数,向所有它能直接跳到的位置的边的起点连边(容量无限) (当然起点和对岸也要分别建一条边,容量无限,并按一样的规则与其他的地方间连边) 那么答案就是从起点到对岸的最大流 显然不能直接跑... 而最大流=最小割,显然如果是最小割,那么不能包括任何容量无限的边,那么只能选由位置产生的边 经过观…
(点击此处查看原题) 题意分析 已知 n , p , w, d ,求x , y, z的值 ,他们的关系为: x + y + z = n x * w + y * d = p 思维法 当 y < w 的时候,我们最多通过1e5次枚举确定答案 而当 y >= w 的时候,平局所得分为:y * d = (y-w)*d + w*d ,可以看作平局的局数为 y - w ,多出的w*d贡献给 (w*d)/w = d 局胜局,所以胜局为 x + d ,说明此时用x+y局胜局和平局得到的分数可以由 x + d…
C - Covered Points Count CodeForces - 1000C You are given nn segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each othe…
Description Archeologists have found a secret pass in the dungeon of one of the pyramids of Cycleland. To enter the treasury they have to open an unusual lock on the door. The lock consists of n words, each consisting of some hieroglyphs. The wall ne…
题意:你需要订阅一些服务,每个服务每天需要花费\(c_i\),要从第\(a_i\)用到第\(b_i\)天,你可以购买会员,会员每天需要花费\(C\),但是这天的服务不用再另花钱了,问你订阅这些服务的最小花费是多少. 题解:对于这种某一段区间的加加减减的问题,我们首先应该考虑的是用差分,我们可以用map来做差分数组,然后遍历map累加差分数组的前缀和,再和\(C\)比较,贡献给答案就可以了. 代码: #include <bits/stdc++.h> #define ll long long #d…
Crash Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know th…
Elimination Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds.…
题意是说一个人喝酒 有两种办法 买塑料瓶的 a块钱 喝了就没了 或者是买玻璃瓶的b块钱 喝完还能卖了瓶子c块钱 求最多能喝多少瓶 在开始判断一次 a与b-c的关系 即两种方式喝酒的成本 如果a<=b-c 那么直接全部买塑料瓶就行了 没必要买玻璃瓶 因为麻烦 而且会出现钱不够b却够b-c这种情况 很麻烦 如果a>b-c  也就是说买玻璃瓶更省一些 就应当先买玻璃瓶的 不行了再尝试塑料瓶 第一种情况只做一次除法就够了 第二种情况 如果用while循环(n>b)来做 会超时在test48...…
Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the numbe…
Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place! This contest consists of n problems, and Pasha solves ith problem in ai time units (his solutions are…