
STL
xuanweiace
一个热爱算法竞赛的弱校ACMer路过。青大本,浙大硕,方向后端开发,菜鸡一枚,奋斗ing...
展开
-
素数环(dfs&&STL做法)HDU - 1016
这题第一思路显然dfs,但是最近想了一下可以用next_permutation做,结果TLE了,究其原因,就是深搜的时候剪枝做的比较好,所以运行的时间一对比(样例是n=18),会发现dfs的解法程序在不停的输出数据,但是STL的却仅仅是在闪光标。 得结论:有的题剪枝的十分优雅(比如这题,如果1 2 判断不成立,那么第二个数放2这一大支直接剪掉了),便不能用next_permutati...原创 2018-06-07 22:22:39 · 264 阅读 · 0 评论 -
【HRBUST - 1054 】Brackets! Brackets! (括号匹配,思维,STL栈)
题干:There are six kinds of brackets: ‘(‘, ‘)’, ‘[‘, ‘]’, ‘{’, ‘}’. dccmx’s girl friend is now learning java programming language, and got mad with brackets! Now give you a string of brackets. Is it v...原创 2018-10-05 16:57:43 · 436 阅读 · 0 评论 -
【CodeForces-1041C】Coffee Break(贪心,STL,set二分维护,题意难,有坑,SJ题,构造)(知识点总结)
题干:Recently Monocarp got a job. His working day lasts exactly mm minutes. During work, Monocarp wants to drink coffee at certain moments: there are nn minutes a1,a2,…,ana1,a2,…,an, when he is able a...原创 2018-10-07 23:27:11 · 1136 阅读 · 0 评论 -
【牛客 - 181C】序列(前缀和,二分,可用set维护)(有坑)
题干:小a有n个数,他想把他们划分为连续的权值相等的k段,但他不知道这是否可行。每个数都必须被划分这个问题对他来说太难了,于是他把这个问题丢给了你。输入描述:第一行为两个整数n,q,分别表示序列长度和询问个数。第二行有n个数,表示序列中的每个数。接下来的q行,每行包含一个数k,含义如题所示。输出描述:输出q行,每行对应一个数Yes或者No,分别表示可行/不可行...原创 2018-10-10 18:31:40 · 306 阅读 · 0 评论 -
【CodeForces - 1042B】Vitamins(去重方法,二进制或stlmap,水题)
题干:Berland shop sells nn kinds of juices. Each juice has its price cici. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". ...原创 2018-09-29 11:25:03 · 827 阅读 · 0 评论 -
【CodeForces - 246D】Colorful Graph (暴力,图,存边,STL)
题干:You've got an undirected graph, consisting of n vertices and m edges. We will consider the graph's vertices numbered with integers from 1 to n. Each vertex of the graph has a color. The color of ...原创 2018-11-08 17:37:10 · 356 阅读 · 0 评论 -
【CodeForces - 260B 】Ancient Prophesy (暴力匹配,BF算法,日期字符串)
题干:A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".We'll say that some date is mentione...原创 2018-11-14 17:07:36 · 356 阅读 · 0 评论 -
【CodeForces - 527C】Glass Carving(线段树或者SBT或者set)
题干:Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular w mm × h mm sheet of glass, a diamond glass cutter and lots ...原创 2018-11-19 15:27:04 · 268 阅读 · 0 评论 -
【CodeForces - 305C】Ivan and Powers of Two(思维,STL,set,优先队列)
题干:Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order.Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper....原创 2018-11-29 22:40:48 · 259 阅读 · 0 评论 -
【CodeForces - 988C 】Equal Sums (思维,STLmap,STLset,tricks)
题干:You are given kk sequences of integers. The length of the ii-th sequence equals to nini.You have to choose exactly two sequences ii and jj (i≠ji≠j) such that you can remove exactly one element ...原创 2019-02-16 00:11:57 · 334 阅读 · 0 评论 -
【HDU - 5700】【51nod - 1672】 区间交(贪心,STLset 或线段树第k大)
题干:小A有一个含有n个非负整数的数列与m个区间,每个区间可以表示为li,ri。它想选择其中k个区间, 使得这些区间的交的那些位置所对应的数的和最大。(是指k个区间共同的交,即每个区间都包含这一段,具体可以参照样例) 在样例中,5个位置对应的值分别为1,2,3,4,6,那么选择[2,5]与[4,5]两个区间的区间交为[4,5],它的值的和为10。 收起输入第一行三个数...原创 2019-02-17 21:11:17 · 245 阅读 · 0 评论 -
【计蒜客 - 蓝桥训练】轻重搭配(贪心,STLset 或 二分)
题干:n 个同学去动物园参观,原本每人都需要买一张门票,但售票处推出了一个优惠活动,一个体重为 xx 的人可以和体重至少为 2x2x 配对,这样两人只需买一张票。现在给出了 nn 个人的体重,请你计算他们最少需要买几张门票?输入格式第一行一个整数 nn,表示人数。第二行 nn 个整数,每个整数 a_iai 表示每个人的体重。输出格式一个整数,表示最少需要购买的门票数目。...原创 2019-02-12 14:38:13 · 758 阅读 · 1 评论 -
【牛客 - 331B】炫酷五子棋(STLset 或Hash,tricks,二维map标记)
题干: 五子棋是一个简单的双人游戏。小希最近在思索一种更好玩的五子棋。她希望胜利不再是谁先五子连珠谁赢,而变成谁落子后,该子与之前的子五子连珠的次数更多才能胜利。但是如果是在普通的棋盘上,这个游戏又显得不是很有趣,所以她将棋盘扩大至N*N,因为棋盘过大,没有一个程序能将其展示出来,所以如何落子只能凭借记忆。她希望你能写一个程序,判断每步落子与之前的同色棋子是否能形成五子连珠。 五...原创 2019-02-13 21:08:05 · 337 阅读 · 0 评论 -
【牛客 - 1080B】tokitsukaze and Hash Table(STLset,并查集,Hash)
题干:链接:https://ac.nowcoder.com/acm/contest/1080/B来源:牛客网tokitsukaze有n个数,需要按顺序把他们插入哈希表中,哈希表的位置为0到n-1。插入的规则是:刚开始哈希表是空的。对于一个数x,在哈希表中,如果(x mod n)的位置是空的,就把x放在(x mod n)的位置上。如果不是空的,就从(x mod n)往右开始找到...原创 2019-08-24 14:30:31 · 253 阅读 · 0 评论 -
【2019南昌邀请赛现场赛 - J】Prefix(STLmap,思维)
题干:yah hasnstrings<s1,⋯,sn>, and he generates a sequencePby two steps:P=<s1,⋯,sn>Replace eachsiwith all prefixes of itself.An example is:thenstrings are< aab,ab &g...原创 2019-09-06 15:54:06 · 385 阅读 · 0 评论 -
【2019icpc南京站网络赛 - F】Greedy Sequence(思维,贪心构造,STLset)
题干:You're given a permutationaaof lengthnn(1 \le n \le 10^51≤n≤105).For eachi \in [1,n]i∈[1,n], construct a sequences_isiby the following rules:s_i[1]=isi[1]=i; The length ofs_isiis...原创 2019-09-06 15:57:29 · 216 阅读 · 0 评论 -
【HDU - 1022】Train Problem I (栈模拟,水题,思维)
题干:As 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 the fastest all o...原创 2018-09-13 14:13:44 · 259 阅读 · 0 评论 -
【HDU - 1702 】ACboy needs your help again! (栈和队列,水题模拟)
题干:ACboy was kidnapped!! he miss his mother very much and is very scare now.You can't image how dark the room he was put into is, so poor :(. As a smart ACMer, you want to get ACboy out of the mon...原创 2018-09-13 14:06:17 · 343 阅读 · 0 评论 -
【HDU - 1263】 水果(STL)
题干:夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以很容易掌握所有水果的销售情况了. Input第一行正整数N(0<N<=10)表示有N组测试数据. 每组测试数据的第一行是一个整数M(0<M<=100),表示工有M次成功的交易.其后有M...原创 2018-07-30 00:18:50 · 286 阅读 · 0 评论 -
**【HDU - 1052】 田忌赛马(田忌赛马类贪心或双端队列)(或dp)
U - Tian Ji -- The Horse RacingHere is a famous story in Chinese history."That was about 2300 years ago. General Tian Ji was a high official in the country Qi. He likes to play horse ...转载 2018-07-14 23:01:27 · 325 阅读 · 0 评论 -
【HDU - 1412】 {A} + {B} (STL + set)
题干:给你两个集合,要求{A} + {B}. 注:同一个集合中不会有两个相同的元素.Input每组输入数据分为三行,第一行有两个数字n,m(0<n,m<=10000),分别表示集合A和集合B的元素个数.后两行分别表示集合A和集合B.每个元素为不超出int范围的整数,每个元素之间有一个空格隔开.Output针对每组数据输出一行数据,表示合并后的集合,要求从小到大输出...原创 2018-07-30 00:05:00 · 175 阅读 · 0 评论 -
STL之 set简略介绍。
set常用函数及其讲解 构造set集合的主要目的是为了快速检索,使用set前,需要在程序头文件中包含声明“#include<set>”。 set集合容器实现了红黑树(Red-Black Tree)的平衡二叉检索树的的数据结构,在插入元素时,它会自动调整二叉树的排列,把该元素放到适当的位置.例如会将数字进行从小到大的默认排序,将string按字典顺序自动排列。 创建集合对象...原创 2018-07-29 22:08:35 · 282 阅读 · 0 评论 -
【CF#2A】Winner(模拟 STL-map)☆
题干:The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, h...原创 2018-07-29 21:46:44 · 359 阅读 · 0 评论 -
【HDU - 5688 】Problem D(STL+map)
题干:度熊所居住的 D 国,是一个完全尊重人权的国度。以至于这个国家的所有人命名自己的名字都非常奇怪。一个人的名字由若干个字符组成,同样的,这些字符的全排列的结果中的每一个字符串,也都是这个人的名字。例如,如果一个人名字是 ACM,那么 AMC, CAM, MAC, MCA, 等也都是这个人的名字。在这个国家中,没有两个名字相同的人。 度熊想统计这个国家的人口数量,请帮助度熊设计一个程序,用...原创 2018-07-30 00:04:20 · 265 阅读 · 0 评论 -
HDU 3785 寻找大富翁(sort排序或优先队列)
题干: 浙江桐乡乌镇共有n个人,请找出该镇上的前m个大富翁.Input输入包含多组测试用例. 每个用例首先包含2个整数n(0<n<=100000)和m(0<m<=10),其中: n为镇上的人数,m为需要找出的大富翁数, 接下来一行输入镇上n个人的财富值. n和m同时为0时表示输入结束.Output请输出乌镇前m个大富翁的财产数,财产多的排前面,如果大富翁不足...原创 2018-07-11 10:27:57 · 377 阅读 · 0 评论 -
【POJ - 1028】 Web Navigation( 栈 or 模拟队列 )
题干:Standard web browsers contain features to move backward and forward among the pages recently visited. One way to implement these features is to use two stacks to keep track of the pages that can ...原创 2018-07-30 22:05:54 · 248 阅读 · 0 评论 -
【51Nod-1100】 斜率最大(贪心)☆双排序
题干:平面上有N个点,任意2个点确定一条直线,求出所有这些直线中,斜率最大的那条直线所通过的两个点。(点的编号为1-N,如果有多条直线斜率相等,则输出所有结果,按照点的X轴坐标排序,正序输出。数据中所有点的X轴坐标均不相等,且点坐标为随机。)Input第1行,一个数N,N为点的数量。(2 <= N <= 10000) 第2 - N + 1行:具体N个点的坐标,X Y均...原创 2018-08-01 22:15:09 · 243 阅读 · 0 评论 -
【51nod - 1087】 1 10 100 1000(找规律推公式,水,map)
题干:1,10,100,1000...组成序列1101001000...,求这个序列的第N位是0还是1。Input第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000) 第2 - T + 1行:每行1个数N。(1 <= N <= 10^9)Output共T行,如果该位是0,输出0,如果该位是1,输出1。Sample I...原创 2018-08-05 15:39:09 · 951 阅读 · 0 评论 -
【51nod - 1065】 最小正子段和( 前缀和排序 )
题干:N个整数组成的序列a11,a22,a33,…,ann,从中选出一个子序列(aii,ai+1i+1,…ajj),使这个子序列的和>0,并且这个和是所有和>0的子序列中最小的。例如:4,-1,5,-2,-1,2,6,-2。-1,5,-2,-1,序列和为1,是最小的。Input第1行:整数序列的长度N(2 <= N <= 50000) 第2 - N+1行:...原创 2018-08-11 21:20:54 · 371 阅读 · 0 评论 -
【HDU - 3328】Flipper (栈模拟)
题干: Problem DescriptionLittle Bobby Roberts (son of Big Bob, of Problem G) plays this solitaire memory game called Flipper. He starts with n cards, numbered 1 through n, and lays them out in a ro...原创 2018-10-08 00:56:04 · 256 阅读 · 0 评论 -
【HDU - 5914 】Triangle (打表 或 set维护)
题干:Mr. Frog has n sticks, whose lengths are 1,2, 3⋯⋯n respectively. Wallice is a bad man, so he does not want Mr. Frog to form a triangle with three of the sticks here. He decides to steal some stic...原创 2018-09-05 01:06:37 · 231 阅读 · 0 评论 -
【51nod - 1875】 丢手绢(约瑟夫问题,可打表,用STL模拟)
题干:六一儿童节到了,小朋友们在玩丢手绢的游戏。总共有C个小朋友,编号从1到C,他们站成一个圈,第i(1<i<=C)个人的左边是i-1,第1个人的左边是C。第i(1<=i<C)个人的右边是i+1,第C个人的右边是1。然后再给出一个常数E。刚开始的时候1号小朋友拿着手绢,接下来游戏开始,在游戏的每一轮,拿手绢的人会把手绢向右边传递E-1个人,拿到手绢的人退出圈,把手绢递给...原创 2018-09-10 09:22:34 · 333 阅读 · 0 评论 -
【POJ - 3125 】Printer Queue(模拟,队列+优先队列,STL)
题干:The only printer in the computer science students' union is experiencing an extremely heavy workload. Sometimes there are a hundred jobs in the printer queue and you may have to wait for hours to...原创 2018-09-09 00:56:29 · 335 阅读 · 0 评论 -
【Codeforces - 900C】Remove Extra One(思维,STLset,tricks)
题干:You are given a permutationpof lengthn. Remove one element from permutation to make the number of records the maximum possible.We remind that in a sequence of numbersa1, a2, ..., akthe ele...原创 2019-10-09 20:25:02 · 199 阅读 · 0 评论