算法
♡-流浪孩
这个作者很懒,什么都没留下…
展开
-
Educational Codeforces Round 99------Sequence and Swaps
题目You are given a sequence a consisting of n integers a1,a2,…,an, and an integer x. Your task is to make the sequence a sorted (it is considered sorted if the condition a1≤a2≤a3≤⋯≤an holds).To make the sequence sorted, you may perform the following opera原创 2020-12-01 17:20:05 · 155 阅读 · 0 评论 -
Educational Codeforces Round 99 ------ Ping-pong
题意Alice and Bob play ping-pong with simplified rules.During the game, the player serving the ball commences a play. The server strikes the ball then the receiver makes a return by hitting the ball back. Thereafter, the server and receiver must alternatel原创 2020-12-01 14:23:40 · 279 阅读 · 0 评论 -
Educational Codeforces Round 99 (Rated for Div. 2)------Jumps
题目You are standing on the OX-axis at point 0 and you want to move to an integer point x>0.You can make several jumps. Suppose you’re currently at point y (y may be negative) and jump for the k-th time. You can:either jump to the point y+kor jump to原创 2020-12-01 14:00:24 · 176 阅读 · 0 评论 -
Educational Codeforces Round 98 (Rated for Div. 2)------Radio Towers
题目There are n+2 towns located on a coordinate line, numbered from 0 to n+1. The i-th town is located at the point i.You build a radio tower in each of the towns 1,2,…,n with probability 12 (these events are independent). After that, you want to set the s原创 2020-11-21 10:24:44 · 154 阅读 · 0 评论 -
Educational Codeforces Round 98 (Rated for Div. 2)------Robot Program
题目There is an infinite 2-dimensional grid. The robot stands in cell (0,0) and wants to reach cell (x,y). Here is a list of possible commands the robot can execute:move north from cell (i,j) to (i,j+1);move east from cell (i,j) to (i+1,j);move south fro原创 2020-11-21 08:29:37 · 153 阅读 · 0 评论 -
牛客小白月赛29(签到:A、E、G、H)
A贪心,由于基地可以重复销毁,所以找出找出每架战机可轰炸基地的最大价值,排序之后贪心找一下即可#include<iostream>#include<algorithm>using namespace std;const int N = 1e6 + 15;struct node{ int d, v;}no[N];bool cmp(node a, node b){ if(a.d == b.d) return a.v < b.v;原创 2020-11-15 08:31:29 · 197 阅读 · 0 评论 -
Codeforces Round #672 (Div. 2)------Cubes Sorting
题目Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes.For completing the chamber Wheatley needs n cubes. i-th cube has a volume ai.Wheatley has to place cubes in such a way that they原创 2020-11-10 14:34:29 · 104 阅读 · 0 评论 -
Educational Codeforces Round 97 (Rated for Div. 2)------Reverse Binary Strings
题目题意给你一个01字符串,可以对其中的一段进行翻转操作,问使字符串变成01交错的字符串至少需要多少次操作题解翻转字符串不会改变翻转区间内的01关系,只会改变头和尾的关系,交换找到相邻的相同的作为头,然后往后找第一个相邻的相同的且与头不相同的作为尾翻转第一种思想属于暴利,复杂度有点高,会被卡超时,因此介绍第二种思想第二种思想,多出来的连续的0或1的区间长度之和的最大值AC代码...原创 2020-11-07 09:44:17 · 125 阅读 · 0 评论 -
Educational Codeforces Round 97 (Rated for Div. 2)------Marketing Scheme
题目题意给定一个区间【l, r】,找出是否存在一个数a使得区间内所有数x满足x % a >= a / 2题解如果2 * l > r 即满足题意AC代码#include<stdio.h>int main(){ int t; scanf("%d", &t); while(t--){ int l, r; scanf("%d%d", &l, &r); if(2 * l > r)原创 2020-11-07 08:23:04 · 159 阅读 · 0 评论 -
Codeforces Round #681------The Delivery Dilemma
题目Petya is preparing for his birthday. He decided that there would be n different dishes on the dinner table, numbered from 1 to n. Since Petya doesn’t like to cook, he wants to order these dishes in restaurants.Unfortunately, all dishes are prepared in原创 2020-11-04 19:41:49 · 175 阅读 · 0 评论 -
Codeforces Round #681------Saving the City
题目Bertown is a city with n buildings in a straight line.The city’s security service discovered that some buildings were mined. A map was compiled, which is a string of length n, where the i-th character is “1” if there is a mine under the building number原创 2020-11-04 19:15:46 · 173 阅读 · 0 评论 -
Codeforces Round #681------Kids Seating
题目:Today the kindergarten has a new group of n kids who need to be seated at the dinner table. The chairs at the table are numbered from 1 to 4n. Two kids can’t sit on the same chair. It is known that two kids who sit on chairs with numbers a and b (a≠b)原创 2020-11-04 18:58:45 · 231 阅读 · 0 评论 -
Codeforces Round #678 (Div. 2)------Binary Search
题目Andrey thinks he is truly a successful developer, but in reality he didn’t know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number x in an array.原创 2020-10-31 10:25:00 · 226 阅读 · 0 评论 -
Codeforces Round #678 (Div. 2)------Prime Square
题目Sasha likes investigating different math objects, for example, magic squares. But Sasha understands that magic squares have already been studied by hundreds of people, so he sees no sense of studying them further. Instead, he invented his own type of sq原创 2020-10-31 08:50:01 · 227 阅读 · 0 评论 -
Codeforces Round #678 (Div. 2)------Reorder
题目For a given array a consisting of n integers and a given integer m find if it is possible to reorder elements of the array a in such a way thatIt is forbidden to delete elements as well as insert new elements. Please note that no rounding occurs during原创 2020-10-31 08:23:10 · 102 阅读 · 0 评论 -
2020牛客国庆集训派对day2(A,C,D,E,F,G,H,J,)
A、AKU NEGARAKU约瑟夫环裸题AC代码#include<iostream>#include<stdio.h>using namespace std;#define ll long longll yuesefu(ll n, ll m) { if (n == 1) { return 0; } else { return (yuesefu(n - 1, m) + m) % n; }}int mai原创 2020-10-03 10:04:24 · 317 阅读 · 0 评论 -
2020牛客国庆集训派对day1 ------ ABB(马拉车裸题 + 条件判断)
题目Fernando was hired by the University of Waterloo to finish a development project the university started some time ago. Outside the campus, the university wanted to build its representative bungalow street for important foreign visitors and collaborators原创 2020-10-03 09:42:00 · 768 阅读 · 0 评论 -
蓝桥杯算法训练 ------ Two k-Convex Polygons
题目给定n个棍子的长度和整数k,求能否在其中选出2k个棍子拼成两个凸多边形。使得两个凸多边形都恰好有k跟棍子组成,且任意相邻的边都不共线。输入第一行包括两个正整数n,k,表示棍子总数和多边形边数。第二行包括n个正整数,表示每根棍子的长度。输出第一行输出一个单词Yes或者No表示是否能选出满足要求的2k个棍子。如果第一行输出的是Yes,则第二行要输出方案。输入的棍子从1开始按照输入顺序编号,你需要输出2k个空格隔开的正整数,前k个表示组成第一个凸多边形的棍子的编号,后k个表示组成第二个凸多边形棍原创 2020-10-02 10:48:02 · 713 阅读 · 1 评论 -
2019 CCPC 秦皇岛 Gym - 102361F(HDU - 6736 ) ------ Forest Program
题目The kingdom of Z is fighting against desertification these years since there are plenty of deserts in its wide and huge territory. The deserts are too arid to have rainfall or human habitation, and the only creatures that can live inside the deserts are原创 2020-09-26 19:18:56 · 190 阅读 · 0 评论 -
牛客练习赛70 ------ 拼凑
题目:牛牛还是很喜欢字符串"puleyaknoi"。牛牛有T个超长超长的字符串,不过这次他更懒了,他希望直接在字符串中看见他喜欢的字符串。如果一个子串中含有一个子序列是”puleyaknoi“,那么他就把这个子串称作好的子串。牛牛是个懒人,他不喜欢看太长的子串,那样他会觉着眼镜很累。你能帮他求出对于每个字符串,最短的好的子串的长度是多少吗?如果没有,请输出-1输入第一行一个T表示数据组数接下来T行每行一个字符串(保证字符串只含小写字母)输出共T行每行一个答案样例输入3sxpul原创 2020-09-26 09:34:04 · 161 阅读 · 0 评论 -
牛客练习赛70 ------ 重新排列
题目:牛牛有个很喜欢的字符串”puleyaknoi“。牛牛有T个很长很长的字符串,他很喜欢把字符串中的子串(连续的某段)打乱,并且按照自己的喜好重新排列。如果牛牛能把一段重新排列出他喜欢的字符串,他就会把这个子串称作:喜欢的子串。牛牛是个懒人,他不喜欢对太长的子串进行重排,那样他会觉着眼镜很累。你能帮他求出对于每个字符串,最短的喜欢的子串的长度是多少吗?如果没有,请输出-1。输入:第一行一个表示数据组数接下来行每行一个字符串(保证字符串只含小写字母)输出:共T行每行一个答案样例:输原创 2020-09-26 09:28:53 · 194 阅读 · 0 评论 -
Codeforces Round #669 (Div. 2) ------ Big Vova
题目题意给定你一个数组a,你可以对数组a进行重新排序,然后得到新的数组b,对数组b进行gcd,得到数组c,c[i] = gcd(b[1], b[2],b[i]),使得c数组是的字典序最大。求这样的数组b题解看数据范围之后,可以直接暴力。b数组第一个数为a数组中最大的数,后面的数是能使得其gcd最大的数,依次往下就好AC代码#include<iostream>#include<stdio.h>#include<algorithm>#include&l原创 2020-09-12 16:20:55 · 121 阅读 · 0 评论 -
Codeforces Round #669 (Div. 2) ------ Ahahahahahahahaha
题目题意给你一个长度为n的数组,数组元素由0或1构成,你可以进行随意的删除操作,一次只能删除一个元素,最多操作次数不能超过n / 2次。操作后的结果就是:奇数位数字之和等于偶数位数字之和。最后输出剩余的数组元素题解由于题目没有规定说删除次数最少,所以直接找出特殊情况。如果题目里面0的个数大于等于n / 2, 那么直接保留n / 2个0即可,其余的都删除如果题目里面1的个数大于等于n / 2且数目为偶数,那么直接保留所有1即可,其余0删除;如果是奇数,则保留num(1的数目) - 1个1,这样就原创 2020-09-12 10:48:13 · 215 阅读 · 0 评论 -
Codeforces Round #666 (Div. 2) ------ Stoned Game
题目T is playing a game with his friend, HL.There are n piles of stones, the i-th pile initially has ai stones.T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from i原创 2020-09-05 19:27:39 · 853 阅读 · 0 评论 -
Codeforces Round #666 (Div. 2) ------ Power Sequence
题目题意:给定一个长度为n的序列,可以进行两种操作,求使其变为最佳序列的最小花费操作一:排序,此操作没有花费操作二:对任意一个数无限制的进行加一或者减一操作,每次花费为1个单元最佳序列定义:a[i] = c^i,数组下标从0开始,即首项为1的等比数列题解:求出c的范围,暴力枚举即可。根据题目给出的数据范围,可知这个数组的最大和为1e14,然而等比数列的增长是非常快的,因此很快便会打到上界,所以最大公比为pow(1e14, 1.0 / n)AC代码:#include<iostrea原创 2020-09-05 16:29:36 · 159 阅读 · 0 评论 -
Codeforces Round #666 (Div. 2) ------ Multiples of Length
题目You are given an array a of n integers.You want to make all elements of a equal to zero by doing the following operation exactly three times:Select a segment, for each number in this segment we can add a multiple of len to it, where len is the length原创 2020-09-05 15:35:36 · 186 阅读 · 0 评论 -
牛客练习赛68
A、牛牛的mex题解:这题注意看a[i]的数值范围,处理一下前缀和后缀中的最小值即可,不在这个区间中的最小值即min(前缀中的最小值, 后缀中的最小值)AC代码:#include<iostream>#include<stdio.h>#include<algorithm>#include<queue>#include<map>using namespace std;const int N = 1e5 + 15;int a[N]原创 2020-09-05 09:54:22 · 180 阅读 · 0 评论 -
2019 南昌邀请赛(复现,签到题题解)
题一:A Good Game题解:利用前缀和,求出所有区间值,然后操作排序,贪心求解即可知识点:前缀和 + 贪心AC代码:#include<iostream>#include<stdio.h>#include<algorithm>#include<queue>#include<map>#include<string.h>#include<string>using namespace std;con原创 2020-07-08 17:10:26 · 202 阅读 · 0 评论 -
牛客算法周周练13
A、最小生成树小 A 有一张 n 个点的带权无向图,这张无向图非常特别,首先第 i 个点有一个点权 ai,之后这张无向图是一张完全图,且边 (u,v) 的权值为 au+av现在小 A 想找一个这张图的边权之和最小的生成树,需要你来帮帮他题解:每个点都和最小那个点连接形成的树即最小生成树注意:使用长整形AC代码:#include<iostream>#include<algorithm>using namespace std;#define ll long long原创 2020-07-01 19:19:35 · 384 阅读 · 0 评论 -
计算第k个答案-----摩尔斯电码字典(动态规划 + 递归)
题目:摩尔斯电码字典在没有电话的时代,摩尔斯电码是无线电传输领域中的一种常用代码。电码以短信号(短点,o)和长信号(长点,-)的不同组合表示各种文字。例如:o—表示英文字母J,而—表示英文字母M。假设有一本以n个长点和m(n、m<=100)个短点组成的、包含所有信号的字典。例如:n=m=2,就会包含如下信号。–oo-o-o-oo-o–oo-o-oo–这些信号已按照字典顺序排列好了。-的ASKII码是45,而o的ASCII码是111。因此,按照字典顺序,-在前,o在后。给定n和m时,原创 2020-06-29 16:17:38 · 1311 阅读 · 3 评论 -
多重序列
题目:给出n个组,第i组有m个数,分别为a[i][j] ,一组数的权值表示为该组数所有数的乘积,找出权值最大的组,输出权值对mod取模后的值。对于每组数据给出一个k,保证a[i][j]是k的非负整数次幂。输入:第一行4个数n,m,k,mod,意义见题目描述接下来n行,每行m个数,第i行第j个数表示a[i][j];输出:一个数,表示最大的权值对mod取模的结果数据范围:1≤n,m≤2000,1≤k≤100,1≤a[i][j] ,mod≤10^12题解:这是一道刷牛客时候的签到题,就感觉是原创 2020-06-24 16:18:48 · 161 阅读 · 0 评论 -
Codeforces Round #633 (Div. 2)------(Powered Addition)
题目You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second:Select some distinct indices i1,i2,…,ik which are between 1 an...原创 2020-04-27 14:21:14 · 180 阅读 · 0 评论 -
Codeforces Round #633 (Div. 2) ------ Filling Diamonds
题目You have integer n. Calculate how many ways are there to fully cover belt-like area of 4n−2 triangles with diamond shapes.Diamond shape consists of two triangles. You can move, rotate or flip the ...原创 2020-04-27 14:01:26 · 175 阅读 · 1 评论 -
贪心算法的应用---背包问题(easy-x图形化)
运行截图://贪心法求背包问题#include<iostream>#include<algorithm>#include<graphics.h>#include<conio.h>using namespace std;const int maxn = 1e5 + 15;struct node { int p; int w; /...原创 2020-04-27 13:56:36 · 397 阅读 · 0 评论 -
动态规划问题------ 0-1背包(easy-x图形化)
运行截图://动态规划求0-1背包问题#include<iostream>#include<vector>#include<graphics.h>#include<conio.h>using namespace std;struct KNAP{ int w; //weight; int v; //value;};//...原创 2020-04-27 13:54:27 · 176 阅读 · 0 评论 -
分治法的应用------凸包问题(easy-x图形化)
//分治法求凸包问题#include<iostream>#include<vector>#include<algorithm>#include<graphics.h>#include<conio.h>#include<map>using namespace std;const int maxn = 1e5 ...原创 2020-04-27 13:51:51 · 475 阅读 · 4 评论 -
蛮力法的应用------凸包问题(easy-x图形化)
演示截图://蛮力法求凸包问题#include<iostream>#include<vector>#include<algorithm>#include<conio.h>#include<map>#include<graphics.h>using namespace std;const int maxn ...原创 2020-04-27 13:50:16 · 556 阅读 · 0 评论 -
Codeforces Round #633 (Div. 2) ------ Sorted Adjacent Differences
题目:You have array of n numbers a1,a2,…,an.Rearrange these numbers to satisfy |a1−a2|≤|a2−a3|≤…≤|an−1−an|, where |x| denotes absolute value of x. It’s always possible to find such rearrangement.Note...原创 2020-04-27 13:46:27 · 170 阅读 · 0 评论 -
Codeforces Round #628 (Div. 2)------Ehab the Xorcist
题目:Given 2 integers u and v, find the shortest array such that bitwise-xor of its elements is u, and the sum of its elements is v.InputThe only line contains 2 integers u and v (0≤u,v≤1018).Output...原创 2020-03-15 14:30:06 · 185 阅读 · 0 评论 -
Codeforces Round #628 (Div. 2)------Ehab and Path-etic MEXs
题目:You are given a tree consisting of n nodes. You want to write some labels on the tree’s edges such that the following conditions hold:Every label is an integer between 0 and n−2 inclusive.All th...原创 2020-03-15 14:06:43 · 274 阅读 · 0 评论