Codeforces Round #504 E. Down or Right 题目描述:交互题. 有一个\(n \times n\)的方阵,有一些格子是障碍,从\((1, 1)\)出发,只能向右向下走,能走到\((n, n)\),你有\(4n\)次询问,每次询问\((r_1, c_1)\)能否走到\((r_2, c_2)\),但这两个点的曼哈顿距离要大于\(n-1\),最后输出一条从\((1, 1)\)到\((n, n)\)的路径. solution 从\((1, 1)\)出发,优先向下走,向下…
Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array aa consisting of nn integers. Beauty of array i…
我们知道不满足的肯定是两边大中间小的,这样就用RMQ查询两个相同等值的区间内部最小值即可,注意边界条件 #include<bits/stdc++.h> #define x first #define y second #define ok cout << "ok" << endl; using namespace std; typedef long long ll; typedef unsigned long long ull; typedef ve…
A. Co-prime Array 题目连接: http://www.codeforces.com/contest/660/problem/A Description You are given an array of n elements, you must make it a co-prime array in as few moves as possible. In each move you can insert any positive integral number you want…
D. Imbalanced Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the differenc…
A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array of n elements, you must make it a co-prime array in as few moves as possible. In each move you can i…
[题目] B. Lost Array [描述] Bajtek有一个数组x[0],x[1],...,x[k-1]但被搞丢了,但他知道另一个n+1长的数组a,有a[0]=0,对i=1,2,...,n.由此可以找到数组x[0],x[1],...,x[k-1]的一些可能情况,即满足这个关系的数组x[0],x[1],...,x[k-1].问一共有多少种可能的数组x[0],x[1],...,x[k-1]的长度k,输出可能的数量以及所有可能的长度k. 数据范围:1<=n<=1000,1<=a[i]&l…
D. Beautiful Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array aa consisting of nn integers. Beauty of array is the maximum sum of some consecutive subarray of t…
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…
题目链接:E. Maximum Subsequence 用了一个Meet-in-the-middle的技巧,还是第一次用到这个技巧,其实这个技巧和二分很像,主要是在dfs中,如果数量减小一半可以节约很多的时间. Meet in the middle(有时候也叫作split and merge)是一种用以获取足够高效解决方案的灵巧的思想.和分治思想非常类似,它将问题分割成两个部分,然后试着合并这两个子问题的结果.好处在于通过使用一点额外的空间,你可以解决两倍规模的原来可以解决的问题. #in…
#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; ]; int main(){ int k,n; int zk; int yk; while(~scanf("%d%d",&n,&k)){ zk=; yk=; scanf("%s",s); int lens=str…
#include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> using namespace std; ]; ]; int main() { int n,m; int lena; int lenb; while(~scanf("%d%d",&n,&m)) { scanf("%s",a); scanf("%…
D. Array Restoration time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Initially there was an array $$$a$$$ consisting of $$$n$$$ integers. Positions in it are numbered from $$$1$$$ to $$$n$$…