C. Insertion Sort Petya is a beginner programmer. He has already mastered the basics of the C++ language and moved on to learning algorithms. The first algorithm he encountered was insertion sort. Petya has already written the code that implements th…
题目传送门 /* 贪心/数学:还以为是BFS,其实x1 + 4 * k = x2, y1 + 4 * l = y2 */ #include <cstdio> #include <algorithm> #include <cstring> using namespace std; ; const int INF = 0x3f3f3f3f; char s[MAXN][MAXN]; int main(void) //Codeforces Round #212 (Div. 2)…
B. Substrings Sort time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given nn strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such…
一开始读错题了...想当然地认为只能相邻元素交换...(然后换了两种写法WA了4发,5分钟切A的优势荡然无存) 题目链接:https://codeforces.com/contest/1365/problem/B 题意 有 $n$ 个数,每个数的种类为 $0$ 或 $1$,不同种类的元素可以任意交换,问这些数能否排为非递减序. 题解 如果两个种类都有,一定可以排为有序,稍微证明一下: 将种类为 $0$ 的数都交换到最左边,种类为 $1$ 的数都交换到最右边 每个种类的数可以利用另一个种类的一个数…
D. Bubble Sort Graph time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an …
题意:有一组数,每次操作可以将某个数移到头部或者尾部,问最少操作多少次使得这组数非递减. 题解:先离散化将每个数映射为排序后所对应的位置,然后贪心,求最长连续子序列的长度,那么最少的操作次数一定为\(n-len\). 感觉不好解释,直接上图,其实就是排序后它们一定是连续的,所以我们就求一个最长的连续的,然后s剩下的数移到头部尾部,贪心的想,这样一定是最优解. 代码: #include <iostream> #include <cstdio> #include <cstring…
D. Fools and Foolproof Roads   You must have heard all about the Foolland on your Geography lessons. Specifically, you must know that federal structure of this country has been the same for many centuries. The country consists of n cities, some pairs…
A. Two Semiknights Meet 题目大意:有一个8x8的棋盘,上面放有两个骑士,骑士以“田字”的方式走.每个方格都被定义为good或者bad,问骑士能否在good的格子中相遇? 由于骑士最初位于good的格子中,并且骑士可以按原路返回,所以只需判断骑士是否能够相遇就行了(相遇后可以返回任意一个骑士的初始位置).根据骑士的移动特性,两个骑士位置的行和列之差应该为4的倍数. 自己开始的时候,还试图计算相遇位置,然后bfs逐个验证,想麻烦了... #include <cstdio>…
A. Game With Sticks (451A) 水题一道,事实上无论你选取哪一个交叉点,结果都是行数列数都减一,那如今就是谁先减到行.列有一个为0,那么谁就赢了.因为Akshat先选,因此假设行列中最小的一个为奇数,那么Akshat赢,否则Malvika赢. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace…
 cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....       其实这个应该是昨天就写完的,不过没时间了,就留到了今天.. 地址:http://codeforces.com/contest/651/problem/A A. Joysticks time limit per test 1 second memory limit per test 256…