Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/482/problem/A Description Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consisting of n distinct posi…
题意:对于某个序列,若\(1\le i\le n\),\(1\le j\le i\)且\(p_j>p_i\),或者\(1\le i\le n\),\(i<j \le n\)且\(p_j>p_i\),那么就可以在\(i\)和\(j\)之间连一条边,求有多少能够成环的长度为\(n\)的序列. 题解:对于长度为\(n\)的序列,也就是有\(n\)个点,那么要成环的话,边数必须\(\ge n\),所以我们要让能连的边数\(<n\),再思考一下,对于每个数,除了\(n\),对于\([1,n-…
链接: https://codeforces.com/contest/1234/problem/E 题意: Let's define pi(n) as the following permutation: [i,1,2,-,i−1,i+1,-,n]. This means that the i-th permutation is almost identity (i.e. which maps every element to itself) permutation but the elemen…
题意:给你\(n\)个顶点和\(m\)条边,问它们有多少个单环(无杂环),例如图中第二个就是一个杂环. 题解:不难发现,如果某几个点能够构成单环,那么每个点一定只能连两条边.所以我们先构建邻接表,然后从某个数开始跑dfs,如果这一边所有点的度数都为\(2\),那么就能构成一个单环. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include &l…
C. K-special Tables 题目连接: http://www.codeforces.com/contest/625/problem/C Description People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitiv…
D. The table 题目连接: http://www.codeforces.com/contest/226/problem/D Description Harry Potter has a difficult homework. Given a rectangular table, consisting of n × m cells. Each cell of the table contains the integer. Harry knows how to use two spells…
C. Harmony Analysis 题目连接: http://www.codeforces.com/contest/610/problem/C Description The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil…
D. Lazy Student Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/606/problem/D Description Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a gr…
D. Regular Bridge Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/problem/D Description An undirected graph is called k-regular, if the degrees of all its vertices are equal k. An edge of a connected graph is called a b…
A. 24 Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/468/problem/A Description Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game. Initially you ha…
B. School Marks Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/problem/B Description Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test the…
原题链接:http://codeforces.com/contest/584/problem/A 题意: 给你n和t,让你构造一个长度为n的数,并且被t整除 题解: 方法很多,可以乱构造.....不过需要特判n=1且t=10这种特殊情况 代码: #include<iostream> #include<cstring> using namespace std; int t,n; int main() { cin >> n >> t; && t…
题目链接:http://codeforces.com/problemset/problem/788/B B. Weird journey time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little boy Igor wants to become a traveller. At first, he decided to vi…
链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s1,s2,-,sn is beautiful if |si−si+1|=1 for all 1≤i≤n−1. Trans…
A. Brain's Photos time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpo…
这道题不错,思维上不难想到规律,但是如何写出优雅的代码比较考功力. 首先第一个人的序号可以确定,那么接下来所有奇数位的序号就可以一个连一个的确定了.然后a[i].first==0时的a[i].secod就是第二个人的序号,然后偶数位的序号也可以一个连一个的确定了. 用一个next数组,其下标就是a[i].first,其值就是a[i].second,这样巧妙地使用数组下标就解决了“串链子”这个难点,我之前想的每次用二分来找真是弱爆了.. 而在找第一个人的序号时也是妙用flag数组下标. #incl…
B. Mahmoud and Ehab and the bipartiteness time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bi…
题目链接:G. New Roads 题意:给出n个结点,t层深度,每层有a[i]个结点,总共有k个叶子结点,构造一棵树. 分析: 考虑一颗树,如果满足每层深度上有a[i]结点,最多能有多少叶子结点 那么答案很简单,就是对(a[i]-1)求和再加1(每一层的结点都集中在上一层的一个结点上)   同理,我们考虑最少能有多少叶子结点,就是把上一个的答案再减去min(a[i]-1, a[i-1]-1)的求和,就是每一层的结点都尽可能的分散在上一层的结点 根据这个,那么如果要求有k个叶子节点,k在最大值与…
C. Median Smoothing   A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and e…
D2. Kirk and a Binary String (hard version) time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output The only difference between easy and hard versions is the length of the string. You can hack this pro…
题意:给你一个\(n\)x\(m\)的矩阵,你可以任意位置的元素+1,只能加一次,问你如何使得任意位置的元素不等于它四周的值.输出操作后的矩阵. 题解:构造,矩阵中某两个下标的和的奇偶性一定和四周的都不同,因为题目保证有解,所以我们只要让下标和是奇数的填奇数,偶数的填偶数即可. 代码: int t; int n,m; int g[110][110]; int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>t;…
题意:给出一个长度为\(n\)的序列\(a\),根据\(a\)构造一个序列\(b\),要求: ​ 1.\(b_{1}=0\) ​ 2.对于\(i,j(i\le i,j \le n)\),若\(a_{i}=a_{j}\),则\(b_{i}=b_{j}\) ​ 3.对于\(i\in [1,n-1]\),有\(b_{i+1}=b_{i}\)或\(b_{i+1}=b_{i}+1\) 求有多少可能的\(b\),答案对\(998244353\)取模. 题解:由第二个条件能知道,对于所有\(a_{i}=a_{…
题意:有一个长度为\(2n\)的数组,删去两个元素,用剩下的元素每两两相加构造一个新数组,使得新数组所有元素的\(gcd\ne 1\).输出相加时两个数在原数组的位置. 题解:我们按照新数组所有元素均为偶数来进行构造,因为旧数组的长度为\(2n\),所以无论原数组有多少个奇数和偶数,我们都可以选择删去两个数,使得剩下的数两两组合得到偶数,直接分类讨论输出即可. 代码: #include <iostream> #include <cstdio> #include <cstrin…
Codeforces Round #485 (Div. 2) E. Petr and Permutations 题目连接: http://codeforces.com/contest/987/problem/E Description Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to gene…
Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output For a positive integer n let's define a function f: f(n) =  - 1 + 2 - 3 + .. + ( - 1)n…
Codeforces Round #453 (Div. 1) A. Hashing Trees 题目描述:给出一棵树的高度和每一层的节点数,问是否有两棵树都满足这个条件,若有,则输出这两棵树,否则输出perfect solution 首先判断什么时候是perfect:当不存在相邻两层的节点数均大于\(0\)时,输出perfect. 接下来就是构造的问题.若上一层只有一个节点,那么这一层的所有节点只能连到那个唯一的节点,否则分为两棵树不同的构造: 所有点都连到上一层的第一个节点 第一个点连到上一层…
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate it n = int(raw_input()) s = "" a = ["I hate that ","I love that ", "I hate it","I love it"] for i in ran…
Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393…
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输出”#Color”,如果只有”G”,”B”,”W”就输出”#Black&White”. #include <cstdio> #include <cstring> using namespace std; const int maxn = 200; const int INF =…
 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…