题意:有一组数,每次操作可以将某个数移到头部或者尾部,问最少操作多少次使得这组数非递减. 题解:先离散化将每个数映射为排序后所对应的位置,然后贪心,求最长连续子序列的长度,那么最少的操作次数一定为\(n-len\). 感觉不好解释,直接上图,其实就是排序后它们一定是连续的,所以我们就求一个最长的连续的,然后s剩下的数移到头部尾部,贪心的想,这样一定是最优解. 代码: #include <iostream> #include <cstdio> #include <cstring…
题目链接:http://codeforces.com/contest/451/problem/B 解题报告:给出一个序列,要你判断这个序列能不能通过将其中某个子序列翻转使其成为升序的序列. 我的做法有点不一样,我是将原来的序列先按照升序排好序,然后分别从头和尾开始扫,找到跟原来的数组不一样的子序列的区间,然后判断这个区间是不是原来的区间翻转而来. #include<cstdio> #include<cstring> #include<iostream> #include…
题目链接: https://codeforces.com/contest/1209/problem/E2 题意: 给出$n$行和$m$列 每次操作循环挪动某列一次 可以执行无数次这样的操作 让每行最大值的累加和最大 数据范围: $1\leq n \leq 12$ $1\leq m \leq 20000$ 分析: 定义$dp[i][j]$,考虑前$i$列,选择状态为$j$的最大值 $ans=dp[m][(1<<n)-1]$ $dp[i][j]$可以由$dp[i-1][k]$转移,$k$是$j$的…
题目链接: https://codeforces.com/contest/1165/problem/F2 题意: 需要买$n$种物品,每种物品$k_i$个,每个物品需要两个硬币 每天获得一个硬币 有$m$个优惠 在$d_i$天,$t_i$物品卖一个硬币 求购买所需物品最少需要的天数 数据范围: $1 \le n, m \le 2 \cdot 10^5$ 分析: 我们可以注意到,如果某天是某个物品的最后优惠时间,那么我们一定要在这天尽可能多地购买这个物品 对答案进行二分 再二分得到每个物品在这个答…
Codeforces 题目传送门 & 洛谷题目传送门 qwq 这题大约是二十来天前 AC 的罢,为何拖到此时才完成这篇题解,由此可见我是个名副其实的大鸽子( 这是我上 M 的那场我没切掉的 F2 哦,u1s1 我上 M 还要多亏那场的 F1 啊( 首先暴力 \(3^nn\) 枚举子集显然是过不去的,否则这题就退化到 F1 了(大雾 考虑用一个容斥的思想,考虑求出答案的后缀和 \(f_i\),其中 \(i\) 是一个长度为 \(n-1\) 的二进制串.形式化地说,\(f_i\) 等于满足以下条件的…
题目链接:http://codeforces.com/problemset/problem/724/B 题目大意: 给出N*M矩阵,对于该矩阵有两种操作: (保证,每行输入的数是 1-m 之间的数且不重复) 1.交换两列,对于整个矩阵只能操作一次 2.每行交换两个数. 交换后是否可以使每行都是1-m 数字递增. 解题思路: 1.得到矩阵后先判断,是否每行可以交换两个数可以得到递增的矩阵,如果可以则输出"YES". 2.暴力交换两列,交换两列后,判断每行是否可以交换两个数得到递增的矩阵,…
B. Batch Sort time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a table consisting of n rows and m columns. Numbers in each row form a permutation of integers from 1 to m. You…
import java.util.Random; public class test { public static void main(String[] args) { int[] arr= generatenumbers(10); show(arr,"before sort:"); quicksort(arr,0,arr.length-1); show(arr,"after sort:"); } static void quicksort(int[] arr,i…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud  Bubble Sort Graph Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an in ascending order. He is bored of this so simple al…
You are given a sequence of integers of length nn and integer number kk. You should print any integer number xx in the range of [1;109][1;109] (i.e. 1≤x≤1091≤x≤109) such that exactly kk elements of given sequence are less than or equal to xx. Note th…