CF1082A Vasya and Book 题解】的更多相关文章

Content 给定 \(T\) 组数据,每组数据给出四个整数 \(n,x,y,d\).小 V 有一本 \(n\) 页的书,每次可以恰好翻 \(d\) 页,求从第 \(x\) 页恰好翻到第 \(y\) 页的最少次数,或者报告不存在这样的方案. 数据范围:\(1\leqslant n,d\leqslant 10^9\),\(1\leqslant x,y\leqslant n\),\(1\leqslant t\leqslant 10^3\). Solution 分类讨论题. 如果 \(|x-y|\b…
Content 有两个球队在踢足球,现在给出一些足球运动员被黄牌或红牌警告的时间,求每个队员第一次被红牌警告的时间. 注意:根据足球比赛规则,两张黄牌自动换成一张红牌. 数据范围:比赛时间 \(90\) 分钟,足球员号码 \(\leqslant 99\). Solution 这道题目就是一个很纯粹的模拟.主要注意以下几点: 两个球队当中也许有相同号码的球员.比如说近现代的 \(10\) 号球员有很多,比如说齐达内和梅西等. 球员被红牌下场了,但后面还有可能会录入关于该球员的警告信息,此时应该忽略…
Content 给定两个长度分别为 \(n\) 和 \(m\) 的数列 \(A,B\).你需要将两个数列都恰好分成 \(k\) 份,使得两个数列中第 \(i(i\in[1,k])\) 份的元素和对应相等.问是否可行,并在可行的情况下求出最大的 \(k\). 数据范围:\(1\leqslant n,m\leqslant 3\times 10^5\),\(1\leqslant A_i,B_i\leqslant 10^9\). Solution 我们先将两个数列中的所有数的和加起来,记为 \(S_A,…
Content 小 V 有 \(s\) 块钱,商店里有巧克力卖,每块巧克力 \(c\) 块钱,现在商店给出优惠:购买 \(a\) 块巧克力可以免费获得 \(b\) 块巧克力,求小 V 最多能够买到的巧克力的块数. 你需要处理 \(t\) 组询问. 数据范围:\(1\leqslant t\leqslant 100,1\leqslant s,a,b,c\leqslant 10^9\). Solution 我们可以明显的发现,尽量把钱花完能够获得最多的巧克力.所以我们先买 \(\left\lfloor…
CF1082A Vasya and Book 模拟一下即可 \(Code\ Below:\) #include <bits/stdc++.h> using namespace std; const int inf=0x3f3f3f3f; int n,x,y,d,ans; int main() { int T; scanf("%d",&T); while(T--){ scanf("%d%d%d%d",&n,&x,&y,&am…
之所以在codeforces上找这100道水题的原因是为了巩固我对最近学的编程语言的掌握程度. 找的方式在codeforces上的PROBLEMSET中过的题最多的那些题里面出现的最前面的10个题型,它们是: math(数学) brute force(暴力) strings(字符串) implementation(模拟) greedy(贪心) sortings(排序) number theory(数论) constructive algorithm dp(动态规划) shortest path(…
Content 小 \(A\) 要乘坐交通工具,其中公交车的辆数是 \(n\),第 \(i\) 辆公交车的编号为 \(i\),乘坐次数为 \(a_i\):手推车的辆数是 \(m\),每辆手推车的编号为 \(i\),乘坐次数为 \(b_i\).当地的公交公司给出了 \(4\) 种门票类型: 花费 \(c_1\) 元乘坐一次公交车或者一次手推车. 花费 \(c_2\) 元乘坐同一个编号的公交车或者同一编号的手推车无限次. 花费 \(c_3\) 元乘坐所有公交车或者所有手推车无限次. 花费 \(c_4…
题目链接 思路分析 看到题目中 \(n,m \leq 1000\) ,故直接考虑 \(O(n^2)\) 级别做法. 我们先把所有的点按照 \(val\) 值从小到大排序,这样的话二维问题变成序列问题. 设 \(f_i\) 表示走到第 \(i\) 个点的价值的期望. 先列出裸的 \(dp\) 方程:(\(Num\) 表示符合条件的点的个数) \[f_i =\frac{1}{Num} \sum_{a_i > a_j}(x_i-x_j)^2+(y_i-y_j)^2+f_j \] 但是这个好像是 \(O…
题解 CF1082A [Vasya and Book] 史上最难A题,没有之一 从题意可以看出,翻到目标页只有三种办法 先从\(x\)到\(1\),再从\(1\)到\(y\) 先从\(x\)到\(n\),再从\(n\)到\(y\) 直接从\(x\)到\(y\) 三种的必要条件分别是 \((y-1)\mod d \equiv 0\) \((n-y)\mod d \equiv 0\) \(|x-y|\mod d \equiv 0\) 所以如果上面三种都不满足的话就输出\(-1\) 不然就取最小的输出…
C. Marina and Vasya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/problem/C Description Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters.…
A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/problem/A Description One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks. Accordi…
C. Vasya and Petya's Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/C Description Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number. P…
Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only.…
咸鱼了好久...出来冒个泡_(:з」∠)_ 题目连接:1107G - Vasya and Maximum Profit 题目大意:给出\(n,a\)以及长度为\(n\)的数组\(c_i\)和长度为\(n\)的严格单调上升数组\(d_i\),求\(\max\limits_{1 \le l \le r \le n} (a\cdot(r-l+1)-\sum_{i=l}^{r}c_i-gap(l,r))\),其中\(gap(l, r) = \max\limits_{l \le i < r} (d_{i…
Vasya came up with a password to register for EatForces — a string ss. The password in EatForces should be a string, consisting of lowercase and uppercase Latin letters and digits. But since EatForces takes care of the security of its users, user pas…
题目描述 Vasya has a string s of length n consisting only of digits 0 and 1. Also he has an array a of length n. Vasya performs the following operation until the string becomes empty: choose some consecutive substring of equal characters, erase it from t…
写之前,先发表下感慨:好久没写题解了,也许是因为自己越来越急利了,也可以说是因为越来越懒了. A. Diverse Substring 直接找一找有没有相邻的两个不同的字符即可. B. Vasya and Books 分别记录书本摆放顺序$a[]$,取书顺序$b[]$,每本书的位置$pos[]$,每本书在不在书堆上$in[]$,书堆最顶端的书的位置$top$(因为用的是数组,元素位置是固定的). 然后,按照题意枚举输入的取书顺序$b[]$,同时记录答案$ans$,更新$top$即可. C. Va…
B. Vasya and Wrestling 题目连接: http://codeforces.com/contest/493/problem/B Description Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wi…
A. Vasya and Football 题目连接: http://codeforces.com/contest/493/problem/A Description Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player wh…
E. Vasya and Good Sequences time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya has a sequence $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. Vasya may pefrom the fol…
做出了4题,还不错,可惜还是掉rating……能保持在蓝名已经不错了. 题目跳转链接. [A]公平的游戏 题意: Petya和Vasya在玩游戏.他们有n张卡片(n是偶数).每张卡片上有一个整数. 游戏开始前,Petya会选出一个数,然后Vasya会选出另一个数(不同于Petya选的数),然后每人从卡片中抽出所有写着他选中的数的卡片. 举个例子,Petya选了5,而Vasya选了10,那么Petya抽出所有写着5的卡片,而Vasya抽出所有写了10的卡片. 如果Petya和Vasya能抽走所有卡…
C. Vasya and String 题目连接: http://www.codeforces.com/contest/676/problem/C Description High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as th…
1051E. Vasya and Big Integers 题意 给出三个大整数\(a,l,r\),定义\(a\)的一种合法的拆分为把\(a\)表示成若干个字符串首位相连,且每个字符串的大小在\(l,r\)之间,求每个字符串不能有前导零,求\(a\)有多少种合法的拆分方案. 题解 不难想到\(dp\),设\(dp_i\)表示前\(i\)个数有多少种合法的拆分方案. \(dp_i=\sum_{j=1}^i dp_{j-1}\)(从\(j+1~i\)拆分的数在\(l,r\)之间) 直接转移是\(O(…
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforces.com/contest/1016/problem/C 题意: emmm,说不清楚,还是直接看题目吧. 题解: 这个题人行走的方式是有一定的规律的,最后都是直接走到底,然后从另外一行走回来.并且通过画图观察,会发现他走到格子的时间会有一定的规律. 所以就维护几个前缀和就行了,从1到n枚举一下,还要…
Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contest/1107/problem/D 题意: 给出一个n*(n/4)的矩阵,这个矩阵原本是一些01矩阵,但是现在四个四个储存进二进制里面,现在给出的矩阵为0~9以及A~F,表示0~15. 然后问这个矩阵能否压缩为一个(n/x)*(n/x)的矩阵,满足原矩阵中大小为x*x的子矩阵所有数都相等(所有子矩阵构…
A. Vasya and Book 题目链接:https://codeforc.es/contest/1082/problem/A 题意: 给出n,x,y,d,x是起点,y是终点,d是可以跳的格数,注意是不能跳出边界,最少跳到1,最多跳到n.问最少跳到y的步数是多少. 题解: 从x到y,有三种途径,一是从x直接跳 |y-x|/d 步到y:二是先从x跳到1,然后再跳到y:三是先从x跳到n,然后再跳到y. 注意一下从x跳到边界的步数就好了. 代码如下: #include <bits/stdc++.h…
Codeforces 1107G 线段树最大子段和 + 单调栈 G. Vasya and Maximum Profit Description: Vasya got really tired of these credits (from problem F) and now wants to earn the money himself! He decided to make a contest to gain a profit. Vasya has \(n\) problems to choo…
D. Vasya And The Matrix time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the te…
Codeforces1107E 记忆化dp E. Vasya and Binary String Description: Vasya has a string \(s\) of length \(n\) consisting only of digits 0 and 1. Also he has an array \(a\) of length \(n\). Vasya performs the following operation until the string becomes empt…
                                                      C. Marina and Vasya   Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. M…