【CodeForces 618B】Guess the Permutation】的更多相关文章

题 题意 有个1到n的一个全排列,告诉你第i个数和全部n个数相比的较小的是哪个,和自己相比时为0,于是有个主对角线为0的矩阵,求原数列 分析 我的想法是,给我们的每一行之和按大小排一下,就知道第i个数是数列里第几大的了.因为是n的全排列,所以第几大就是几. 按sum排完序后,r[sum[i].id]=i;这句表示原来在id位置的数是现在第i大的,所以r就是要求的全排列了. 代码 #include <stdio.h> #include <algorithm> #define N 60…
[题目链接]:http://codeforces.com/problemset/problem/785/E [题意] 给你一个初始序列1..n顺序 然后每次让你交换任意两个位置上面的数字; 让你实时输出q个操作,每个操作过后整个序列逆序对的个数; [题解] 分块法; 分成根号n个块. 每个块按照数字升序排; 然后再用一个a数组具体记录每个位置上的数字; 找逆序对的方式如下: 对于交换l,r 查找l+1..r-1当中比a[l]小的数字,比a[l]大的数字; 查找l+1..r-1当中比a[r]小-比…
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=2000),问满足[数列长度是k && 数列中每一个元素arr[i]在1~n之间 && 数列中元素可以重复]的数列有多少个?结果对10^9+7取余 解题思路:dp[i][j]表示长度是j,最后一位是i的种数 if(kk%i==0) dp[kk][j+1]+=dp[i][j] #inc…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number ass…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan regi…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Kleofáš is participating in an n-thlon - a tournament consisting of n different competitions in n different disciplines (numbered 1 through n). T…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Anton loves transforming one permutation into another one by swapping elements for money, and Ira doesn't like paying for stupid games. Help them…
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q个操作; 有以下两种类型 ①将第i个连通块里面灯取反 ②询问你(x1,y1)(x2,y2)这个矩形区域内灯的权值的和; [题解] 要用到二维的树状数组; 取反操作只要O(1)就能完成; 即先不管它是什么,取反就是了; 然后在询问的时候,直接用二维树状数组累加; 这里的累加可能是减也可能是加; 也可能…
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小; [题解] 首先明确n<=2的时候是无解的. n>2之后都有解; 这里设 n2+b2=a2 则有 n2=a2−b2 也即 n2=(a+b)∗(a−b) 这里对n分两类讨论; ① n为奇数 则令 a−b=1 a+b=n2 这样 2∗a=n2+1 因为n是奇数所以右边是个偶数; 得出来的a就是整数了…