![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法设计-排序与检索
lab104_yifan
这个作者很懒,什么都没留下…
展开
-
UVA 120 Stacks of Flap jacks
uva 120 Stacks of Flap jacks题意 翻转烧饼 每次翻转是从自选中的烧饼往上到顶部一整叠一起翻转 最终要得到从小到大排列的烧饼解法 把烧饼从大到小每一个都进行一次判断,如果不在该放置的位置,就把这烧饼翻到顶,再翻到底,直到每个烧饼都判断完成。代码:#include using namespace std;#include #include #原创 2013-07-09 08:25:18 · 1322 阅读 · 0 评论 -
UVA 1423 - Guess(拓扑排序)
UVA 1423 - Guess题目链接题意:给定一个每个区间和的正负,构造一个序列,使得满足这个矩阵思路:每个区间和等于两个前缀和的差,这样就可以知道每两个前缀和的大小关系,利用拓扑排序可以求出顺序,然后对应要控制不超过|10|,所以从-10开始,大的就+1,然后构造出这个前缀和序列,对应每个ai就等于c[i] - c[i - 1]代码:#include原创 2014-08-27 16:13:27 · 1463 阅读 · 0 评论 -
uva 12096 - The SetStack Computer(STL)
UVA 12096 - The SetStack Computer题目链接题意:几个操作,push是在栈顶加入一个空集,dup是复制栈顶集合,在放入栈顶,union是把头两个取并集放回,int是头两个取交集放回,add是取头两个,把第一个当成一个集合加入第二个,每次操作输出栈顶集合的里面的个数思路:用set,stack模拟,然后利用map去hash一个集合,模拟即可原创 2014-08-13 21:06:05 · 1157 阅读 · 0 评论 -
UVA 1471 - Defense Lines(扫描+二分)
UVA 1471 - Defense Lines题目链接题意:给定一个序列,要求删去一个连续子序列后,得到的序列有一个最长的连续递增序列,输出最长连续递增序列长度思路:先左右扫描一遍,把每个位置往左和往右的最大长度记录下来,然后在从左往右扫描一遍,开一个数组Min用来记录长度i的序列,最后一位的最小值,这个序列是满足单调性的,因为递增序列肯定是1,2,3,4...这样不断往原创 2014-08-25 14:04:08 · 1957 阅读 · 0 评论 -
UVA 501 - Black Box(优先队列)
UVA 501 - Black Box题目链接题意:给定一些操作,每次add进一个数,然后第i次询问的时候输出当前第i小的数字思路:用两个优先队列搞,相当于把序列分成两个序列,每次取的答案就是后一个队列的头代码:#include #include #include #include using namespace std;const int N原创 2014-08-03 16:22:54 · 1487 阅读 · 0 评论 -
UVA 514 - Rails(模拟)
514 - Rails题目链接题意:一个火车,一开是是有序的1-n车厢,给一个序列,问是否能通过轨道变换成该序列思路:栈模拟即可代码:原创 2014-07-27 01:27:47 · 1164 阅读 · 0 评论 -
UVA 10895 - Matrix Transpose(STL)
UVA 10895 - Matrix Transpose题目链接题意:给定一个矩阵,表示方式为表示非0元素位置和值,求这个矩阵行列交换后的矩阵思路:用两个vector嵌套模拟二维数组,这样只要记录下每个数的位置和值即可代码:原创 2014-07-26 20:23:09 · 791 阅读 · 0 评论 -
UVA 246 - 10-20-30 (模拟+STL)
UVA 246 - 10-20-30题目链接题意:给52张的扑克堆,先从左往右发7张牌,之后连续不断从左往右发7张牌,如果有牌堆形成了以下3种情况(按顺序判断):1、头两张+尾一张和为10或20或302、头一张+尾两张和为10或20或303、尾三张和为10或20或30就把这三张牌拿走,放到总牌堆底(这步要不断执行直到不再满足条件或牌堆没了)如果有一个牌堆因为这个原创 2014-07-27 01:00:20 · 3290 阅读 · 0 评论 -
UVA 1203 - Argus(优先队列)
UVA 1203 - Argus题目链接题意:给定一些注册命令,表示每隔时间t,执行一次编号num的指令,注册命令结束后,给定k,输出前k个执行顺序思路:用优先队列去搞,任务时间作为优先级,每次一个任务出队后,在把它下次执行作为一个新任务入队即可代码:#include #include #include using namespace std;ch原创 2014-07-25 16:23:26 · 1108 阅读 · 0 评论 -
11991 - Easy Problem from Rujia Liu?(基础数据结构)
UVA 11991 - Easy Problem from Rujia Liu?题目链接题意:给一个长度n的序列,有m询问,每个询问会问第k个出现的数字的下标是多少思路:用map和vector搞,map[i][j]直接保存的就是数字i第j个出现,每次直接输出即可代码:#include #include #include #include using原创 2014-07-25 15:35:32 · 933 阅读 · 0 评论 -
UVA 1325 - Hypertransmission(扫描方法)
The president of the Galactic Federation has recently decided that all planets of the galaxy must establish hyper-radio centers to broadcast their programs. To ensure the process, the government has s原创 2014-02-10 08:18:43 · 1793 阅读 · 0 评论 -
10810 - Ultra-QuickSort(归并排序求逆序数)
Problem B: Ultra-QuickSortIn this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of ndistinct integers by swapping two adjacent sequence elements u原创 2014-01-20 19:16:29 · 1523 阅读 · 0 评论 -
UVA 10535 - Shooter(扫描+几何+最大重叠区间)
Problem EShooterInput: Standard InputOutput: Standard OutputTime Limit: 5 Seconds The shooter is in a great problem. He is trapped in a 2D maze with a laser gun and can use it once. The gu原创 2014-01-20 17:11:28 · 1450 阅读 · 0 评论 -
UVA 10755 - Garbage Heap(三维子矩阵最大和)
Garbage HeapTime limit: ? secondsMemory limit: 64 megabytesFarmer John has a heap of garbage formed in a rectangular parallelepiped.It consists of garbage pieces each of which has a value.原创 2014-01-20 14:35:26 · 2655 阅读 · 0 评论 -
11776 - Oh Your Royal Greediness!(最大重叠区间)
Problem FOh Your Royal Greediness!Input: Standard InputOutput: Standard Output Once upon a time there lived a greedy landlord in a not far far away country. The landlord used to employ armed原创 2014-01-12 19:14:36 · 1165 阅读 · 0 评论 -
UVA 1398 - Meteor(排序+扫描方法+几何)
The famous Korean internet company nhn has provided an internet-based photo service which allows The famous Korean internet company users to directly take a photo of an astronomical phenomenon in spac原创 2014-01-19 14:24:32 · 1659 阅读 · 0 评论 -
UVA 11462 - Age Sort(计数排序+输入外挂)
BAge SortInput: Standard InputOutput: Standard Output You are given the ages (in years) of all people of a country with at least 1 year of age. You know that no individ原创 2014-01-18 23:13:15 · 1986 阅读 · 0 评论 -
UVA 400 Unix ls
UVA 400 Unix ls水题一枚。。先进行字典序排序。。然后找出最大长度串,利用这个最大长度求出行列数,然后按题目要求输出即可1A 水过#include using namespace std;#include #include int cmp(const void *a, const void *b){ return (strcmp((c原创 2013-07-20 23:58:48 · 1186 阅读 · 0 评论 -
HDU 5033 Building(北京网络赛B题)
HDU 5033 Building题目链接思路:利用单调栈维护建筑建的斜线,保持斜率单调性,然后可以把查询当成高度为0的建筑,和建筑和在一起考虑,从左往右和从右往左各扫一遍即可代码:#include #include #include #include #include using namespace std;const int N = 200005;原创 2014-09-22 16:00:07 · 1122 阅读 · 0 评论