STL
文章平均质量分 67
h1021456873
这个作者很懒,什么都没留下…
展开
-
HDU Train Problem I (STL_栈)
Problem DescriptionAs the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is原创 2015-08-15 12:52:04 · 647 阅读 · 0 评论 -
51nod 1191 消灭兔子 (贪心+优先队列)
有N只兔子,每只有一个血量B[i],需要用箭杀死免子。有M种不同类型的箭可以选择,每种箭对兔子的伤害值分别为D[i],价格为P[i](1 特别说明:1、当箭的伤害值大于等于兔子的血量时,能将兔子杀死;2、血量B[i],箭的伤害值D[i],箭的价格P[i],均小于等于100000。Input第1行:两个整数N,M,中间用空格分隔(1 <= N, M <= 5000原创 2015-11-14 12:52:06 · 813 阅读 · 0 评论 -
51nod 1001 数组中和等于K的数对
给出一个整数K和一个无序数组A,A的元素为N个互不相同的整数,找出数组A中所有和等于K的数对。例如K = 8,数组A:{-1,6,5,3,4,2,9,0,8},所有和等于8的数对包括(-1,9),(0,8),(2,6),(3,5)。Input第1行:用空格隔开的2个数,K N,N为A数组的长度。(2 <= N <= 50000,-10^9 <= K <= 10^原创 2015-10-15 00:41:23 · 465 阅读 · 0 评论 -
51nod 1163 最高的奖励 (贪心+STL)
有N个任务,每个任务有一个最晚结束时间以及一个对应的奖励。在结束时间之前完成该任务,就可以获得对应的奖励。完成每一个任务所需的时间都是1个单位时间。有时候完成所有任务是不可能的,因为时间上可能会有冲突,这需要你来取舍。求能够获得的最高奖励。Input第1行:一个数N,表示任务的数量(2 <= N <= 50000)第2 - N + 1行,每行2个数,中间用空格分隔,表原创 2015-10-29 21:02:02 · 826 阅读 · 0 评论 -
51nod 1095 Anigram单词 (map——multiset结合)
一个单词a如果通过交换单词中字母的顺序可以得到另外的单词b,那么定义b是a的Anigram,例如单词army和mary互为Anigram。现在给定一个字典,输入Q个单词,从给出的字典中找出这些单词的Anigram。Input第1行:1个数N,表示字典中单词的数量。(1 <= N <= 10000)第2 - N + 1行,字典中的单词,单词长度 <= 10。第N原创 2015-10-30 15:59:29 · 512 阅读 · 0 评论 -
51nod 活动安排问题之二 (贪心+stl)
有若干个活动,第i个开始时间和结束时间是[Si,fi),活动之间不能交叠,要把活动都安排完,至少需要几个教室?分析:能否按照之一问题的解法,每个教室安排尽可能多的活动,即按结束时间排序,再贪心选择不冲突的活动,安排一个教室之后,剩余的活动再分配一个教室,继续贪心选择……反例: A:[1,2) B:[1,4) C:[5,6) D:[3,7)已经按结束时间排好顺序,我原创 2015-10-13 12:27:34 · 1124 阅读 · 1 评论 -
1040 最大公约数之和 (STL)
给出一个n,求1-n这n个数,同n的最大公约数的和。比如:n = 61,2,3,4,5,6 同6的最大公约数分别为1,2,3,2,1,6,加在一起 = 15Input1个数N(N Output公约数之和Input示例6Output示例15#includeusing namespace std;vect原创 2015-10-31 17:19:33 · 671 阅读 · 0 评论 -
51nod 1294 修改数组 (LIS变形_DP)
Input第1行:一个数N表示序列的长度(1 <= N <= 100000)。第2 - N + 1行:每行1个数,对应数组元素。(0 Output输出最少需要修改几个数使得整个数组是严格递增的。Input示例512234Output示例3求LIS是用lower_bound(),而非严格递增用upper_bound()原创 2015-11-17 23:17:08 · 609 阅读 · 0 评论 -
cf#333 (Div. 2) 区间最大最小值(RMQ || STL_set)
题目大意:n个数的序列,问最长的区间,区间内最大的数和最小的数差小于等于1Sample test(s)input51 2 3 3 2output4input115 4 5 5 6 7 8 8 8 7 6output5#include#include#include#inc原创 2015-11-27 17:18:26 · 444 阅读 · 0 评论 -
HDU 1075 翻译 (字典树||map)
Problem DescriptionIgnatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it lea原创 2016-01-17 18:01:58 · 308 阅读 · 0 评论 -
HDU 1027 全排列 (STL_permution)
题意:求1-n的按升序规则的第M个排列,如1243是N=4的第2个排列,1324是第3个,即第M小序列Sample Input6 411 8 Sample Output1 2 3 5 6 41 2 3 4 5 6 7 9 8 11 10#include#include#include#includeusing原创 2015-12-03 21:31:36 · 400 阅读 · 0 评论 -
HDU 1412 参加聚会 (map+树形dp)
题目大意:n个人形成一个关系树,每个节点代表一个人,节点的根表示这个人的唯一的直接上司,只有根没有上司。要求选取一部分人出来,使得每2个人之间不能有直接的上下级的关系,求最多能选多少个人出来,并且求出获得最大人数的选人方案是否唯一。前半部分很容易求得,直接一个树形DP,后面的判断最优解是否唯一比较难搞。。看了roba的ppt顿时恍然大悟。 §原创 2016-03-01 12:33:51 · 373 阅读 · 1 评论 -
Solve equation
DescriptionYou're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (原创 2016-03-27 14:54:18 · 392 阅读 · 0 评论 -
PAT 1063. Set Similarity (STL||集合交,并)
Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*100%, where Nc is the number of distinct common numbers shared by the two sets, and Nt is the total number of distinct num原创 2016-12-03 10:48:16 · 296 阅读 · 0 评论 -
codeforces 721D D. Maxim and Array (STL||优先队列)
Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he invented positive integerx and decided to add or subtract it from arbitrary arr原创 2016-11-27 14:58:25 · 304 阅读 · 0 评论 -
codeforce 749 D. Leaving Auction 拍卖 (set+二分) 思维题!!!
题目大意(源自CF群):有n每一次出价都是一个整数对(a[i],b[i])(a[i]有q每一个询问包含一个整数k以及k个人的编号l[j],保证k的总和不会超过2e5问如果这些人不出现的话,谁会获得这件商品?对于每一个询问,输出两个整数,胜出者的编号以及胜出者出的价格,如果没有人胜出,输出两个0.思路:用set >pos维护竞价人的下标和最大值,把最大值作为p原创 2017-02-08 12:17:24 · 445 阅读 · 0 评论 -
51nod 1117 聪明的木匠 (优先队列_STL)
一位老木匠需要将一根长的木棒切成N段。每段的长度分别为L1,L2,......,LN(1 木匠发现,每一次切割花费的体力与该木棒的长度成正比,不妨设切割长度为1的木棒花费1单位体力。例如:若N=3,L1 = 3,L2 = 4,L3 = 5,则木棒原长为12,木匠可以有多种切法,如:先将12切成3+9.,花费12体力,再将9切成4+5,花费9体力,一共花费21体力;还可以先将12切成4+8,花费原创 2015-10-26 23:51:11 · 864 阅读 · 0 评论 -
zufe 1931: 菜贩xiaoshua (set+map模拟题,好题)
Description 土老板种了很多菜,准备拿到市场上卖. 据土老板讲,现在卖菜比当程序员赚多了….. 于是xiaoshua又自告奋勇地去当起了菜贩. As we all know,土老板是个财大气粗的主儿, 他给xiaoshua分配了一个摊位,而这个摊位很特别, 呈直线型,且长度很长很长很长… 为了简化问题,我们可以把它理解成是无穷个大小相等的格子从左原创 2015-10-26 15:26:46 · 385 阅读 · 0 评论 -
Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) A. Bear and Elections(优先队列)
Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.There are n candidates, including Limak. We know how many citizens are goi原创 2015-08-30 12:10:35 · 824 阅读 · 1 评论 -
Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) B. Bear and Three Musketeers(STL_暴力)
Do you know a story about the three musketeers? Anyway, you will learn about its origins now.Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He nee原创 2015-08-31 16:24:16 · 696 阅读 · 1 评论 -
UVa 11572 - Unique Snowflakes (滑动窗口STL_map||set) 好题!!!
题目大意:给n个数, nset容器的新技能get√#include#include#include#include#includeusing namespace std;const int maxn=1e6+100;int a[maxn];int main(){ int t,n,i,j; setset; cin>>t; while(t-原创 2015-09-01 19:21:32 · 894 阅读 · 1 评论 -
UVa 传说中的车(白书P11134_放棋子+set)
题意: 给你一个n*n的棋盘,让你在棋盘上放n个棋子,要求是所有棋子不能相互攻击(同行或者同列就会攻击),并且每个棋子都有一个限制,那就是必须在给定的矩形r[i]里,输出每个棋子的位置,special Jude。思路: 看完后第一反应就是匈牙利(哎!惭愧啊。)结果想着怎么建图,想了一会呵呵了,果断想别的方法,其实这个题目设计到一个小思想非常好,那就是把整体分原创 2015-09-03 16:12:43 · 538 阅读 · 1 评论 -
POJ 2823 Sliding Window(滑动窗口问题__优先队列||单调队列)
DescriptionAn array of size n ≤ 106 is given to you. There is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the wi原创 2015-09-03 00:04:53 · 776 阅读 · 1 评论 -
UVa 10954 Add All (石子合并_优先队列)
#include#include#include#includeusing namespace std;priority_queue,greater >qq;int main(){ int sum,i,j,num,n,ans; while(cin>>n && n) { for(i=0;i<n;i++) { cin>>num; qq.push(num); }原创 2015-09-04 19:50:03 · 580 阅读 · 1 评论 -
POJ 3320 Jessica's Reading Problem (尺取法_滑动窗口,阅读最少页数)
DescriptionJessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is coming, yet she has spent little time on it. If she wants to pass it, she has to master原创 2015-09-26 10:31:25 · 577 阅读 · 1 评论 -
POJ 3253 Fence Repair (割木头,贪心_优先队列)
DescriptionFarmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each having some integer len原创 2015-09-14 17:07:25 · 419 阅读 · 1 评论 -
POJ 2431 Expedition (汽车加油问题,STL_优先队列+贪心) (挑战程序P76)
DescriptionA group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rather poor drivers, the cows unfortunately managed to run over a rock and puncture the truck's原创 2015-09-15 21:11:03 · 725 阅读 · 1 评论 -
51nod 1289 大鱼吃小鱼 (栈_STL)
有N条鱼每条鱼的位置及大小均不同,他们沿着X轴游动,有的向左,有的向右。游动的速度是一样的,两条鱼相遇大鱼会吃掉小鱼。从左到右给出每条鱼的大小和游动的方向(0表示向左,1表示向右)。问足够长的时间之后,能剩下多少条鱼?Input第1行:1个数N,表示鱼的数量(1 <= N <= 100000)。第2 - N + 1行:每行两个数A[i], B[i],中间用空格分隔,分原创 2015-10-19 19:48:10 · 593 阅读 · 0 评论 -
51nod 1024 矩阵中不重复的元素 (STL)
一个m*n的矩阵。该矩阵的第一列是a^b,(a+1)^b,.....(a + n - 1)^b第二列是a^(b+1),(a+1)^(b+1),.....(a + n - 1)^(b+1).......第m列是a^(b + m - 1),(a+1)^(b + m - 1),.....(a + n - 1)^(b + m - 1)(a^b表示a的b次方)下面是一原创 2015-11-04 22:19:28 · 810 阅读 · 0 评论 -
51nod 1384 全排列 (回溯||STL)
给出一个字符串S(可能又重复的字符),按照字典序从小到大,输出S包括的字符组成的所有排列。例如:S = "1312",输出为:112311321213123113121321211321312311311231213211Input输入一个字符串S(S的长度 Output输出S所包含的字符组成的所有原创 2015-10-20 14:17:45 · 930 阅读 · 0 评论 -
cf B. Finding Team Member (STL_优先队列)
There is a programing contest named SnakeUp, 2n people want to compete for it. In order to attend this contest, people need to form teams of exactly two people. You are given the strength of each po原创 2015-09-18 17:46:30 · 636 阅读 · 1 评论 -
51nod 1094 和为k的连续区间 (暴力||map数组优化)
一整数数列a1, a2, ... , an(有正有负),以及另一个整数k,求一个区间[i, j],(1 <= i <= j <= n),使得a[i] + ... + a[j] = k。Input第1行:2个数N,K。N为数列的长度。K为需要求的和。(2 <= N <= 10000,-10^9 <= K <= 10^9)第2 - N + 1行:A[i](-10^9原创 2015-10-25 16:28:51 · 573 阅读 · 0 评论 -
zufe 1926: sailspark的奇怪癖好 (set的使用,好题 STL)
Description Sail有一个奇怪的癖好,喜欢养奇怪的宠物,虽然在省长要来检查,学校严明禁止养宠物,但他还是孜孜不倦的在自己的衣柜里养了一种很神奇的宠物,就暂时叫它spark吧。 Spark算是一种物种,里面包含着很多个种类,sail想对不同种类的spark进行混养,来了解在混养的时候,spark是否会发生什么变异等。 Spark是一种很原创 2015-10-26 00:19:15 · 423 阅读 · 0 评论 -
codeforce 754 D k个区间的交的尽可能的大 (优先队列) 贪心好题!!!
题意:给定n个区间,现在让你从这n个区间里面选k个区间,使得这k个区间的交的尽可能的大。先给区间按 左端点排序思路:枚举左端点,用优先队列维护右端点,然后动态的更新答案即可!!!!All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighbori原创 2017-02-08 21:09:59 · 451 阅读 · 0 评论