CF992C Nastya and a Wardrobe】的更多相关文章

Nastya and a Wardrobe time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dress…
我是题面 题意很清晰,这种题,我们当然还是有两种方法来做啦 方法一:找规律 读完题我们来看样例,通过样例一已我们大概可以看出,答案或许是\(n*2^{k+1}\) 肯定不能这么简单对吧,那就来看样例二,难道答案是\(n*2^{k+1}-k\)或者是\(n*2^{k+1}-2^{k-1}\)也有可能是\(n*2^{k+1}-2^k+1\) 通过样例三可得,答案是\(n*2^{k+1}-2^k+1\) 方法二:数学证明 每个月都是乘2,所以第i个月取走一个对第j个月的影响就是\(2^{j-i}(i<…
Nastya received a gift on New Year - a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, right a…
<题目链接> 题目大意: 你开始有X个裙子 你有K+1次增长机会 前K次会100%的增长一倍 但是增长后有50%的机会会减少一个 给你X,K(0<=X,K<=1e18), 问你最后裙子数量的期望值是多少(答案 mod 1e9+7) 解题分析: 一看到X,K的范围这么大,就应该想到是要推公式,找规律的题.本题的公式很好推,直接按照题意模拟即可. #include <cstdio> #include <cstring> #include <algorith…
写一下二叉树  推一下公式就出来了, 注意取模时的输出形式 #include <bits/stdc++.h> #define mem(a, b) memset(a, b, sizeof(a)) using namespace std; typedef long long LL; , INF = ; LL n, k; LL qp(LL a, LL b) { LL res = ; while(b) { ) res = res * a % MOD; a = a * a % MOD; b >&g…
http://codeforces.com/problemset/problem/992/C 题意: 给你两个数x,k,k代表有k+1个月,x每个月可以增长一倍,增长后的下一个月开始时x有50%几率减1,增长k+1个月后结果是每种情况的总和除以种数. 题目要求的是增长k+1个月后的结果. 我们根据第三个样例可以推出他的增长过程 3 6 5 12 11 10 9 |     |     | | 24    22 20 18 从这个推导我们容易得出最后得到的每种情况构成一个等差数列,公差为2 结果是…
A. Nastya and an Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this…
B. Nastya Studies Informatics time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so s…
Nastya and an Array 输出有几种不同的数字 #pragma comment(linker, "/STACK:102400000,102400000") #ifndef ONLINE_JUDGE #include "stdafx.h" #else #include<bits/stdc++.h> #endif using namespace std; typedef long long lint; typedef vector<int…
题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeForces - 215C - Crosses(思维题) C:CF–思维练习–CodeForces - 216C - Hiring Staff (思维+模拟) D:CF思维联系–CodeForces-217C C. Formurosa(这题鸽了) E:CF思维联系–CodeForces - 218C E…
At the big break Nastya came to the school dining room. There are nn pupils in the school, numbered from 11 to nn. Unfortunately, Nastya came pretty late, so that all pupils had already stood in the queue, i.e. Nastya took the last place in the queue…
C. Nastya Is Transposing Matrices time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Nastya came to her informatics lesson, and her teacher who is, by the way, a little bit famous here gave he…
E - Nastya and King-Shamans 题目大意:有n个数,每一次操作更改一个数,每次操作之后问你是否有一个数等于其前面所有数的和. 思路:好题,想了很久没想出来,看了题解,主要思想就是满足条件的数会成倍增长,如我们知道了 1 - i 里面没有满足条件的数, 那么我们找一个最小的 j 满足 a[ j ] >= sum(1, i),j就可能成为一个答案, 我们check一下,如果可以就是这个点,如果不行那么 不可能前缀就从 1 - i 变成了 1 - j, 这个过程最多 执行log…
\(>Codeforces\space992 E. Nastya and King-Shamans<\) 题目大意 : 给你一个长度为 \(n\) 的序列,有 \(q\) 次操作,每一次操作将一个数 \(A_i\) 改为另外一个数.每一次操作结束时,你需要找出一个位置 \(x\) 满足 \(A_x = sum_{x-1}\) 其中 \(sum\) 表示前缀和 $n , q \leq 2 \times 10^5   0 \leq A_i \leq 10^9 $ 解题思路 : 博主亲测分块加均摊分…
CF992E Nastya and King-Shamans 题意翻译 给定一个序列 \(a_i\),记其前缀和序列为 \(s_i\),有 \(q\) 个询问,每次单点修改,询问是否存在一个 \(i\) 满足 \(a_i=s_{i-1}\),有多解输出任意一个,无解输出 \(-1\). 输入输出格式 输入格式: The first line contains two integers \(n\) and \(q\) The second line contains n n integers \(…
思路: 1. 最终答案不超过能与Nastya“直接交换”的人数. 2. 对于排在j前面的i,如果i和i-j之间(包括j)的每个人都能“直接交换”,j才能前进一步. 实现: #include <bits/stdc++.h> using namespace std; ; int a[N], p[N], cnt[N]; vector<int> v[N]; int main() { int n, m; while (cin >> n >> m) { ; i <…
B. Nastya Studies Informatics time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so s…
Nastya Studies Informatics   time limit per test 1 second   memory limit per test 256 megabytes   input standard input output standard output   Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent,…
Nastya Studies Informatics time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she…
D. Nastya and Scoreboard 题意 一块电子屏幕上有n个数字. 每个数字是通过这样7个线段显示的,现在你不小心打坏了k个线段,给出打坏之后的n个数字的显示方式,问之前的屏幕表示的最大数字是多少? 思路 看数据范围感觉就是DP. 我们把n个数字先倒过来,要尽可能的让后面的数字大. dp[i][j][k]表示前i个数字打坏了j个线段最后一个数字为k是否可行. 对于第i个数字,枚举可以变成的数字. 回溯一下即可. 代码 #include<bits/stdc++.h> #defin…
C. Nastya and Strange Generator 题意 有一个随机全排列生成器,给出你一个全排列,让判断是否可以通过这个生成器产生. 生成器工作方式: 第i步为数字i寻找位置pos. 首先pos是一个空位置,定义每个空位置的价值为左边连续有数字的位置数,会为数字i在价值最大的一个或者多个位置中选择一个位置. 比如上图,第三个位置的值是2,第4个位置的值是0,这时4就选择了第3个位置. 思路 写一下就会发现,这个生成器生成的全排列是有规律的. n的全排列 x+y+1 x+y+2...…
题目链接: http://codeforces.com/contest/1136/problem/E 题意: 初始有a数组和k数组 有两种操作,一,求l到r的区间和,二,$a_i\pm x$ 并且会有一个连锁反应 $$while\left ( a_{i+1}<a_i+k_i \right )a_{i+1}=a_i+k_i,i++ $$ 数据范围: $2 \leq n \leq 10^{5}$$-10^{9} \leq a_i \leq 10^{9}$$-10^{6} \leq k_i \leq…
这道题,神仙贪心题... 题意就是我给出数的顺序,并给出多个交换,每个只能用于相邻交换,问最后一个元素,最多能往前交换多少步. 我们考虑这样一个问题,如果一个这数和a[n]发生交换,那么这个数作为后面的数能和前交换的数已经没有任何效果了. 但是这个数如果没有往后,他将在想要被交换那个数的前面,就算,前面的数找到满足了,也必须要把这个数往前放,并把这个数往后放,才行. 我们交换只能考虑这种情况. 4 3 2 1 我们有 4 3 4 2 4 1 那么整体往前移动,4移动到最后. 而且我们这样考虑,为…
题意:给出两个n*m的矩阵,每次操作可以让一个正方形矩阵行列交换.问,在无限次操作下,第一个矩阵能否变成第二个矩阵 分析:先把操作限定在2*2的矩阵中.这样对角线上的元素就可以随意交换.也就是说,如果给相邻的元素随意的交换次数,那么一个长度为n的数列可以得到任何顺序. 然后把操作放大,发现不在一个对角线上的元素无论如何也是无法交换位置的. ac代码: #include<bits/stdc++.h> using namespace std; const int maxn=505; int num…
题意 题目链接 Sol yy出了一个暴躁线段树的做法. 因为题目保证了 \(a_i + k_i <= a_{i+1}\) 那么我们每次修改时只需要考虑取max就行了. 显然从一个位置开始能影响到的位置是单调的,而且这些位置的每个改变量都是\((a_i + x) + \sum_{t=i}^{j-1} k_t\) 那么可以建两棵线段树分别维护这两部分的值 每次修改的时候二分出要修改的位置. 打cf一定要记得开数据结构题啊qwq #include<bits/stdc++.h> #define…
题意 题目链接 给出一个排列,以及\(m\)个形如\((x, y)\)的限制,表示若\(x\)在\(y\)之前则可以交换\(x, y\). 问\(n\)位置上的数最多能前进几步 \(n \leqslant 3* 10^5, m \leqslant 5 * 10^5\) Sol 每次遇到这种动来动去的题基本都做不出来qwq 我最开始想到的是图论模型,然后发现不管怎么建都有反例.结果标算是个神仙贪心?.. 考虑这样一种贪心:从前往后处理每一个数,记一个\(num\)数组表示该位置的数最多能往后移动几…
链接 [https://codeforces.com/contest/1136/problem/D] 题意 有N个人,a[i]表示第i个人的编号,m个二元组. 当前一个在后一个的前面一个位置时二者可以交换. 问最后一个人最多可以往前移多少? 分析 很好的一个贪心 必须明确一个东西 如果一个人目前的位置在pos处,那么如果后面有n-pos个人可以和他交换,那么他就肯定能和最后一个人交换. 当然这里的n-pos是除开某些已经和最后一个人交换了的人的. 如果可以交换,那就最后一个人往前移.否则就把该位…
链接 [https://codeforces.com/contest/1136/problem/C] 题意 给你两个规模一样的矩阵 问是否可以通过不断选取A矩阵的子"方正"转置得到B矩阵 分析 明确一点,那些i+j相等的位置一定是在某个子方正的斜对角上(右上往左下画线就知道), 而且这个斜对角的任意两个元素是一定可以通过一些转置互换,而且其他位置不变. 自己拿几个矩阵模拟就知道了 后面只需要对每个i+j相等的排序对比两个矩阵的就OK了 代码 #include<bits/stdc+…
题意 给出一个长度为 \(n\) 的序列 \(\{a_i\}\) , 现在会进行 \(m\) 次操作 , 每次操作会修改某个 \(a_i\) 的值 , 在每次操作完后你需要判断是否存在一个位置 \(i\), 满足 \(\displaystyle a_i = \sum_{j=1}^{i - 1}a_j\) 并求任意一个 \(i\) . \(n, m ≤ {10}^5 , 0 ≤ a_i ≤ {10}^9\) 题解 考虑一个暴力,不妨首先从 \(i = 1\) 开始判断是否合法,由于 \(a_i\)…
vp的时候没码出来.. 我们用set去维护, 每一块区域, 每块区域内的元素与下一个元素的差值刚好为ki,每次加值的时候我们暴力合并, 可以发现我们最多合并O(n)次. 然后写个线段树就没了. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<…