B. Minimize the Permutation You are given a permutation of length n. Recall that the permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation…
B. Minimize the Permutation You are given a permutation of length nn. Recall that the permutation is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2…
D. Make a Permutation! time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to n. Recently Ivan learned…
题目传送门 根据字典序,是个人都会想到依次把目前最小的数尽量往前面移动,直到它不能再往前移动,或者已经到了它的期望位置(就是排列的那个位置 比如$i$就应该在位置$i$)为止. 所以我刚开始是这么写的: #include<cstdio> #include<algorithm> #include<cstring> #include<vector> using namespace std; #define N 105 #define ll long long i…
[cf div 2 706E] Working routine Vasiliy finally got to work, where there is a huge amount of tasks waiting for him. Vasiliy is given a matrix consisting of n rows and m columns and q tasks. Each task is to swap two submatrices of the given matrix. Fo…
http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 序列中的数无论怎么改,都不会改变与绝对值最大的数的逆序对的数量 所以从绝对值最大的数开始,决定它的正负 若这个序列中没有重复的最大值 若i是正数,与右边比他小的形成逆序对 若i是负数,与左边比他小的形成逆序对 所以两边取较小的 若序列中出现重复的最大值 那么最优解的最大值一定是 先是若干个负数,然…
题意:有两个完全相同的排列,将其中一个的元素按相对顺序插入另外一个排列中,给你操作完的排列,求原排列. 题解:感觉看看样例就能直接写了啊,直接遍历,用桶存数字个数,如果桶为空,直接输出即可. 代码: int t; int n; vector<int> v; map<int,int> mp; int main() { ios::sync_with_stdio(false);cin.tie(0); cin>>t; while(t--){ cin>>n; mp.c…
http://codeforces.com/contest/724/problem/C 题目大意: 在一个n*m的盒子里,从(0,0)射出一条每秒位移为(1,1)的射线,遵从反射定律,给出k个点,求射线分别第一次经过这些点的时间. 解法一: (模拟) 射线不管怎么反射,都是和水平方向成45°角的,也就是说每一段射线上的点,横坐标和纵坐标的和或者差相等. 把每一个点放入它所对应的对角线里,然后模拟射线的路径就好. 代码: #include <iostream> #include <cstd…
F. Restore a Number   Vasya decided to pass a very large integer n to Kate. First, he wrote that number as a string, then he appended to the right integer k — the number of digits in n. Magically, all the numbers were shuffled in arbitrary order whil…
C. Epidemic in Monstropolis time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue fo…