![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
思维
【杰杰】
这个作者很懒,什么都没留下…
展开
-
P1013 [NOIP1998 提高组] 进制位
传送门题意:给你一个由字母代表数字的加法表,问你这个加法是几进制以及每个字母所代表的数字是多少。思路:动手稍微模拟一下就会发现:1.表中一定会有进位。当表中有数字x时,那就一定会有数字x2,x4…一直到出现进位。2.由于第一列和第一行的字符串长度都为1,那么可以的到这个表一定是n-1进制的。还是基于第一点,结合加法表和进位的特点,可以得到:最终一定会出现0到n-1的所有数。所以只需要先找到0,再找到1,就可以推出后面的字母了。#include<bits/stdc++.h>us原创 2022-03-21 10:50:51 · 249 阅读 · 0 评论 -
D. Yet Another Sorting Problem
传送门题意:给你一个序列,每次操作选择三个下标,使得选择的这三个下标的数以环形互相移动(即1,2,3变为3,1,2),问你经过任意次的操作后,这个序列能不能变为非递减序列。思路:首先考虑序列中是否存在两个相同的数。若存在:那么每两次操作都可以将两个不处于正确位置的数移动到正确位置。若不存在:那么可以证明:每次操作都会让整个序列的逆序对进行偶数次的改变,最终,如果初始序列的逆序对为偶数,则“YES”,否则“NO”。#include<bits/stdc++.h>using name原创 2022-03-03 17:26:44 · 277 阅读 · 0 评论 -
P1069 [NOIP2009 普及组] 细胞分裂
传送门题意:给你m1,m2,现在有M=m1m2M = m1^{m2}M=m1m2个试管,n种细胞,每种细胞经过1s可以分裂成aia^iai个细胞,问你可以将细胞平均分配到M个试管的最短时间。思路:先得出m1的质因数集合s1以及这些m1中这些质因数的个数,可以想到:如果i细胞可以在有限的时间内得到合适的数量使其可以分配到M个试管中去,那么i细胞每次分裂的个数ai,它的质因数集合设为s2,则s1一定包含于s2。于是,s2集合里的质因数每秒加1,而s1里的每种质因数的个数应该还需要乘上m2,最后我们只原创 2021-09-26 11:50:04 · 421 阅读 · 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 · 187 阅读 · 0 评论 -
P4447 [AHOI2018初中组]分组
传送门题意:给定一个序列,要给这些序列分组,要求组内的值连续且不重复,问元素个数最少的组的元素个数最大值。思路:可以先将连续的数字看成一组,在这些连续数字中,由小到大判断每一个值的个数,对于相邻两个数来说,如果较大值的个数比较小值得个数多,那么较大值就可以让自己的全部值参与划分并且还有剩余,但如果较大值的个数比较小值小,那么划分就可以到此结束了,若是较大值参与划分,它便不会有剩余,这就可能导致后面的值无法分配,从而使得答案较小。#include<bits/stdc++.h>usin原创 2021-09-18 15:56:37 · 239 阅读 · 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 · 88 阅读 · 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 · 121 阅读 · 0 评论 -
Codeforces Round #739 (Div. 3) D. Make a Power of Two
传送门思路:算出n与2的每个幂次方的最大匹配数即可,最好把2的0到61的幂全部匹配一次,否则可能会wa4.#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>#include<map>#include<queue>#include<math.h>#include<vector>using names原创 2021-08-20 10:42:14 · 102 阅读 · 0 评论 -
Codeforces Round #739 (Div. 3) C. Infinity Table
传送门思路:找规律,每一行的第一个数为完全平方数。#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>#include<map>#include<queue>#include<math.h>#include<vector>using namespace std;#define ll long lo原创 2021-08-19 23:04:10 · 55 阅读 · 0 评论 -
Codeforces Round #727 (Div. 2) B. Love Song
传送门思路:前缀和。#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>#include<map>#include<queue>#include<math.h>#include<vector>using namespace std;#define ll long longll sum[10001原创 2021-08-18 21:36:21 · 119 阅读 · 0 评论 -
牛客9-Happy Number
传送门#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>#include<map>#include<queue>#include<math.h>#include<vector>using namespace std;#define ll long longll a[1000];int main原创 2021-08-17 22:57:02 · 90 阅读 · 0 评论 -
Codeforces Round #738 (Div. 2) C. Mocha and Hiking
传送门题意:给你一个有向图,问你是否存在经过所有点一次且仅一次的路径。思路:对于一般情况,我们只需要考虑是否存在<i,n+1>和<n+1,i+1><i,n+1>和<n+1,i+1><i,n+1>和<n+1,i+1>这样的路径,存在,则有解。除此之外,还有两种特殊情况,即当<n,n+1>或<n+1,1><n,n+1>或<n+1,1><n,n+1>或<n+1,1&g原创 2021-08-16 10:21:28 · 85 阅读 · 0 评论 -
B. Friends and Candies
#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>#include<map>#include<queue>#include<math.h>using namespace std;#define ll long longint a[200010];int main(){ int t; cin>&g.原创 2021-08-13 00:11:19 · 59 阅读 · 0 评论 -
Codeforces Round #726 (Div. 2)-C. Challenging Cliffs
传送门题意:给你n座山的高度,输出满足第一座山和最后一座山的高度差最小且难度最大的序列。思路:排序,先满足首尾,再将选择的那两座山的后面一部分接到头后头,把剩下的山从小到大再接在后面。#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>#include<map>#include<queue>#include<math原创 2021-08-12 23:42:48 · 104 阅读 · 0 评论 -
Codeforces Round #728 (Div. 2)-B. Pleasant Pairs
传送门题意:给你一串数字,求满足ai+aj=i+ja_i+a_j=i+jai+aj=i+j且i<j的序列对数。思路:对于第i个数,仅当下标j满足(j+i)=ai+aj(j+i)=a_i+a_j(j+i)=ai+aj时合法,也就是说,每次应选择j+i为aia_iai的倍数的下标。#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>#in原创 2021-08-12 23:02:10 · 82 阅读 · 0 评论 -
杭电多校5-VC Is All You Need
传送门题意:给你n个点和一个k维空间,问你是否存在一个k-1维得超平面,使得对于所有n个点的所有不同的颜色组合,该平面可以使不同颜色的点分开。思路:画图或者直接看样例。#include<bits/stdc++.h>using namespace std;#define ll long longconst ll mod = 1e9+7;int main(){ int t; cin>>t; while(t--) {原创 2021-08-04 00:03:26 · 222 阅读 · 3 评论 -
牛客多校6-I.Intervals on the Ring
传送门题意:给你一个环,上面连续分布着数字1到n,给你m个不相交区间,让你给出数个区间,使得这些区间的交等于m个区间的并。思路:找到所有空着的地方,所有空着的区间的补集就是答案。#include<stdio.h>#include<iostream>#include<algorithm>#include<bits/stdc++.h>#include<queue>#include<string.h>#include&原创 2021-08-03 00:07:55 · 68 阅读 · 0 评论 -
Codeforces Round #736 (Div. 2) C. Web of Lies
传送门题意:n个人,m个朋友关系,在一个关系中,编号较小的那个人权力较小。q次操作:让两个人成为朋友;让两个人断绝关系;杀死所有有朋友的并且他的所有朋友的权力都比他大的人,重复该操作直到没有可以杀掉的人,该操作不影响后续关系。思路:对于一个人来说,如果它能够存活下来,那么它一定不会结交比它权力更大的朋友,因而我们可以先算出初始关系当中能够活下来的人数ans,再用一个数组fri[x]来表示第x个人拥有的比它权力更大的朋友的个数,在每次添加或者删除一段关系时,对其做出改变,同时判断ans是否需要做出改原创 2021-08-02 01:18:26 · 194 阅读 · 0 评论 -
Educational Codeforces Round 112 (Rated for Div. 2) C-Coin Rows
传送门思路:双指针,从第一行最右边和第二行最左边开始,尽量让两个指针所划过的数有着最小的差值,当两指针相遇时,便是爱丽丝拐弯的地方。#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>#include<map>#include<queue>#include<math.h>using namespace std;原创 2021-08-01 22:23:39 · 75 阅读 · 0 评论 -
牛客暑假多校训练营第一场-1001 Mod, Or and Everything
传送门题意:给你一个n,求n分别模上1到n之后相或的值思路:由或的性质可以得知:只需要找到所有模数在二进制位上出现的1的并集即可(并且对于同一模数,多个该模数和单个该模数对答案的贡献一样),而对于此题来说,我们肯定可以在模数中找到一个从1开始且公差为1的等差数列,因而我们只需要找到模数的最大值,就可以得出答案。#include<bits/stdc++.h>using namespace std;#define ll long longll a[100];int main()原创 2021-07-23 18:13:27 · 105 阅读 · 0 评论 -
杭电多校:KD-Graph(并查集)
传送门题意:将图中的点划分为k个集合,求一个值d,对于集合内的点:若点与点之间有直接相连的路径,则这些路径至少有一个小于等于d;对于不同集合的点:若这两点有直接相连的路径,则这些路径全部大于d。思路:这题和点的关系不大,我们更看重边,因为要保证集合内的点之间的边值小于等于某个数,集合与集合之间的边值大于某个数,可以想到一个初步的思路:将边的权值由小到大排列,并按排列后的顺序合并成一个集合(如果先合并权值大的边,就势必会导致集合内的边权值大于集合外边的权值);但仅仅是由小到大合并也无法满足条件,因原创 2021-07-22 22:01:18 · 105 阅读 · 0 评论 -
牛客暑假多校训练营2.K—stack
传送门题意:已知若干时刻的单调栈大小,求一个合法的序列思路:对于该单调栈不同时刻同样大小时,可以得出这样一个结论:越晚加入单调栈的元素(即下标越大)一定比之前加入的小可采取反证法证明此结论:在不同时刻栈大小相同的情况下,若后加入的元素大于先加入的元素,则后加入的元素无法将先加入的元素剔除从而导致后加入的元素会使得栈大小+1,与条件矛盾。其次,对于该单调栈不同时刻不同大小时,可以得出这样一个显而易见结论:大的时候加入的元素一定比小的时候加入的元素大综上两条结论,可以得出这样一个行之有效的解题方法原创 2021-07-21 12:05:14 · 68 阅读 · 0 评论 -
Simple Math Problem
传送门思路:题目中给出的矩阵均为16进制表示,根据规律输出对应10进制数即可。#include<bits/stdc++.h>using namespace std;#define ll long longconst int inf = 0x3f3f3f3f;int main(){ ll n; cin>>n; ll x,y; cin>>x>>y; if(x+y < n) { cout<<(y+1)*y/2+原创 2021-05-17 21:35:03 · 121 阅读 · 0 评论 -
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 · 72 阅读 · 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 · 383 阅读 · 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 · 233 阅读 · 0 评论