数据结构
数据结构题目杂集
SoyBean_
这个作者很懒,什么都没留下…
展开
-
大数取模,快速幂取模板子
大数取模模板: while(scanf("%s", num) != EOF) { int len = strlen(num); __int64 ans = 0; for(int i = 0; i < len; ++i) { ans =原创 2017-08-15 10:38:51 · 403 阅读 · 0 评论 -
通过余弦相似度找物品之间的联系
由于毕设用到了推荐算法,这几天在搜索资料,对基于项目的协同过滤算法有了一定的理解,我的理解就是“物以类聚”。通过所有用户对某一商品的评分,来寻找商品之间的相似度。在这里我用的是利用求余弦的方式来判别。程序主要解决了2个问题1、评分中心化:不同的用户打分喜好不同,有的人喜欢打高分,例如喜欢打5分不喜欢打3分,有的人喜欢打低分,例如喜欢打4分不喜欢打1分,这样对数据是有影响的,因此需要平分中心化。除此之外对于一个用户他没有评价的商品,默认为0,这个0有着极大的不喜欢的意义,这对于数据的分析也有影响,我们.原创 2020-05-15 11:04:37 · 1298 阅读 · 0 评论 -
Satisfactory Pairs
Given a positive integer, , find and print the number of pairs of positive integers , where , that exist such that the equation (where and are positive integers) has at least one solution.Input Fo原创 2017-06-25 18:46:07 · 301 阅读 · 1 评论 -
CodeForces 214B
yxc loves math lessons very much, so he doesn't attend them, unlike wwl. But now yxc wants to get a good mark for math. For that Ms. lxh, his ACM teacher, gave him a new task. yxc solved the task imme原创 2017-06-20 22:16:37 · 220 阅读 · 0 评论 -
CF—Hot Bath
Bob is about to take a hot bath.There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2. The cold water原创 2017-06-07 17:26:50 · 440 阅读 · 0 评论 -
New Year Table
Gerald is setting the New Year table. The table has the form of a circle; its radius equals R. Gerald invited many guests and is concerned whether the table has enough space for plates for all those g原创 2017-06-06 22:50:59 · 218 阅读 · 0 评论 -
Can you answer these queries?
A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use our secret weapon to eliminate the battleships. Each of the battleships can be marked a value of end原创 2017-08-24 21:16:00 · 309 阅读 · 0 评论 -
Just a Hook ---线段树区间更新
In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length.原创 2017-08-21 20:54:05 · 216 阅读 · 0 评论 -
A Simple Problem with Integers POJ - 3468--------线段树的区间更新解析及例题
传送门: http://poj.org/problem?id=3468思路:典型的线段树区间更新(线段树效率快的精华就是区间更新)lazy思想:比如现在需要对[a,b]区间值进行加c操作,那么就从根节点[1,n]开始调用update函数进行操作,如果刚好执行到一个子节点,它的节点标记为root:如果tree[root].l== a && tree[root].r == b原创 2017-08-19 21:21:50 · 226 阅读 · 0 评论 -
I Hate It HDU - 1754 -----线段树查找区间最大值
很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。这让很多学生很反感。不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。 Input本题目包含多组测试,请处理到文件结束。在每个测试的第一行,有两个正整数 N 和 M ( 0学生ID编号分别从1编到N。第二行包含N个原创 2017-08-19 09:41:08 · 232 阅读 · 0 评论 -
敌兵布阵 HDU - 1166 ----------线段树
C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所原创 2017-08-19 08:50:17 · 221 阅读 · 0 评论 -
Count the Colors -----超详细的线段树的区间染色题解(线段树原来操作可以这么骚Q&_&Q)
Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones.Your task is counting the segments of different colors you can see at last.原创 2017-08-23 20:45:23 · 652 阅读 · 0 评论 -
A Bug's Life-----分类并查集
DescriptionBackgroundProfessor 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 of the原创 2017-08-16 20:56:58 · 511 阅读 · 0 评论 -
Supermarket POJ - 1456------贪心加并查集
A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of time units starting from the moment the s原创 2017-08-16 20:04:08 · 191 阅读 · 0 评论 -
食物链------种类并查集
原题传送门 :http://poj.org/problem?id=1182推荐blog传送门,超级详细:http://blog.csdn.net/c0de4fun/article/details/7318642/这种题,渣渣我是刚不了的……,百度了一堆帖子,说实话谈到关键代码的真的不是很多,也确实有好的帖子,让我收获了不少。做题思路:种类并查集,首先利用一个数组a来确定并查集关系,原创 2017-08-16 16:35:40 · 331 阅读 · 0 评论 -
How Many Answers Are Wrong--HDU3038--------带权并查集
TT and FF are ... friends. Uh... very very good friends -________-bFF is a bad boy, he is always wooing TT to play the following game with him. This is a very humdrum game. To begin with, TT shoul原创 2017-08-15 09:46:04 · 194 阅读 · 0 评论 -
The Suspects POJ - 1611 ---并查集
Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to s原创 2017-08-14 19:43:01 · 190 阅读 · 0 评论 -
Wireless Network POJ - 2236------并查集
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the n原创 2017-08-14 10:58:58 · 222 阅读 · 0 评论 -
Treats for the Cows---区间dp--逆序推
DescriptionFJ has purchased N (1 The treats are interesting for many reasons:The treats are numbered 1..N and stored sequentially in single file in a long box that is open at both ends. On a原创 2017-08-09 21:30:10 · 177 阅读 · 0 评论 -
Max Sum Plus Plus HDU - 1024
Problem DescriptionNow I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more diff原创 2017-08-09 15:54:34 · 179 阅读 · 0 评论 -
FatMouse's Speed HDU - 1160 --dp的路径记忆问题
FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence原创 2017-08-09 09:48:24 · 291 阅读 · 0 评论 -
Piggy-Bank HDU - 1114 ---完全背包模板
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1114完全背包,每个物品都有无限个,可以进行多次的取用#include #include #include #include #include #define inf 999999using namespace std;int main (){ int pi[12000原创 2017-08-07 21:08:42 · 240 阅读 · 0 评论 -
Monkey and Banana HDU - 1069------DP
A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monk原创 2017-08-07 09:48:37 · 203 阅读 · 0 评论 -
Salty Fish---DP的变形
海边躺着一排咸鱼,一些有梦想的咸鱼成功翻身(然而没有什么卵用),一些则是继续当咸鱼。一个善良的渔夫想要帮这些咸鱼翻身,但是渔夫比较懒,所以只会从某只咸鱼开始,往一个方向,一只只咸鱼翻过去,翻转若干只后就转身离去,深藏功与名。更准确地说,渔夫会选择一个区间[L,R],改变区间内所有咸鱼的状态,至少翻转一只咸鱼。渔夫离开后想知道如果他采取最优策略,最多有多少只咸鱼成功翻身,但是咸鱼大概有十万条原创 2017-07-24 21:23:48 · 265 阅读 · 0 评论 -
小明の魔法计划(最长倍数子序列)
Problem Description在一个遥远的数学魔法国度,小明在学习一个魔法,这个魔法需要一些施法材料,所幸的是施法材料已经准备好了,下一步就是建立魔法阵了,每一个施法材料都有一个特性值,表示为一个大于1小于10 ^ 7的整数,当且仅当一个材料的特性值是另一个材料的特性值的倍数的时候,他们才可以建立法力连接。比如说,一个特性值为6和一个特性值为9的施法材料是不可以建立法力连接的,而一原创 2017-07-24 21:07:20 · 936 阅读 · 0 评论 -
Virus (最长上升公共子序列)
We have a log le, which is a sequence of recorded events. Naturally, the timestamps are strictlyincreasing.However, it is infected by a virus, so random records are inserted (but the order of orig原创 2017-06-10 21:44:16 · 347 阅读 · 2 评论 -
免费馅饼
免费馅饼Time Limit: 1000MS Memory Limit: 32768KBSubmit StatisticProblem Description都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼。说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内。馅饼如果掉在了地上当然就不能吃了,所以ga原创 2017-04-26 21:51:54 · 209 阅读 · 0 评论 -
最长公共子序列问题·
最长公共子序列问题Time Limit: 1000MS Memory Limit: 65536KBSubmit StatisticProblem Description给定两个序列X=Input输入数据有多组,每组有两行 ,每行为一个长度不超过500的字符串(输入全是大写英文字母(A,Z)),表示序列X和Y。Output每组输出一行,表示所求得的最长公共原创 2017-04-25 16:59:23 · 322 阅读 · 0 评论 -
Candies POJ--3159 -------邻接表存图(OJ卡队列与vector数组)
传送门:http://poj.org/problem?id=3159这道题很不友好!!!卡掉了queue,卡掉了vector,这么卡题,像我一样的弱儿怎么办啊!!!!!!!!于是,乖乖的百度---“图的邻接表存储方式”,啊啊啊,本以为vector 可以用到死的啊!!!分割线-------------------------------------------------------原创 2017-08-04 20:49:03 · 281 阅读 · 0 评论 -
昂贵的聘礼 POJ - 1062 ----对区间进行枚举的Dijst算法
昂贵的聘礼Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 50284 Accepted: 15061Description年轻的探险家来到了一个印第安部落里。在那里他和酋长的女儿相爱了,于是便向酋长去求亲。酋长要他用10000个金币作为聘礼才答应把女儿嫁给他。探险家拿不出这么多金币,便请求酋长降低要求。酋长说:原创 2017-08-04 09:26:44 · 221 阅读 · 0 评论 -
F - Wormholes POJ - 3259--SPFA 算法判断负环是否存在
While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that i原创 2017-08-02 15:58:11 · 268 阅读 · 0 评论 -
Heavy Transportation POJ - 1797 --- 最短路思维的最大承载量(最大生成树)
BackgroundHugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his cus原创 2017-08-01 21:35:28 · 268 阅读 · 0 评论 -
DFS输出全排列
emmmm。。。之前的遗留问题,今天又翻了出来。。。记得课本上这道题是 递归的例题。。。。递归文化博大精深,没看懂………………现用dfs解一遍此题题目链接 :acm.sdut.edu.cn problem题号搜4165代码如下:#include <iostream>#include<algorithm>#include <queue>#include &l...原创 2018-03-11 15:26:48 · 500 阅读 · 0 评论 -
Oil Deposits HDU - 1241 ---DFS
The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides th原创 2017-07-29 21:13:21 · 214 阅读 · 0 评论 -
H - A计划 HDU - 2102----普通BFS注意坑点
可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验。魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老。年迈的国王正是心急如焚,告招天下勇士来拯救公主。不过公主早已习以为常,她深信智勇的骑士LJ肯定能将她救出。现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输机用#表示,墙用*表示原创 2017-07-26 10:44:33 · 243 阅读 · 0 评论 -
Grandpa's Walk UVALive - 6038 -DFS
题目链接如下https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4049对图进行深度遍历,数条数就好了#include #include #include#includeusing namespace std;int原创 2017-07-25 19:47:25 · 246 阅读 · 0 评论 -
POJ---- Pots ----BFS的路径回溯问题
You are given two pots, having the volume of A and B liters respectively. The following operations can be performed:FILL(i) fill the pot i (1 ≤ i ≤ 2) from the tap;DROP(i) empty the po原创 2017-07-23 09:53:59 · 371 阅读 · 0 评论 -
HDU 1495 非常可乐
大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为。因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享这一瓶可乐,而且一定要喝的和seeyou一样多。但seeyou的手中只有两个杯子,它们的容量分别是N 毫升和M 毫升 可乐的体积为S (S<101)毫升 (正好装满一瓶) ,它们三个之间可以相互倒可乐 (都是没有刻度的,且 S==N+M,101>S>0,N原创 2017-07-22 10:29:48 · 247 阅读 · 0 评论 -
数据结构实验之图论四:迷宫探索
有一个地下迷宫,它的通道都是直的,而通道所有交叉点(包括通道的端点)上都有一盏灯和一个开关;请问如何从某个起点开始在迷宫中点亮所有的灯并回到起点? Input连续T组数据输入,每组数据第一行给出三个正整数,分别表示地下迷宫的结点数N(1 Output若可以点亮所有结点的灯,则输出从S开始并以S结束的序列,序列中相邻的顶点一定有边,否则只输出部分点亮的灯的结点序列,最后输原创 2017-06-12 17:14:55 · 319 阅读 · 0 评论 -
Fire Game
Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just empty and then they start原创 2017-06-10 21:14:14 · 208 阅读 · 0 评论