算法
文章平均质量分 82
双木林233
啦啦啦啦啦啦啦啦
展开
-
1296C Yet Another Walking Robot (Codeforces)(map)
Yet Another Walking Robot 题目链接题意:输入一段路径,输出最短的重复段。思路:每走一步将到达的点存入map,进行判重,并保存最小值;#include<iostream>#include<map>using namespace std;struct node{ int x,y; friend bool opera...原创 2020-02-07 17:15:28 · 206 阅读 · 0 评论 -
算法协会19级STL训练赛题解
Let the Balloon Rise HDU - 1004不重复数字 HYSBZ - 2761{A} + {B} HDU - 1412Ignatius and the Princess IV HDU - 1029(map)Andy's First Dictionary UVA - 10815原创 2019-12-15 15:53:35 · 223 阅读 · 0 评论 -
Andy's First Dictionary UVA - 10815
Andy's First Dictionary题目链接这道题的要求将所有出现的单词按照顺序输出,完全符合set去重并且自动排序的功能,我们就可以选择用set进行代码实现。在进行样例测试的时候可能会有问题,回车总是代表一个字符串的结束标记符,在这里我们要进行多组输入,所以我们在输入未知的多组字符串后要结束多组输入,及使该输入达到end of file时结束多组输入,Crtl+z即代表EO...原创 2019-12-15 15:50:06 · 275 阅读 · 0 评论 -
Ignatius and the Princess IV HDU - 1029(map)
Ignatius and the Princess IV题目链接这道题给出的测试样例都一定存在一个special integer。我们可以利用数组进行存储及遍历,也可以用map进行存储。#include<iostream>#include<map>using namespace std;map<int,int>ma;int main...原创 2019-12-15 15:30:03 · 175 阅读 · 0 评论 -
{A} + {B} HDU - 1412
题目链接题意要求是去重,并且输出顺序是从小到大,所以完全符合set自动去重和排序的特点。#include<iostream>#include<algorithm>#include<set>using namespace std;int n,m;int main(){ while(cin>>n>>m){ s...原创 2019-11-29 20:43:21 · 149 阅读 · 0 评论 -
不重复数字 HYSBZ - 2761
题目链接题意要求就是去重,并且输出顺序不改变,只保留第一次出现的元素。set和map都可实现(map内部会自动排序,所以需要边存入map,判断是否是第二个及以上出现的元素,随即输出)/*set*/#include<iostream>#include<algorithm>#include<set>using namespace std;...原创 2019-11-29 20:35:24 · 203 阅读 · 0 评论 -
Let the Balloon Rise HDU - 1004
题目链接map经典水题。#include<iostream>#include<map>using namespace std;#define ll long longconst int MAXN=200010;map<string,int> ma;int main(){ int n; while(cin>>n&&...原创 2019-11-29 20:27:40 · 151 阅读 · 0 评论 -
Valeriy and Deque CodeForces - 1180C(deque)
Valeriy and DequeRecently, on the course of algorithms and data structures, Valeriy learned how to use a deque. He built a deque filled with nn elements. The ii -th element is aiai (ii = 1,2,…,n1,2,...原创 2019-11-28 20:10:27 · 251 阅读 · 0 评论 -
Pairs CodeForces - 1169B
PairsToad Ivan has mm pairs of integers, each integer is between 11 and nn , inclusive. The pairs are (a1,b1),(a2,b2),…,(am,bm)(a1,b1),(a2,b2),…,(am,bm) .He asks you to check if there exist two in...原创 2019-11-25 21:59:31 · 310 阅读 · 0 评论 -
Circle Metro CodeForces - 1169A
Circle MetroThe circle line of the Roflanpolis subway has nn stations.There are two parallel routes in the subway. The first one visits stations in order 1→2→…→n→1→2→…1→2→…→n→1→2→… (so the next st...原创 2019-11-25 20:52:46 · 229 阅读 · 0 评论 -
Nick and Array CodeForces - 1180B
Nick and ArrayNick had received an awesome array of integers a=[a1,a2,…,an]a=[a1,a2,…,an] as a gift for his 55 birthday from his mother. He was already going to explore its various properties but af...原创 2019-11-25 20:17:03 · 195 阅读 · 0 评论 -
Engines AtCoder - 4900
EnginesProblem StatementE869120 is initially standing at the origin (0,0) in a two-dimensional plane.He has N engines, which can be used as follows:When E869120 uses the i-th engine, his X-...原创 2019-11-24 15:38:22 · 283 阅读 · 0 评论 -
Shortest Path on a Line AtCoder - 5635
Shortest Path on a LineProblem StatementWe have N points numbered 1 to N arranged in a line in this order.Takahashi decides to make an undirected graph, using these points as the vertices. In...原创 2019-11-23 17:35:34 · 209 阅读 · 0 评论 -
Engines AtCoder - 4900
EnginesProblem StatementE869120 is initially standing at the origin (0,0) in a two-dimensional plane.He has N engines, which can be used as follows:When E869120 uses the i-th engine, his X-...原创 2020-05-08 11:40:42 · 142 阅读 · 0 评论 -
Counting of Trees AtCoder - 5633
Counting of TreesProblem StatementGiven is an integer sequence D1,…,DN of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following cond...原创 2019-11-21 21:18:14 · 232 阅读 · 0 评论 -
AB Substrings AtCoder - 5039
AB SubstringsProblem StatementSnuke has N strings. The i-th string is si.Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number ...原创 2019-11-18 21:08:08 · 161 阅读 · 0 评论 -
Kleene Inversion AtCoder - 5165
Kleene InversionProblem StatementWe have a sequence of N integers A~=~A0,~A1,~…,~AN−1.Let B be a sequence of K×N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 ...原创 2019-11-18 21:00:02 · 327 阅读 · 2 评论 -
Lower AtCoder - 4871
LowerProblem StatementThere are N squares arranged in a row from left to right.The height of the i-th square from the left is Hi.You will land on a square of your choice, then repeat moving...原创 2019-11-18 20:49:47 · 129 阅读 · 0 评论 -
Powerful Discount Tickets AtCoder - 4864
Powerful Discount TicketsProblem StatementTakahashi is going to buy N items one by one.The price of the i-th item he buys is Ai yen (the currency of Japan).He has M discount tickets, and he...原创 2019-11-18 20:33:13 · 243 阅读 · 0 评论 -
Monsters Battle Royale AtCoder - 4297
Monsters Battle RoyaleProblem StatementThere are N monsters, numbered 1,2,…,N.Initially, the health of Monster i is Ai.Below, a monster with at least 1 health is called alive.Until there ...原创 2019-11-18 20:08:11 · 259 阅读 · 0 评论 -
ModSum(思维)
ModSumProblem StatementFor an integer N, we will choose a permutation {P1,P2,…,PN} of {1,2,…,N}.Then, for each i=1,2,…,N, let Mi be the remainder when i is divided by Pi.Find the maximum po...原创 2019-11-18 19:36:22 · 356 阅读 · 0 评论 -
一周补题集
以下是每道题的链接:ModSum(思维)Monsters Battle RoyalePowerful Discount TicketsLowerKleene InversionAB Substrings Counting of TreesShortest Path on a LineEngines原创 2019-11-16 15:19:28 · 100 阅读 · 0 评论 -
RGB Substring (easy version)
RGB Substring (easy version)The only difference between easy and hard versions is the size of the input.You are given a string ss consisting of nn characters, each character is 'R', 'G' or 'B'.Y...原创 2019-11-16 15:09:39 · 307 阅读 · 0 评论 -
Cotree
CotreeAvin has two trees which are not connected. He asks you to add an edge between them to make them connected while minimizing the function ∑ni=1∑nj=i+1dis(i,j)∑i=1n∑j=i+1ndis(i,j), where dis(i,j...原创 2019-11-13 21:42:47 · 238 阅读 · 0 评论 -
Rng (规律+逆元+概率)
RngAvin is studying how to synthesize data. Given an integer n, he constructs an interval using the following method: he first generates a integer r between 1 and n (both inclusive) uniform-randomly...原创 2019-11-11 21:45:10 · 603 阅读 · 0 评论 -
Wave (dp/暴力)
WaveAvin is studying series. A series is called "wave" if the following conditions are satisfied:1) It contains at least two elements;2) All elements at odd positions are the same;3) All elements...原创 2019-11-10 20:10:09 · 264 阅读 · 0 评论 -
Worker (二分)
WorkerAvin meets a rich customer today. He will earn 1 million dollars if he can solve a hard problem. There are n warehouses and m workers. Any worker in the i-th warehouse can handle ai orders per...原创 2019-11-10 18:40:29 · 508 阅读 · 0 评论 -
Traffic(暴力模拟)
TrafficAvin is observing the cars at a crossroads. He finds that there are n cars running in the east-west direction with the i-th car passing the intersection at time ai . There are another m cars ...原创 2019-11-10 18:28:51 · 751 阅读 · 0 评论 -
Budget (思维)
BudgetAvin’s company has many ongoing projects with different budgets. His company records the budgets using numbers rounded to 3 digits after the decimal place. However, the company is updating the...原创 2019-11-10 17:50:47 · 565 阅读 · 0 评论 -
Fixing Banners(DFS)
Fixing BannersHarbin, whose name was originally a Manchu word meaning "a place for drying fishing nets", grew from a small rural settlement on the Songhua River to become one of the largest citi...原创 2019-11-03 10:57:11 · 723 阅读 · 1 评论 -
数据结构实验四 串基本操作的实现
实验目的:1.掌握串的模式匹配操作。实验要求:1.分别使用BF和KMP算法完成串的模式匹配。实验过程:1.设计完成next值的计算函数;2.设计完成修正next值的函数;3.KMP算法代码;4.输入子串(abbc)和主串(abbabbcad)5.输出子串在主串中开始的位置。实验结果:输入:子串:abbc 主串:abbabbcad输出:4实验分析...原创 2019-10-10 11:27:26 · 1196 阅读 · 0 评论 -
A Bug's Life (二分图 并查集)
A Bug's Life 二分图 并查集BackgroundProfessor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs...原创 2019-09-24 15:28:36 · 190 阅读 · 0 评论 -
洛谷P1162 填涂颜色(dfs)
填涂颜色题目链接(洛谷)这道题我的思路是从边缘的0进行dfs并进行标记,这样回路中的0肯定无法被标记,wa了一回,因为只标记了一个边缘的0,边缘的0不一定是相通的。#include<iostream>#include<string.h> using namespace std; int vis[32][32];char map[32][32];int d[2...原创 2019-09-21 15:45:41 · 227 阅读 · 0 评论 -
记忆化搜索
1、记忆化搜索的思想记忆化搜索的思想是,在搜索过程中,会有很多重复计算,如果我们能记录一些状态的答案,就可以减少重复搜索量2、记忆化搜索的适用范围根据记忆化搜索的思想,它是解决重复计算,而不是重复生成,也就是说,这些搜索必须是在搜索扩展路径的过程中分步计算的题目,也就是“搜索答案与路径相关”的题目,而不能是搜索一个路径之后才能进行计算的题目,必须要分步计算,并且搜索过程中,一个搜索结果必须可...转载 2019-07-30 11:17:57 · 80 阅读 · 0 评论