题目链接: C. Prefix Product Sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Consider a sequence [a1, a2, ... , an]. Define its prefix product sequence . Now given n, find a permutation…
题目链接 \(Description\) 对于一个序列\(a_i\),定义其前缀积序列为\(a_1\ \mathbb{mod}\ n,\ (a_1a_2)\ \mathbb{mod}\ n,...,(a_1a_2...a_n)\ \mathbb{mod}\ n\). 给定\(n\),求一个\(n\)的排列,使得该排列的前缀积序列是\([0,1,2,...,n-1]\)的一个排列.无解输出\(NO\). \(n\leq10^5\). \(Solution\) 考虑无解的情况.因为\(n!\equi…
意甲冠军: 对于数字n, 他询问是否有1~n置换 这种布置能够在产品上模每个前缀n 有可能0~n-1 解析: 通过观察1肯定要在首位,n一定要在最后 除4意外的合数都没有解 其它质数构造 a[i]=i*inv[i-1] , 这样用逆元把前面每一个数的影响都消除掉 C. Prefix Product Sequence time limit per test 1 second memory limit per test 256 megabytes input standard input outpu…
Consider a sequence [a1, a2, ... , an]. Define its prefix product sequence . Now given n, find a permutation of [1, 2, ..., n], such that its prefix product sequence is a permutation of [0, 1, ..., n - 1]. Input The only input line contains an intege…
大意: 构造一个[1,2,...n]的排列, 使得前缀积模n为[0,1,...,n-1]的排列 这种构造都好巧妙啊, 大概翻一下官方题解好了 对于所有>=6的合数$n$, 有$(n-1)! \equiv 0 \space (mod \space n)$, 一定不成立 对于素数可以构造$[1,\frac{2}{1},\frac{3}{2},\frac{4}{3},...,\frac{n-1}{n-2},n]$, 或者构造$[1,g,g^{-2},g^3,g^{-4},...,n]$, $g$为$n…
题意 将1~n的正整数重排列,使得它的前缀积在模n下形成0~n-1的排列,构造解或说明无解.n≤1E5. 思考 小范围内搜索解,发现n=1,n=4和n为质数时有解. 不难发现,n一定会放在最后,否则会多出很多的0. 1.n≥4且n为合数:由于n能写成pq的形式,其中pq|(n-1)!,因此第n-1的位置上一定为0,故无解. 2.n为质数:按以下方式构造.令答案ai=i*(i-1)-1(若i-1=0,令其逆元为1).则其前缀积为1,2,3,...,n-1,0.由于i*(i-1)-1=j*(j-1)…
传送门 题目大意 分析 因为n为质数所以i-1的逆元唯一 因此ai唯一 代码 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cctype> #include<cmath> #include<cstdlib> #include<queue> #inc…
题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考虑:如果操作的次数最少,那么最终得到的不降的数列,必然是由原始数列中的数组成的,具体的证明可以使用反证法 知道了上面讲述的性质,这题就好搞了 先将原始数列(设为 A,共 n 个数)中所有的数去重并从小到达排序,保存在另一个数列中(设为 B,共 m 个数) 定义状态:f[i][j] 表示将原始数列中的…
正解:构造+数论 解题报告: 传送门! maya这题好神仙啊我jio得,,,反正我当初听的时候是没有太懂的,,, 首先这题你要知道一些必要的数学姿势 比如哥德巴赫猜想巴拉巴拉的 然后直接讲题趴QAQ 首先看到说,分成质数之后,不难想到哥德巴赫猜想(,,,什么鬼辣我连哥德巴赫猜想的内容都不清楚哪里不难想到了QAQ (哥德巴赫猜想:任一大于2的偶数可分为不同俩质数之和) 然后对这n个数的和:sum=n*(n+1)/2分类讨论 1)sum为质数 欧克分成一组就成了! 2)sum为非2偶数 利用哥德巴赫…
链接: 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…
题目链接  Divisibility 题意 给定$n$和$k$,构造一个集合$\left\{1, 2, 3, ..., n \right\}$的子集,使得在这个集合中恰好有$k$对正整数$(x, y)$, $x < y$ 满足$x$是$y$的约数. 选定$1$和$2$, 首先把满足 $x > [\frac{n}{2}]\ $的质数$x$留出来, 然后把满足 $ [\frac{n}{3}]\  < x <=  [\frac{n}{2}]\ $的质数,以及他们的两倍留出来,   留出来…
题目:戳这里 题意:n个数,两种操作,第一种是a[i]*a[j],删掉a[i],第一种是直接删除a[i](只能用一次)剩下的数序列号不变.操作n-1次,使最后剩下的那个数最大化. 解题思路: 正数之间全用操作1得到的结果最大. 负数的个数如果是偶数,全用操作1最后得到的也最大.如果是奇数,那最大的那个负数(贪心的思想)就要进行特殊操作,具体怎么操作要看后面有没有0,如果有0就用操作1去乘,没有就用操作2直接给这个数删了. 有0的话就把所有的0乘最后一个0,然后把最后一个0删了. 附ac代码: 1…
题目链接: D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output For each string s consisting of characters '0' and '1' one can define four integers a00, a01, a10 and a11, where …
K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/K Description The world famous scientist Innokentiy almost finished the creation of perpetuum mobile. Its main part is the energy generator which…
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is wr…
D. Multipliers 题目连接: http://codeforces.com/contest/615/problem/D Description Ayrat has number n, represented as it's prime factorization pi of size m, i.e. n = p1·p2·...·pm. Ayrat got secret information that that the product of all divisors of n take…
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite sequence of Picks. Fortunately, Picks remembers how to repair the sequence. Initi…
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2, ...…
[题目链接] http://codeforces.com/problemset/problem/610/C [题目大意] 构造出2^n个由1和-1组成的串使得其两两点积为0 [题解] 我们可以构造这样一个矩阵,右下角四分之一和其余三个分块相反, 不断扩展这个矩阵即可. [代码] #include <cstdio> #define rep(i,n) for(int i=1;i<=n;i++) using namespace std; const int N=1000; int k,p[N]…
[题目链接] http://codeforces.com/contest/804/problem/E [题目大意] 给出一个1到n的排列,问每两个位置都进行一次交换最终排列不变是否可能, 如果可能输出交换顺序. [题解] 我们发现对于四个一组组内进行六次交换之后可以保证四个数的位置不变, 而对于每组相互之间可以一共进行十六次交换使得两组均不会发生变化 所以如果n能被4整除,那么我们可以4个分组达到目的, 当不能被4整除的时候,我们发现余数为2和3的时候都不能构造出可行解. 在余数为1的时候有一种…
题目链接 http://codeforces.com/contest/1276/problem/C 题解 嗯,比赛结束前3min想到做法然后rush不出来了--比赛结束后又写了15min才过-- 以下是我的做法: 设最优解的行数和列数分别是\(R\)和\(C\), 不妨设\(R\le C\). 那么显然对于每个数我们只能选不超过\(R\)个. 考虑将所有数按出现次数从大到小排序,枚举\(R\), 求出可用的数的个数,设为\(cnt\), 那么显然\(C\le \frac{cnt}{R}\). 我…
A 直接判存不存在连续的三个包含A,B,C就行 /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long ll; typedef unsigned long long ull; ][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }}; , gakki = +…
原题链接:http://codeforces.com/problemset/problem/848/A 题意:让我们构造一个字符串.这里有一种操作:取走这个字符串的若干部分,分成两部分,然后将这两部分的合并插回字符串中,进行过处理的字符串部分不能再次被单独取出,只能整体取出,直到无法操作后停止.每次这种操作后,消耗, f(s,c)是c字符在s字符串重复的次数. 让我们输出:若干次操作后最小值恰好为k的字符串,不用考虑字符的顺序. 思路:最好怎么简单怎么做.如果我们让字符串中只有一种字符,显然通过…
Codeforces 题面传送门 & 洛谷题面传送门 中规中矩的构造题一道. 首先考虑将两张图都向一个中间状态转化.方便起见我们取所有点都连向 \(1\) 号点的情形作为中间状态. 考虑怎样从初始状态向我们这个中间状态转化.显然我们要将所有不与 \(1\) 相连的对角线都变得与 \(1\) 相连对吧,那我们就考虑从 \(2\) 开始枚举每一个点 \(x\) 以及一个与 \(x\) 相连的边 \((x,y)(x<y)\),满足 \(y\) 与 \(1\) 有边,如果 \(|x-y|>2\…
Codeforces 题目传送门 & 洛谷题目传送门 obviously,难度高一点的构造题对我来说都是不可做题 首先考虑将排列拆成一个个置换环,也就是 \(\forall i\) 连边 \(i\to p_i\),显然这样我们可以得到一个个环. 首先考虑怎样同时处理两个置换环,假设有两个环,长度分别为 \(p,q\),元素分别为 \(x_1,x_2,\cdots,x_p;y_1,y_2,\cdots,y_q\).我们考虑以下步骤同时将这两个环中所有元素复位: 交换 \(x_1,y_1\),两个置…
C. Laboratory Work time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : standard output Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value \(n\) tim…
题意:给定n和k,求第n个序列中第k个数是多少,序列是这样构造,原来只有1,然后再copy一遍放在到后面再在中间放上一个没有出现过的最小整数,就变成了 121,下次就成了1213121. 析:很明显是用递归来做,如果k在前半部分,那么就再递归,如果是在后半部分,那么就是先减一半再递归. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <st…
题目链接: B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dreamoon likes to play with sets, integers and .  is defined as the largest positive integer that divides both a a…
题目链接: E. Points on Plane time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output On a plane are n points (xi, yi) with integer coordinates between 0 and 106. The distance between the two points wi…
H - Football BetsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87493#problem/H Description While traveling to England, it is impossible not to catch the English passion for football. Almost everyon…