![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
cf
文章平均质量分 60
记录cf
【杰杰】
这个作者很懒,什么都没留下…
展开
-
D. Strange Definition
传送门题意:给你一个数列,数列中互相之间满足lcm(x,y)/gcd(x,y)lcm(x,y)/gcd(x,y)lcm(x,y)/gcd(x,y)开方后是整数的可以构成一个多重集合,每过一秒数列中的所有数都会变为他们的乘积,问第w秒的时候,数列中最大的多重集合中的元素个数。思路:通过观察式子lcm(x,y)/gcd(x,y)lcm(x,y)/gcd(x,y)lcm(x,y)/gcd(x,y)可以知道同属一个集合内的元素需要满足何种性质。对每个数分解质因数,则x=p1k1∗p2k2∗∗∗pmKmx=原创 2022-04-04 13:31:30 · 287 阅读 · 0 评论 -
D. Martial Arts Tournament
传送门题意:给你n个数,构造一组x,y,将这n个数划分为小于等于x,大于等于y以及大于x小于y的数三个区间,我们可以往每个区间添加数,使得每个区间的数为2的幂次,输出添加数的最小个数。思路:设num[x]为1-x中数的个数,我们枚举小于等于x的区间需要添加的2的幂次和大于x且小于y的2的幂次,那么剩下的部分自然就是大于等于y的数字个数,枚举求最小添加数。#include<bits/stdc++.h>using namespace std;#define ll long long原创 2022-01-17 18:48:22 · 670 阅读 · 0 评论 -
E. Replace the Numbers
传送门题意:执行q次操作,有两个选项:添加一个数或者将当前所有指定的数变为另一个数。思路:我们记录每个数第一次出现的位置,作为“头”,在新添加数的时候,记录每个位置上的数第一次出现的位置,也就是它的“头”。在修改时,只需要合并“头”就行了。#include<bits/stdc++.h>using namespace std;#define ll long long#define endl '\n'int ans[500010];int link[500010];int f原创 2022-01-10 17:23:36 · 350 阅读 · 0 评论 -
Codeforces Round #748 (Div. 3)A,B,C,D1,E题解
A. Elections传送门题意:给你a,b,c三个数,问你让这三个数每一个都严格大于其它俩数的最小花费。思路:分别对a,b,c进行判断即可。#include<bits/stdc++.h>#define ll long longusing namespace std;#define eps 0.00000001int main(){ int t; cin>>t; while(t--) { ll a,b,c; cin>>a>原创 2021-10-14 01:00:33 · 236 阅读 · 0 评论 -
Educational Codeforces Round 115 (Rated for Div. 2) D. Training Session
传送门题意:给你n个题,每个题都有一个主题和一个难度,输入保证同一个主题下不会有相同难度的题出现,现选择三个题组成一个题集,问你满足以下至少一个条件的选择有多少种:1.所选择的三个题目主题互不相同。2.所选择的三个题难度互不相同。思路:直接算出所有方案数的难度过大,于是走反面,用总的选择数-非法的选择数。对于此题的输入,我们可以建立邻接矩阵,并将每一种难度的题的数目装入桶中。遍历所有的问题,对于问题a(i,j)a(i,j)a(i,j),i表示主题,j表示难度,一定包含问题a的非法组合的数目为:原创 2021-10-12 22:30:58 · 107 阅读 · 0 评论 -
Codeforces Round #743 (Div. 2) B. Swaps
传送门思路:遍历b数组,找到a数组中小于bib_ibi的下标最小的数。#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>#include<map>#include<queue>#include<math.h>#include<vector>using namespace std;#define原创 2021-09-20 22:33:59 · 185 阅读 · 0 评论 -
Codeforces Round #730 (Div. 2) D1. RPD and Rap Sheet (Easy Version)
传送门思路:假设0到n-1之间的数为密码,则可以想到一个可行的解法:第一次输出0,之后的每一次都输出(i−1)⊕(i−2)(i-1)⊕(i-2)(i−1)⊕(i−2)。假设答案为x,那么第一次输出0,答案变为0⊕x;第二次输出0⊕1,那么答案就变为0⊕x⊕0⊕1,即x⊕1;第三次变为x⊕2…以上利用异或的性质,可以在n次询问中获得答案。#include<bits/stdc++.h>#include<ctime>using namespace std;#def原创 2021-09-11 20:03:29 · 87 阅读 · 0 评论 -
Educational Codeforces Round 113 (Rated for Div. 2) C. Jury Meeting
传送门题意:给你一个序列,每次从头到尾每一次让不为0的值减1,执行数次直到序列中所有数为0,问你满足序列中不会出现同一个数连续减两次的排列的种数。思路:易得:当序列中至少有一个最大数在所有比它小1的数的右边,那么该序列不满足条件,为了方便,考虑反面,用整个序列全排列的个数减去反面的个数。考虑反面:当一个最大数在第n位时,这种情况的个数为:An−1n−1∗A最大数个数最大数个数∗A比最大数小一的数的个数比最大数个数小一的数的个数A_{n-1}^{n-1}*A_{最大数个数}^{最大数个数}*A_{原创 2021-09-10 00:17:59 · 59 阅读 · 0 评论 -
Codeforces Round #742 (Div. 2) C. Carrying Conundrum
传送门题意:给你一个数n,并规定了一种特殊的运算规则,问你有多少种选择使得a,b在该运算规则下相加等于n。思路:因为进位不再是向左1位进,而是向左2位进位,因而可以把奇偶位分开来看,将奇数位的数组成一个数字,并得出组成该数字的方法数,偶数位同理,两者相乘-2即为答案(a,b不全为0).#include<bits/stdc++.h>#include<ctime>using namespace std;#define ll long long ll a[100];l原创 2021-09-07 13:49:20 · 116 阅读 · 0 评论 -
Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2) D. Take a Guess
传送门题意:有一个长度为n的隐藏数列,你可以询问最多2*n次数列中某两个位置的数的与或者并,问你这个数列中倒数第k大的数是多少。思路:结论:a+b = a&b+a|b,所以,我们可以求得a1a_1a1与其它数的和,再次询问获得a2+a3a_2+a_3a2+a3的和,通过a1+a2与a2+a3与a1+a3a_1+a_2与a_2+a_3与a_1+a_3a1+a2与a2+a3与a1+a3可以求得a1a_1a1的值,从而求出所有数的值。#include<stdio.h&原创 2021-09-03 18:15:24 · 110 阅读 · 0 评论 -
Codeforces Round #735 (Div. 2) C. Mikasa
传送门题意:给你n和m以及由n异或(1-m)组成的集合,问你这个集合中没有出现过的最小的非负整数是多少。思路:n⨁n\bigoplusn⨁x=kx=kx=k,且x为1到m中的每一个数由交换律可得:n⨁\bigoplus⨁k=x=x=x,而x为1到m中的每一个数,所以要找到集合{n⨁n\bigoplusn⨁x=kx=kx=k}中出现的最小非负整数,就是要找到一个最小的k,满足n⨁\bigoplus⨁k ≥\geq≥ m+1。现在要找到这个k,可以对每一个二进制位进行判断。从最高位开始,如果该原创 2021-08-06 23:08:36 · 67 阅读 · 0 评论 -
Codeforces Round #736 (Div. 2) C. Web of Lies
传送门题意:n个人,m个朋友关系,在一个关系中,编号较小的那个人权力较小。q次操作:让两个人成为朋友;让两个人断绝关系;杀死所有有朋友的并且他的所有朋友的权力都比他大的人,重复该操作直到没有可以杀掉的人,该操作不影响后续关系。思路:对于一个人来说,如果它能够存活下来,那么它一定不会结交比它权力更大的朋友,因而我们可以先算出初始关系当中能够活下来的人数ans,再用一个数组fri[x]来表示第x个人拥有的比它权力更大的朋友的个数,在每次添加或者删除一段关系时,对其做出改变,同时判断ans是否需要做出改原创 2021-08-02 01:18:26 · 193 阅读 · 0 评论 -
Codeforces Global Round 15 A-D
目录A. Subsequence PermutationB. Running for GoldC. Maximize the IntersectionsD. Array DifferentiationA. Subsequence Permutation传送门题意:给你一个字符串,问你要把这个字符串中的字符按从小到大排列,至少需要改变几个字符的位置。思路:将字符串进行排序,然后将原来的字符串和排序后的字符串逐字符比对,若不一样,则说明该字符的位置发生了变化。#include<bits/s原创 2021-07-27 00:23:38 · 113 阅读 · 0 评论 -
Codeforces Round #734 (Div. 3)A - C
该场链接A. Polycarp and Coins题意:用1和2凑出n来,并使得1和2的个数的差值最小;思路:先将n粗略地分为3份,其中2的贡献大约是1的两倍,即如果n是3的倍数,那么2的数量应该等同于1的数量,接下来再考虑n不是3的倍数的情况:如果n%3 == 1,即在满足2的数量等于1的数量时,多出一个1,此时1的数量+1;如果n%3 == 2,同理:2的数量多出一个。#include<bits/stdc++.h>using namespace std;#defin原创 2021-07-25 01:57:28 · 113 阅读 · 0 评论 -
Harbour.Space Scholarship Contest 2021-2022 (open for everyone, rated, Div. 1 + Div. 2)-B
传送门思路:模拟即可,注意在左右两边字母都合法的情况下也要考虑向左走#include<bits/stdc++.h>using namespace std;#define ll long longchar s[1000];char a[1000];int len,flag;void dfs(int pos,int j){ if(flag) { return; } if(j == len) { flag = 1; return; } if(pos ==原创 2021-07-24 21:49:03 · 107 阅读 · 0 评论 -
B. Nastia and a Good Array
传送门Nastia has received an array of n positive integers as a gift.She calls such an array a good that for all i (2≤i≤n) takes place gcd(ai−1,ai)=1, where gcd(u,v) denotes the greatest common divisor (GCD) of integers u and v.You can perform the operation原创 2021-05-08 22:55:12 · 176 阅读 · 0 评论 -
A. Nastia and Nearly Good Numbers
传送门Nastia has 2 positive integers A and B. She defines that:The integer is good if it is divisible by A⋅B;Otherwise, the integer is nearly good, if it is divisible by A.For example, if A=6 and B=4, the integers 24 and 72 are good, the integers 6, 660 a原创 2021-05-08 22:54:10 · 138 阅读 · 0 评论 -
Codeforces Round #719 (Div. 3) E. Arranging The Sheep
传送门You are playing the game “Arranging The Sheep”. The goal of this game is to make the sheep line up. The level in the game is described by a string of length n, consisting of the characters ‘.’ (empty space) and ‘*’ (sheep). In one move, you can move an原创 2021-05-06 23:26:55 · 205 阅读 · 2 评论 -
Codeforces Round #719 (Div. 3) D. Same Differences
传送门You are given an array a of n integers. Count the number of pairs of indices (i,j) such that i<j and aj−ai=j−i.InputThe first line contains one integer t (1≤t≤104). Then t test cases follow.The first line of each test case contains one integer n原创 2021-05-06 23:17:15 · 143 阅读 · 0 评论 -
Educational Codeforces Round 108 (Rated for Div. 2) D. Maximum Sum of Products
传送门You are given two integer arrays a and b of length n.You can reverse at most one subarray (continuous subsegment) of the array a.Your task is to reverse such a subarray that the sum ∑i=1nai⋅bi is maximized.InputThe first line contains one integer n原创 2021-04-30 23:53:44 · 52 阅读 · 1 评论 -
Educational Codeforces Round 108 (Rated for Div. 2) B. The Cake Is a Lie
传送门题读错了,我是傻逼。#include<bits/stdc++.h>using namespace std;#define ll long longint main(){ int t; cin>>t; while(t--) { int n,m,k; cin>>n>>m>>k; if(n*m-1 == k) printf("yes\n"); else printf("no\n"); }}..原创 2021-04-30 11:59:55 · 101 阅读 · 0 评论 -
Educational Codeforces Round 108 (Rated for Div. 2) A. Red and Blue Beans
传送门You have r red and b blue beans. You’d like to distribute them among several (maybe, one) packets in such a way that each packet:has at least one red bean (or the number of red beans ri≥1);has at least one blue bean (or the number of blue beans bi≥1)原创 2021-04-30 11:58:19 · 71 阅读 · 0 评论 -
Codeforces Round #717 (Div. 2) A. Tit for Tat
传送门Given an array a of length n, you can do at most k operations of the following type on it:choose 2 different elements in the array, add 1 to the first, and subtract 1 from the second. However, all the elements of a have to remain non-negative after th原创 2021-04-21 23:49:56 · 125 阅读 · 0 评论 -
Codeforces Round #716 (Div. 2) C. Product 1 Modulo N
传送门Now you get Baby Ehab’s first words: “Given an integer n, find the longest subsequence of [1,2,…,n−1] whose product is 1 modulo n.” Please solve the problem.A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (poss原创 2021-04-20 20:35:51 · 162 阅读 · 0 评论 -
Codeforces Round #716 (Div. 2) A-Perfectly Imperfect Array
Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square.A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero) elements.I原创 2021-04-19 23:58:53 · 140 阅读 · 0 评论 -
Codeforces Round #716(Div. 2) B - AND 0, Sum Big
Baby Badawy’s first words were “AND 0 SUM BIG”, so he decided to solve the following problem. Given two integers n and k, count the number of arrays of length n such that:all its elements are integers between 0 and 2k−1 (inclusive);the bitwise AND of all原创 2021-04-19 23:56:14 · 381 阅读 · 0 评论 -
Codeforces Round #715 (Div. 2) C-The Sports Festival
传送门The student council is preparing for the relay race at the sports festival.The council consists of n members. They will run one after the other in the race, the speed of member i is si. The discrepancy di of the i-th stage is the difference between th原创 2021-04-17 21:58:31 · 161 阅读 · 0 评论 -
Codeforces Round #715 (Div. 2)B. TMT Document
传送门The student council has a shared document file. Every day, some members of the student council write the sequence TMT (short for Towa Maji Tenshi) in it.However, one day, the members somehow entered the sequence into the document at the same time, cre原创 2021-04-17 01:07:18 · 232 阅读 · 0 评论 -
Educational Codeforces Round 107 (Rated for Div. 2) C. Yet Another Card Deck
You have a card deck of n cards, numbered from top to bottom, i. e. the top card has index 1 and bottom card — index n. Each card has its color: the i-th card has color ai.You should process q queries. The j-th query is described by integer tj. For each q原创 2021-04-17 01:00:47 · 105 阅读 · 0 评论 -
Codeforces Round #713 (Div. 3) A-B Palindrome
传送门 C. A-B PalindromeYou are given a string s consisting of the characters ‘0’, ‘1’, and ‘?’. You need to replace all the characters with ‘?’ in the string s by ‘0’ or ‘1’ so that the string becomes a palindrome and has exactly a characters ‘0’原创 2021-04-11 21:38:33 · 242 阅读 · 0 评论 -
CodeCraft-21 and Codeforces Round #711 (Div. 2) B. Box Fitting
B. Box Fittingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n rectangles, each of height 1. Each rectangle’s width is a power of 2 (i. e. it can be represented as 2x for some non-neg原创 2021-03-31 21:04:12 · 145 阅读 · 0 评论 -
CodeCraft-21 and Codeforces Round #711 (Div. 2) A. GCD Sum
A. GCD Sumtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe gcdSum of a positive integer is the gcd of that integer with its sum of digits. Formally, gcdSum(x)=gcd(x, sum of digits of x) for a pos原创 2021-03-31 18:28:15 · 205 阅读 · 0 评论 -
B - Partial Replacement
You are given a number k and a string s of length n, consisting of the characters ‘.’ and ‘’. You want to replace some of the '’ characters with ‘x’ characters so that the following conditions are met:The first character ‘’ in the original string should b原创 2021-03-30 19:57:15 · 110 阅读 · 0 评论 -
Codeforces Round #710 (Div. 3) D - Epic Transformation
D. Epic Transformationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a of length n consisting of integers. You can apply the following operation, consisting of several steps原创 2021-03-29 12:47:00 · 140 阅读 · 0 评论 -
Codeforces Round #710 (Div. 3)C. Double-ended Strings
C. Double-ended Stringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given the strings a and b, consisting of lowercase Latin letters. You can do any number of the following operations in原创 2021-03-29 09:20:06 · 148 阅读 · 0 评论 -
Codeforces Round #709 (Div. 2, based on Technocup 2021 Final Round) A - Prison Break
A. Prison Breaktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMichael is accused of violating the social distancing rules and creating a risk of spreading coronavirus. He is now sent to prison. Luc原创 2021-03-22 11:02:43 · 422 阅读 · 0 评论 -
Educational Codeforces Round 105 (Rated for Div. 2)B. Berland Crossword
思路:枚举四个角是否要染黑。#include<bits/stdc++.h>using namespace std;const int mod = 1e9 + 7;const int inf = 0x3f3f3f3f; int check(int uu, int rr, int dd, int ll,int u, int r, int d, int l,int zs,int zx,int ys,int yx){ if(uu >= u && rr >=.原创 2021-03-05 10:54:23 · 74 阅读 · 1 评论 -
Codeforces Global Round 13 B - Minimal Cost
传送门 B. Minimal Costtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a graph of n rows and 106+2 columns, where rows are numbered from 1 to n and columns from 0 to 106+1:Let’s原创 2021-03-01 13:57:12 · 182 阅读 · 0 评论 -
Codeforces Round #702 (Div. 3)B. Balanced Remainders
思路:答案与数组内元素本身无关,只与其模3后的值的个数有关,于是,可以想到,while(c0!=c1 || c0!=c2 || c1!=c2),便从c0到c2,找到最大的值,记为pos,然后让其后一个值加上(pos-n/3),直到c0c1c2.#include<bits/stdc++.h>using namespace std;#define ll long longconst int mod = 1e9 + 7;int c[3];int main(){ int t; sc.原创 2021-02-26 23:15:37 · 121 阅读 · 0 评论 -
Codeforces Round #703 (Div. 2)A. Shifting Stacks
传送门思路:能满足条件的最低限度为{0,1,2,3,…,n}这种序列,因此我们只需要将给出的序列构造成这种序列就行。#include<bits/stdc++.h>using namespace std;#define ll long longconst int mod = 1e9 + 7;ll a[110];int main(){ int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n)原创 2021-02-26 22:22:02 · 66 阅读 · 0 评论