CodeForces 652B z-sort】的更多相关文章

题目链接:http://codeforces.com/contest/451/problem/B 解题报告:给出一个序列,要你判断这个序列能不能通过将其中某个子序列翻转使其成为升序的序列. 我的做法有点不一样,我是将原来的序列先按照升序排好序,然后分别从头和尾开始扫,找到跟原来的数组不一样的子序列的区间,然后判断这个区间是不是原来的区间翻转而来. #include<cstdio> #include<cstring> #include<iostream> #include…
B. z-sort time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A student of z-school found a kind of sorting called z-sort. The array a with n elements are z-sorted if two conditions hold: ai ≥ …
题目链接: B. z-sort time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A student of z-school found a kind of sorting called z-sort. The array a with n elements are z-sorted if two conditions hold:…
题目链接: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…
转载请注明出处: 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…
先对序列排个序. 例如:1 2 3 4 5 6 7 我们把序列分成两半,前一半是1 2 3 4,后一半是5 6 7 然后,我们从前一半取最小的一个,再从后一半取最小的一个..一直操作下去就能构造出答案了. 由此也可以看到,不可能出现Impossible的情况. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; +; int n…
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…
[题目链接] http://codeforces.com/contest/451/problem/B [算法] 模拟 在序列中找到一段单调递增的子序列,将这段序列反转,然后判断序列是否变得单调递增,即可 [代码] #include<bits/stdc++.h> using namespace std; ; int i,n,l,r; bool flag; int a[MAXN]; int main() { scanf("%d",&n); ; i <= n; i+…
题意 给出一个归并排序的算法\(mergesort\),如果对于当前区间\([l, r)\)是有序的,则函数直接返回. 否则会分别调用\(mergesort(l, mid)\)和\(mergesort(mid, r)\),其中\(mid = \left \lfloor \frac{l+r}{2} \right \rfloor\) 最后合并左右两个子区间 下面请你构造一个\(1 \sim n\)的排列,并且恰好调用\(k\)次\(mergesort\)函数完成排序 分析 首先,对函数的调用次数一定…
A. Points and Segments (easy) Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/430/problem/A Description Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on…
Make It Connected CodeForces - 1095F You are given an undirected graph consisting of nn vertices. A number is written on each vertex; the number on vertex ii is aiai. Initially there are no edges in the graph. You may add some edges to this graph, bu…
Educational Codeforces Round 117 (Rated for Div. 2) A. Distance https://codeforces.com/contest/1612/problem/A 题目给出的条件是 距离为曼哈顿距离,而曼哈顿距离等价于步长. 由题目的一半条件,可以得到步长和为AB步长,各自步长为AB步长的一半. 所以显然可以推出: \[1.如果和为奇数则,不存在\\ 2.如果都为偶数,显然只需要取步长一半即可\\ \] //原始代码 #include<bi…
题意:给出n个点,m个区间,需要给这些点涂上蓝色或者红色,使得每个区间里面的点的红色的点的个数与蓝色的点的个数的差值小于1 唉,题目的标题就标注了一个easy= = 最开始做的时候对点还有区间都排序了,模拟来做,可是错了 后来发现不管区间怎么样,只要红色和蓝色交替涂色, 就一定能满足“使得每个区间里面的点的红色的点的个数与蓝色的点的个数的差值小于1 ”这个条件 有点像上次做的cf交替输出奇数偶数那个A题 #include<iostream> #include<cstdio> #in…
Problem A. AerodynamicsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86821#problem/A Description Bill is working in a secret laboratory. He is developing missiles for national security projects. Bi…
A题: 题意:判断火星上的节假日最多和最少 分析:除以7,然后我们对原数模7的余数进行判断一下即可 #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <vector> #include <algorithm> #include <set> #include <map> #include <…
A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Polycarp loves ciphers. He has invented his own cipher called Right-Left. Right-Left cipher is used for strings. To encr…
B:当n是偶数时无解,因为此时树中有奇数条边,而我们每次都只能删除偶数条.当n是奇数时一定有解,因为此时不可能所有点度数都为奇数,只要找到一个度数为偶数的点,满足将它删掉后,各连通块大小都为奇数就可以了.考虑如何证明这样的点一定存在.钦定一个根后,考虑找到一个度数为偶数的点,满足子树内点度数均为奇数.这样该点的所有儿子的子树都有奇数个点, 因为删掉该点后每个子树内只有一个点度数为偶数.又因为删掉这个点后该树剩下偶数个点和偶数个连通块,所以该点父亲所在连通块也有奇数个点. 于是只需要先自底向上删掉…
F - Opening Portals Pavel plays a famous computer game. A player is responsible for a whole country and he can travel there freely, complete quests and earn experience. This country has n cities connected by m bidirectional roads of different lengths…
E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't solve thi…
A.很水的题目,3个for循环就可以了 #include <iostream> #include <cstdio> #include <cstring> using namespace std; ]; int main() { cin>>str; ; int L = strlen(str); ; i < L; i++) ; j < L; j++) ; k < L; k++) if(str[i] == 'Q' && str[j…
传送门 N ladies attend the ball in the King's palace. Every lady can be described with three values: beauty, intellect and richness. King's Master of Ceremonies knows that ladies are very special creatures. If some lady understands that there is other l…
Discription N ladies attend the ball in the King's palace. Every lady can be described with three values: beauty, intellect and richness. King's Master of Ceremonies knows that ladies are very special creatures. If some lady understands that there is…
A Karen and Morning 找最近的回文时间 模拟  往后推 判判就行 //By SiriusRen #include <bits/stdc++.h> using namespace std; int tx,ty,T; bool check(){ ,ry=tx%; +rx==ty; } int main(){ scanf("%d:%d",&tx,&ty); ){ ;} T++,ty++; )tx++,ty=; )tx=; } } B Karen…
Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from w…
题目:https://vjudge.net/contest/323699#problem/A 题意:给你一棵树,然后有m个查询,每次查询问一条路径最大边小于给定查询的数量 思路:首先我们看到,我们其实可以计算出每个边权小于查询的所有连通块,然后sum+C(n,2),对每个连通块都加上值,然后就是答案了,但是这里注意查询数很多,我们肯定不能O(n)遍历每个查询,但是思路肯定是计算联通块里组合数的数量,怎么处理呢,我们注意到,他这个边权是的值的大小和我的连通块的有关,我们是否可以利用之前求出来的值呢…
这道题并不简单,要得出几个结论之后才可以做.首先就是根据Kruskal求最小生成树的过程,短边是首选的,那么对于这道题也是,我们先做一次直选短边的最小生成树这样会形成多个联通块,这些联通块内部由短边相连.那么接下来要形成完整的最小生成树,我们就得用长边把这些联通块连起来,因为要最短路径,所以我们用Dijkstra做连边的过程 这里给出一个结论:只要满足两个条件:第一,每个联通块内部不能连长边.第二,一个联通块不能被访问两遍. 重点来了:只要是满足这两个条件下树就能保证它是一棵最小生成树. 为什么…
sort - sort lines of text files sort命令用于将文本文件内容加以排序. sort可针对文本文件的内容,以行为单位来排序. 语法: sort [OPTION]... [FILE]... sort [OPTION]... --files0-from=F sort [-bcdfimMnr][-o<输出文件>][-t<分隔字符>][+<起始栏位>-<结束栏位>][--help][--verison][文件] 参数: sort默认无参…
题意 有\(n\)个武器,第\(i\)个武器攻击力为\(a_i\),价值\(ca_i\). 有\(m\)个防具,第\(i\)个防具防御力为\(b_i\),价值\(cb_i\). 有\(p\)个怪,第\(i\)个怪攻击力为\(x_i\),防御力为\(y_i\),价值\(z_i\). 可以选择\(1\)个武器和\(1\)个防具,假设选择第\(i\)个武器和第\(j\)个防具,那么你需要花费\(a_i+b_j\),且可以杀死所有满足攻击力小于\(a_i\)且防御力小于\(b_j\)的怪,并获得这些怪物…
A.Phillip and Trains CodeForces 586D 题意:过隧道,每次人可以先向前一格,然后向上或向下或不动,然后车都向左2格.问能否到达隧道终点. 题解:dp,一开始s所在列如果前方为'.'则dp[i]=1.r[i]代表上一次的dp[i]值. 如果该行当前可行,那么它就可以更新它上下两行(如果有),必须用r[i]去更新. 再判断每行在当前时间是否会发生撞车:看看位置 i+t*2,i+t*2+1,i+t*2+2 是否有车. #include <iostream> #inc…