![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
gym
文章平均质量分 79
tomjobs
别慌,慌也没用
展开
-
Bounty Hunter II Gym - 100753B(DAG最小路径覆盖,二分图最大匹配)
题意:DAG图求最少多少条不想交路径覆盖全图思路:真没想到是二分图;建图以后就构成了二分图,一开始n个点对应n个路径,每进行一次匹配路径数减少一,所以结果就是n减去求最大匹配数。#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<iostream>#include<queue>#include<map>.原创 2021-03-21 18:44:04 · 253 阅读 · 0 评论 -
A - Acing the contest Gym - 102890A(状压DP)
题意:TTT个人参加比赛,你可以任意调换这个TTT个人参加比赛的顺序,每个人有生命值。PPP个比赛,每个比赛有难度值bbb和奖励值ccc。一个人可以选择参加这个比赛,减少bbb的生命值(要保证bbb最后非负),获得ccc的奖励。或者跳过这个比赛,或者将这个比赛甩手给下一个人。求最后得到的奖励值和最大值。思路:写题的时候没读出来顺序可以重排的意思,所以一直wa2。。。因为人的顺序是可以随意变动的,所以我们用状压dp来表示已经比完赛的人,0代表这个人还没有比过赛或者正在比赛。定义dp[sta][p原创 2021-03-02 22:10:43 · 337 阅读 · 0 评论 -
K - L Textiles Gym - 102911L(递归,L方块铺满)
The Philippines is home to more than 175 ethnolinguistic groups, with many indigenous peoples still carrying on their heritage through traditions which are hundreds of years old. Among these traditions is the weaving of fabric and textiles adorned with int原创 2021-01-27 17:19:06 · 408 阅读 · 0 评论 -
H - Implementation Problem Gym - 102911I(模拟)
Alice has encountered a puzzle room in a video game. To progress, she needs to slide some large cubes into their proper positions in order to activate a magic portal which leads deeper into the dungeon. The puzzle is also further complicated by large immov原创 2021-01-27 12:40:47 · 182 阅读 · 0 评论 -
C - Dancing Queen Gym - 102911D(构造)
As their act for their school’s variety show, Alice and Bob are going to perform their own remix of the classic disco song Dancing Queen! Aside from the chorus, their remix has N different verses to be sung by the two of them.The verses are labeled 1,2,3,原创 2021-01-26 23:00:37 · 202 阅读 · 0 评论 -
I - Junior Prom Gym - 102911J(二分图)
Everyone is excited to celebrate the new year and the (eventual) end of the pandemic with a bombastic Junior Prom! Unfortunately, people are a little too excited for it, and each student organization decided to host their own prom—plus, they all scheduled原创 2021-01-26 22:13:25 · 232 阅读 · 0 评论 -
B - Chocolate Game: Love is War Gym - 102911C(对称博弈)
Alice is madly in love with Bob and she hopes to impress him by beating him in yet another chocolate game.The game begins with two piles of chocolate cookies, one on the left and one on the right. Alice and Bob will take turns.On each player’s turn, they原创 2021-01-26 21:51:38 · 236 阅读 · 0 评论 -
2020江苏省赛I - Intersections Gym - 102875I(最短路)
题意:如果当前时间是timtimtim,那么如果timmod (a[x][y]+b[x][y])<a[x][y]tim \mod (a[x][y]+b[x][y])<a[x][y]timmod(a[x][y]+b[x][y])<a[x][y],这个点可以向(x+1,y),(x−1,y)(x+1,y),(x-1,y)(x+1,y),(x−1,y)走,否则可以向(x,y−1),(x,y+1)(x,y-1),(x,y+1)(x,y−1),(x,y+1)走。问(sx,sy)(sx,sy)(s.原创 2020-12-02 13:31:35 · 528 阅读 · 0 评论 -
2020江苏省赛A - Array Gym - 102875A(线段树,欧拉降幂)
思路:有加有乘有次方,看起来好像是不可维护的,但是注意到模数很小,可以从这里下手。lazy[i]lazy[i]lazy[i]代表iii转换为lazy[i]lazy[i]lazy[i],因为ppp很小,所以最多只需要维护30个lazylazylazy标记就好了。不过这样常数有点大,我们在计算快速幂的时候使用一下欧拉降幂优化常数。#include <cstdio>#include <iostream>#include <cstring>#include &l..原创 2020-12-02 12:26:58 · 476 阅读 · 1 评论 -
K - Number with Bachelors Gym - 102835K(数位DP,不出现重复数字的排列,第k数问题)
题意:合法数字定义是不出现重复数字的数。有10进制的询问和16进制的询问,询问第k个合法数字或者[a,b][a,b][a,b]之间有多少个合法数字。思路:写的很麻的一道题,但其实很思路很简单。10进制和16进制是一样的,转换一下就好了。考虑[a,b][a,b][a,b]内多少个合法数字,我们定义dp[i][j]dp[i][j]dp[i][j]代表数字选到了第iii位,并且已经选择数字的状态为jjj(二进制状态,1代表选择了这一个数字,0代表没选择这一个数字)。数位DP算一下就得出[a,b][a原创 2020-11-29 14:51:24 · 482 阅读 · 0 评论 -
H - Optimization for UltraNet Gym - 102835H(最小生成树)
题意:求一棵生成树树,任意两点距离为其路径边上最短边。生成树权值为其任意两点距离的和。要使得生成树最小边最大,然后权值最小。思路:可以想到,肯定是所选的边权值越小越好。同时最小边要足底啊,所以就是确定最小权值边以后,剩下边选最小的几个。这个过程我们要二分枚举最小边,使得最小边最大。可以按边统计答案,就是dfsdfsdfs每次取最小的边,那么这条边分割出两个连通块,大小分别为size1,size2size1,size2size1,size2,边的权值为valvalval,那么这条边的贡献就是size1原创 2020-11-28 11:32:02 · 862 阅读 · 1 评论 -
B - Make Numbers Gym - 102835B(表达式,暴力)
题意:四个数字,可以改变顺序,中间可以添加+,-,*符号。数字之间还可以合并成一个数。求最终能生成多少个数字。思路:暴力枚举生成了哪几个数,再枚举这几个数之间符号是啥,再用栈算出这个结果,用set去重。写的贼麻烦,快麻了。#include <bits/stdc++.h>using namespace std;const int maxn = 2e5+10;set<int>st;int get(deque<pair<int,int>>que)原创 2020-11-28 00:45:19 · 535 阅读 · 1 评论 -
C - Pyramid Gym - 102835C(DP)
题意:n∗nn*nn∗n的棋盘,从(0,0)(0,0)(0,0)出发,只能向右或者向下。如果走到了x+y=nx+y=nx+y=n,那么就停止。每个点有一个方向值,初始均为向右,限定了这点是向右还是向下,每遍历一次方向值就取反。求第kkk个球会在哪个点停止。思路:T∗N∗NT*N*NT∗N∗N,复杂度1e9的算法。。。定义dp[i][j]dp[i][j]dp[i][j]为k−1k-1k−1次后这个点的方向值被改变多少次。转移过程类似于bfs,一层一层的转移。f[x+1][y]+=(f[x][原创 2020-11-28 00:41:20 · 456 阅读 · 0 评论 -
F - Cable Protection Gym - 102835F(基环树的最小点覆盖)
题意:一棵基环树,求最少的点覆盖所有边。思路:定义dp[i][0/1]dp[i][0/1]dp[i][0/1]代表这个点覆盖/不覆盖的最小点数,转移就是普通树DP转移,很基础就不讲了。因为这是一棵基环树,所以我们找到环上一个边(a,b)(a,b)(a,b)断开,然后分别讨论aaa必须被覆盖和bbb必须被覆盖的情况。#include<cstdio>#include<iostream>#include<cstring>#include<algorith原创 2020-11-28 00:22:26 · 646 阅读 · 3 评论 -
B - A Leap of faith Gym - 101864B(树状数组求区间相交)
题意:两类区间,求相互之间有交集区间对数。每次操作还可能增加某一类区间。思路:对每一类区间的左右下标分别开一个树状数组记录出现次数。那么对于第一类区间[l,r][l,r][l,r],我们要计算其与第二类区间有交集的个数。直接计算不好算,我们算与其没有交集的个数,等价于区间右端点在lll之前,或者区间左端点在rrr之后的区间。这个统计过程就可以用树状数组了。#include <cstdio>#include <cstring>#include <vector>原创 2020-11-22 17:56:18 · 270 阅读 · 0 评论 -
H - Little T2 and Derangements Gym - 101864H(第k个错排排列,状压DP)
题意:iii不在第iii个位置的排列称为错排排列,求按字典序第kkk个错排排列。2≤n≤100,k≤1e152≤n≤100,k≤1e152≤n≤100,k≤1e15。思路;对于这类第kkk个排列的问题,都可以想到,只需要很少的数,就可以构造出很多排列。尽管本题nnn范围达到100,但实际上最多考虑20个数字就够了。我们先按照错排公式num[i]=(n−1)∗(num[i−1]+num[i−2])num[i]=(n-1)*(num[i-1]+num[i-2])num[i]=(n−1)∗(num[i原创 2020-11-22 16:37:28 · 252 阅读 · 0 评论 -
I - Marbelous Meena Gym - 101864I(gcd,数学)
题意:nnn堆石头。每次可以选择一堆石头移动一些到另外一堆石头上。要求被移动的石堆结果为之前的两倍。求能否将nnn堆石头合成一堆。不行的话,问要给几个石堆增加数目才可行。思路:结论是nnn堆石头的和为SUMSUMSUM,gcdgcdgcd为GCDGCDGCD。如果SUM/GCDSUM/GCDSUM/GCD是2的次幂数,那就可以,否则就不行,并且最多只需要给一个石堆增加数目达到这个要求。证明:SUM=M∗2kSUM=M*2^kSUM=M∗2k,则MMM是一个奇数。合并完成以后肯定剩下一个数目为SUM原创 2020-11-21 19:56:19 · 187 阅读 · 1 评论 -
GYM J - Non Super Boring Substring Gym - 101864J(回文,组合)
题意:求问多少个子串中存在长度大于等于kkk的回文子串。思路:因为长度大于kkk的回文串,一定包含长度为kkk或者k+1k+1k+1的回文子串,所以只需要考虑长度为kkk和k+1k+1k+1的回文子串。然后对每个左端点确定有多少个匹配的右端点即可。#include <bits/stdc++.h>using namespace std;const int maxn = 1e5+10;const int mod1 = 1e9 + 7;const int mod2 = 1e9 + 9;原创 2020-11-19 14:59:46 · 254 阅读 · 0 评论 -
GYM M - TFF Gym - 101864M(贪心)
题意:H(x)=F(x)∗G(x)H(x)=F(x)*G(x)H(x)=F(x)∗G(x)给你H(x)H(x)H(x)和G(x)G(x)G(x),求F(x)F(x)F(x)。思路:从F(x)F(x)F(x)的最高位开始确定,确定完最高位,就消除掉这个最高位对于H(x)H(x)H(x)的影响,于是下一位就成了最高位。#include <bits/stdc++.h>using namespace std;const int maxn = 2005+10;typedef long lo原创 2020-11-19 14:56:56 · 87 阅读 · 0 评论 -
GYM L - School Reunion Gym - 101864L(双指针)
题意:第iii个人停留的时间为[l,r][l,r][l,r]。求你最少要停留的连续时间为多少,保证能遇到至少ppp个人。思路:对于第iii个人的停留时间[l,r][l,r][l,r],实际上就是差分,使得lll的权值加1,r+1r+1r+1的权值为-1。二分这个连续时间midmidmid,然后看连续midmidmid长度是否存在大于ppp的值。但是有点小问题,区间范围为1e9,不能forforfor一遍搞。但是贪心的想,你停留的时间段的右端点,一定是一个人停留时间的左端点;你停留时间段的左端点,原创 2020-11-19 14:50:20 · 141 阅读 · 0 评论 -
GYM G - GCD and LCM of 3 numbers Gym - 101864G(素数,DP)
题意:询问存在多少x≤y≤zx≤y≤zx≤y≤z,满足F(x,y,z)=x∗y∗z/Gcd(x,y,z)F(x,y,z)=x*y*z/Gcd(x,y,z)F(x,y,z)=x∗y∗z/Gcd(x,y,z)思路:问题可以转换成n=a∗b∗cn=a*b*cn=a∗b∗c,且a,b,ca,b,ca,b,c的gcdgcdgcd为1。这意味着nnn的每个质因子只能分配给2个数,或者分配给1个数。其中n=F(x,y,z)Gcd(x,y,z)2n=\frac{F(x,y,z)}{Gcd(x,y,z)^2}n=G原创 2020-11-19 14:44:06 · 201 阅读 · 0 评论 -
GYM D - Beauty and The Tree Gym - 101864D(启发式合并)
题意:一棵树,每层深度的值为这层深度所有节点权值和。求删掉iii节点对应子树后的最大深度值。思路:裸的启发式合并。先递归轻子树并清空,再递归重子树并且不清空,再遍历轻子树统计结果。#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#include<vector>using namespace原创 2020-11-19 14:34:09 · 196 阅读 · 1 评论 -
GYM A - A Criminal Gym - 101864A(约瑟夫环,找规律)
题意:nnn个人,你是第xxx个人。系统等可能的选择前[L,n][L,n][L,n]个人,然后每次从第二个人开始抓,抓一个挑一个,最后幸存一个。求你幸存的概率。思路:打表发现,幸存者的分布为:1131351357…可以发现幸存的全是奇数,且是按照2i2^i2i一循环。#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#inclu原创 2020-11-19 14:31:04 · 247 阅读 · 0 评论 -
B - Buggy ICPC Gym - 101889B(模拟,猜想)
题意:一个字符串,当输入一个元音字符的时候,整个字符串都会反转,求有多少种输入方案可以得到这个字符串。思路:a1,a2,a3代表元音字符,s1,s2,s3代表辅音字符串。模拟还原结果串,可以发现,只有中间部分的辅音字符串在输入的时候可以不同,其他部分都是确定的,所以求出中间部分辅音字符串的长度即可。#include<cstdio>#include<cmath>#include<algorithm>#include<vector>#inclu原创 2020-10-28 17:08:13 · 184 阅读 · 0 评论 -
J - Jumping frog Gym - 101889J(gcd,置换)
题意:R可与走,P不可以走。可以任选起点,每步的长度为k。求问存在多少k,使得你最后可以跳回起点。从i跳一步后会变成(i+k)%n思路:感觉和之前写过的置换很像,也是在环上跳。对于所跳的步长k,如果gcd(n,k)=1,那么实际就是要遍历每一个点,必须得满足所有点都是R。否则的话,最终要跳n∗k/gcd(n,k)/k=n/gcd(n,k)n*k/gcd(n,k)/k=n/gcd(n,k)n∗k/gcd(n,k)/k=n/gcd(n,k)步。这个部分的个数等于n的约数的个数,不会很多。所以我原创 2020-10-28 12:49:09 · 230 阅读 · 0 评论 -
I - Imperial roads Gym - 101889I(LCA+最小生成树)
题意:一个有权图,求每次必须选一个边的最小生成树值。思路:先跑出最小生成树,然后对于给出的x,y,在最小生成树上找到其路径,删掉一条最大边,再加上(x,y)这条边就是最小生成树的值了。#include<cstdio>#include<cmath>#include<algorithm>#include<vector>#include<map>using namespace std;typedef long long ll;c原创 2020-10-28 11:18:42 · 208 阅读 · 0 评论 -
G - Gates of uncertainty Gym - 101889G(DP)
题意:一个电路由与非门构成,构成二叉树。但是有的与非门只能输出1,有的只能输出0。求有多少种输入方案,使得你能检测出错误。思路:定义dp[i][0/1][0/1]dp[i][0/1][0/1]dp[i][0/1][0/1]代表第iii个门电路本来要输出0/1,结果输出0/1的方案数。那么结果就是dp[1][0][1]+dp[1][1][0]dp[1][0][1]+dp[1][1][0]dp[1][0][1]+dp[1][1][0]。#include <bits/stdc++.h>原创 2020-10-28 11:16:03 · 146 阅读 · 0 评论 -
F - Fundraising Gym - 101889F(线段树DP)
题意:每个人有3个属性a,b,c。求选择一些人,使得任意两个人,要么a,b严格大于另一个人,要么完全相同。求最大的c值和。思路:有两维状态的限制,类似于偏序。定义dp[i][j]dp[i][j]dp[i][j]代表考虑了前iii个人,b的值为jjj时的最大ccc值和。把a,b值完全相同的人先合并。我们一维一维的考虑,先按照第一维度a排序从小到大,第二维度按照b排序从大到小,则从后往前遍历就保证了已经更新过的人bbb大于自己(或者b等于自己,但是他的c值小于自己,所以不会影响到自己)。那么转原创 2020-10-28 11:12:57 · 266 阅读 · 0 评论 -
E - Enigma Gym - 101889E(DP)
题意:一个数字,有些数位是?,要求你替换掉这些?,使得这个数字是N的倍数,没有前导0并且尽量小。思路:定义dp[i][j][k]dp[i][j][k]dp[i][j][k]代表选择了前i个数位,模N的余数为j,当前这一位选择了k是否可行。因为我们要让这个数字最小,所以要从后往前遍历,这样回溯的时候就是从前往后,我们只要每次使用当前最小数字就可以保证这个数字最小了。#include <cstdio>#include <cstring>#include<algorit原创 2020-10-28 11:07:22 · 157 阅读 · 0 评论 -
C - Complete Naebbirac‘s sequence Gym - 101889C
题意:n个数字,你可以加一个数字,减一个数字,或者加一个数字且减一个数字。操作只能进行一次,求能否使得每种数字数目一样。思路:直接枚举#include<cstdio>#include<cmath>#include<algorithm>#include<vector>using namespace std;typedef long long ll;const int maxn = 1e4 + 7;int a[maxn],vis[max原创 2020-10-28 11:04:27 · 199 阅读 · 0 评论 -
2019香港区域赛gym102452 C. Constructing Ranches(点分治)
Ranching and the cowboy tradition originated in Spain, out of the necessity to handle large herds of grazing animals on dry land from horseback. During the Reconquista, members of the Spanish nobility and various military orders received large land grants原创 2020-10-19 00:18:10 · 611 阅读 · 0 评论 -
H - Lighthouses Gym - 102576H(区间DP,环形DP)
题意:有一些房子,构成了一个凸包。房子之间有铁路。你可以从一个房子出发遍历这些铁路,但是要求路径不能交叉,不能走走过的点。求最多走多少距离。思路:环上的区间DP。将房子看做圆,走了i−>ji->ji−>j后,就相当于把圆分为了两半,之后只能走其中一半。定义f[i][j][0/1]f[i][j][0/1]f[i][j][0/1]为还可以逆时针走(i,j)(i,j)(i,j)部分的点,且下一次出发的点为i(j)i(j)i(j)的最大所走距离。因为我们规定了是逆时针方向的走,相.原创 2020-10-12 13:33:35 · 370 阅读 · 0 评论 -
Shuffle Cards Gym - 247729C(rope,平衡树)
Eddy likes to play cards game since there are always lots of randomness in the game. For most of the cards game, the very first step in the game is shuffling the cards. And, mostly the randomness in the game is from this step. However, Eddy doubts that if原创 2020-10-10 16:03:16 · 194 阅读 · 0 评论 -
Erasing Numbers Gym - 102452E(前缀和)
After a long statistics lecture, the students are about to leave the classroom when it suddenly starts to rain heavily. Since you don’t have your umbrella with you, you decide to stay in the classroom and hope the rain will end soon. Several minutes later,原创 2020-10-10 12:30:43 · 686 阅读 · 0 评论 -
Defining Labels Gym - 102452D(进制)
Microsoft Excel is a spreadsheet developed by Microsoft. It features calculation, graphing tools, pivot tables, and a macro programming language called Visual Basic for Applications. It has been a very widely applied spreadsheet for many different operatin原创 2020-10-10 11:31:41 · 197 阅读 · 0 评论 -
G - Game Design Gym - 102452G(构造)
Tower defence games are the best games to kill time. In this kind of games, the player needs to build towers at certain candidate locations to defend a base building from monsters. The difficulty lies in that the budget for building towers is usually quite原创 2020-10-10 11:16:06 · 398 阅读 · 0 评论 -
J - Junior Mathematician Gym - 102452J(数位DP)
Number theory is a branch of pure mathematics devoted primarily to the study of the integers and integer-valued functions. German mathematician Carl Friedrich Gauss said, “Mathematics is the queen of the sciences—and number theory is the queen of mathemati原创 2020-10-10 11:10:05 · 314 阅读 · 0 评论 -
I - Incoming Asteroids Gym - 102452I(优先队列)
The International Coalition to Prevent Catastrophes (ICPC) recently discovered several small asteroids in a nearby galaxy. If these asteroids hit the Earth, it will lead to a terrible disaster. So it is important for the ICPC to fully study the orbit traje原创 2020-10-10 00:22:36 · 529 阅读 · 0 评论 -
Installing Apps Gym - 101623I(背包+贪心)
题意:下载app,每个app有下载容量和安装容量。内存必须满足下载容量才能下载,最后所占空间为安装容量。求c的内存最多可以安装多少个app。思路:比赛的时候wzf猜了个结论,就是按照 d-s排序从大到小遍历,然后按照普通背包跑然后过了。事后想想的话,其实可以从背包转移方程看出来:dp[j−num+a[i].s]=max(dp[j−num+a[i].s],dp[j−num]+1),num=max(a[i].s,a[i].d),num≤j≤cdp[j - num + a[i].s] =max(dp[原创 2020-10-10 00:09:02 · 324 阅读 · 0 评论 -
J - Juggling Troupe Gym - 101623J(结论)
题意:一些数(0,1,2)。每轮游戏中2会分到左右两个位置(第一个和最后一个只会分到一个位置)。全是0,1时游戏结束,求最终序列。思路:感觉像个经典结论题(波形碰撞?),但是找不到源头,感觉证明不了。。。将每个2单独考虑,找到其左边第一个a[l]=0,右边第一个a[r]=0,可以发现在l+r-x的位置会出现0,a[l],a[r]变成1。然后依次考虑下去。#include<cstdio>#include<set>#include<cstring>#inc原创 2020-10-10 09:53:59 · 169 阅读 · 0 评论