
思维
文章平均质量分 53
xuanweiace
一个热爱算法竞赛的弱校ACMer路过。青大本,浙大硕,方向后端开发,菜鸡一枚,奋斗ing...
展开
-
LeetCode 260. 只出现一次的数字 III
题目大意:给定一个整数数组nums,其中恰好有两个元素只出现一次,其余所有元素均出现两次。 找出只出现一次的那两个元素。你可以按 任意顺序 返回答案。进阶:你的算法应该具有线性时间复杂度。你能否仅使用常数空间复杂度来实现?示例 1:输入:nums = [1,2,1,3,2,5]输出:[3,5]解释:[5, 3] 也是有效的答案。示例 2:输入:nums = [-1,0]输出:[-1,0]示例 3:输入:nums = [0,1]输出:[1,0]提示:2 &l.原创 2021-11-20 15:20:10 · 119 阅读 · 0 评论 -
LeetCode 397. 整数替换
题目大意:给定一个正整数n ,你可以做如下操作:如果n是偶数,则用n / 2替换n 。如果n是奇数,则可以用n + 1或n - 1替换n 。n变为 1 所需的最小替换次数是多少?链接:https://leetcode-cn.com/problems/integer-replacement示例 1:输入:n = 8输出:3解释:8 -> 4 -> 2 -> 1示例 2:输入:n = 7输出:4解释:7 -> 8 -> 4 ...原创 2021-11-19 17:29:01 · 348 阅读 · 0 评论 -
LeetCode 318. 最大单词长度乘积
给定一个字符串数组words,找到length(word[i]) * length(word[j])的最大值,并且这两个单词不含有公共字母。你可以认为每个单词只包含小写字母。如果不存在这样的两个单词,返回 0。https://leetcode-cn.com/problems/maximum-product-of-word-lengths示例1:输入: ["abcw","baz","foo","bar","xtfn","abcdef"]输出: 16解释: 这两个单词为 "abcw",...原创 2021-11-19 16:11:37 · 130 阅读 · 0 评论 -
【51Nod - 1270】数组的最大代价(dp,思维)
题干:数组A包含N个元素A1, A2......AN。数组B包含N个元素B1, B2......BN。并且数组A中的每一个元素Ai,都满足1 <= Ai <= Bi。数组A的代价定义如下:(公式表示所有两个相邻元素的差的绝对值之和)给出数组B,计算可能的最大代价S。Input第1行:1个数N,表示数组的长度(1 <= N <= 50000...原创 2019-10-31 20:58:36 · 337 阅读 · 0 评论 -
【Codeforces - 769D】k-Interesting Pairs Of Integers(暴力,统计,思维,数学,异或)
题干:Vasya has the sequence consisting ofnintegers. Vasya consider the pair of integersxandyk-interesting, if their binary representation differs from each other exactly inkbits. For example, ...原创 2019-10-31 20:42:40 · 571 阅读 · 0 评论 -
【CodeForces - 789D】Weird journey(思维,图的性质,tricks,有坑)
题干:Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherland— Uzhlyandia.It is widely known that Uzhlyandia hasncities connected withmbidirec...原创 2019-10-25 13:47:53 · 318 阅读 · 0 评论 -
【CodeForces - 789C】Functions again(最大子段和变形,dp,思维)
题干:Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon th...原创 2019-10-25 13:41:09 · 304 阅读 · 1 评论 -
【CodeForces - 827A】String Reconstruction(并查集合并区间,思维)
题干:Ivan had stringsconsisting of small English letters. However, his friend Julia decided to make fun of him and hid the strings. Ivan preferred making a new string to finding the old one.Ivan ...原创 2019-10-25 13:28:56 · 842 阅读 · 0 评论 -
【CodeForces - 705C】Thor(模拟,STLset优化链表)
题干:Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There arenapplications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the ...原创 2019-10-25 13:06:58 · 286 阅读 · 0 评论 -
【Codeforces - 822C】Hacker, pack your bags!(思维)
C. Hacker, pack your bags!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's well known that the best way to distract from...原创 2019-10-31 21:04:12 · 205 阅读 · 0 评论 -
【CodeForces - 514D】R2D2 and Droid Army(二分+滑动窗口ST表,或 尺取+单调队列或STLmultiset)
题干:An army ofndroids is lined up in one row. Each droid is described bymintegersa1, a2, ..., am, whereaiis the number of details of thei-th type in this droid's mechanism. R2-D2 wants to des...原创 2019-10-14 19:16:44 · 337 阅读 · 0 评论 -
【CodeForces - 697C】Lorenzo Von Matterhorn(二叉树,思维)
题干:巴尼住在NYC。NYC具有从1开始的正整数编号的无数个交叉点。在交叉点i和2i之间以及i和2i + 1之间存在双向道路,对任意整数i都满足。在任意两点之间都有且只有一条最短路。最初任何人都可以通过任何道路免费。 但是后来发生了 q 个事件。 有两种类型的事件:1. 政府制定新规。 一个规则可以用三个整数表示v,u和w。经过这次操作,点u到点v...原创 2019-10-11 21:49:21 · 425 阅读 · 0 评论 -
【CodeForces - 599C 】Day at the Beach(思维)
题干:给定一个数列A,要求你将这个数列划分成几个连续的部分,使得每部分分别从小到大排序后整个数列有序。问最多可以划分成几个部分。Input第一行包含一个整数n(1 ≤ n ≤ 100 000)— 表示数列的长度之后一行n个整数hi(1 ≤ hi ≤ 109). 描述这个数列。Output输出最多能划分出的部分数。ExampleInput31...原创 2019-10-11 21:19:20 · 243 阅读 · 0 评论 -
【CodeForces - 124C】Prime Permutation(数学,思维,小结论)
题干:You are given a strings, consisting of small Latin letters. Let's denote the length of the string as|s|. The characters in the string are numbered starting from1.Your task is to find out if ...原创 2019-10-11 20:27:38 · 295 阅读 · 0 评论 -
【Codeforces - 1000C】Covered Points Count(思维,离散化,差分)
题干:You are givennnsegments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested i...原创 2019-10-11 20:26:34 · 301 阅读 · 0 评论 -
【CodeForces - 999D】Equalize the Remainders(思维,贪心)
题干:You are given an array consisting ofnnintegersa1,a2,…,ana1,a2,…,an, and a positive integermm. It is guaranteed thatmmis a divisor ofnn.In a single move, you can choose any positioniibe...原创 2019-10-11 20:25:36 · 286 阅读 · 0 评论 -
【POJ - 3250 】Bad Hair Day (单调栈)
题干:Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the to...原创 2018-07-16 23:45:53 · 301 阅读 · 0 评论 -
【nyoj 270】数的分解(统计因子模板)
题干:数的分解时间限制:1000 ms | 内存限制:65535 KB难度:1 描述你的任务是找到一个最小的正整数Q,使Q的各位数的乘积等于N。 输入最多450组测试数据。数据以EOF结尾。输入一个整数N(0 ≤ N ≤ 400)。输出输出Q,如果Q不存在则输出−1。样例输入105样例输出255法1:#include<cstdio>#include<iostream&g...转载 2018-07-12 14:13:31 · 291 阅读 · 0 评论 -
【nyoj 47】 过河问题(思维)
过河问题时间限制:1000 ms | 内存限制:65535 KB难度:5描述在漆黑的夜里,N位旅行者来到了一座狭窄而且没有护栏的桥边。如果不借助手电筒的话,大家是无论如何也不敢过桥去的。不幸的是,N个人一共只带了一只手电筒,而桥窄得只够让两个人同时过。如果各自单独过桥的话,N人所需要的时间已知;而如果两人同时过桥,所需要的时间就是走得比较慢的那个人单独行动时所需的时间。问题是,如何设计一个方案...转载 2018-07-14 22:49:21 · 293 阅读 · 0 评论 -
【POJ - 1328】Radar Installation(贪心+计算几何)安装雷达辐射岛屿
题干:Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on t...原创 2018-07-12 23:05:01 · 294 阅读 · 0 评论 -
【51nod-1289】大鱼吃小鱼
题干:有N条鱼每条鱼的位置及大小均不同,他们沿着X轴游动,有的向左,有的向右。游动的速度是一样的,两条鱼相遇大鱼会吃掉小鱼。从左到右给出每条鱼的大小和游动的方向(0表示向左,1表示向右)。问足够长的时间之后,能剩下多少条鱼?Input第1行:1个数N,表示鱼的数量(1 <= N <= 100000)。 第2 - N + 1行:每行两个数Aii, Bii,中间用空格分隔,分别表示鱼的大小...原创 2018-07-12 23:23:50 · 493 阅读 · 0 评论 -
【uva-673】 Parentheses Balance(括号匹配问题)
题干:You are given a string consisting of parentheses () and []. A string of this type is said to be correct:(a)if it is the empty string(b)if A and B are correct, AB is correct,(c)if A is correct, (A) ...原创 2018-07-12 23:46:55 · 468 阅读 · 0 评论 -
【CF#468 div2 D. 】Peculiar apple-tree(思维)
题干:In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there areninflorescences, numbered from1ton. Infloresce...原创 2018-07-24 16:27:59 · 303 阅读 · 0 评论 -
【CF#-931A】 Friends Meeting(思维)
题干:Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another one is in the point x2 = b.Each of the friends can move by one along th...原创 2018-07-24 16:33:31 · 339 阅读 · 0 评论 -
【CF#931.B】World Cup (思维,模拟)
题干:The last stage of Football World Cup is played using the play-off system.There are n teams left in this stage, they are enumerated from 1 to n. Several rounds are held, in each round the remain...原创 2018-07-24 16:42:37 · 691 阅读 · 0 评论 -
【HDU - 3410 】 Passing the Message(单调栈)
题干:What a sunny day! Let’s go picnic and have barbecue! Today, all kids in “Sun Flower” kindergarten are prepared to have an excursion. Before kicking off, teacher Liu tells them to stand in a row. ...原创 2018-07-24 16:52:18 · 299 阅读 · 0 评论 -
*【CF#633B】 A Trivial Problem(二分或枚举)
题干:Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with...原创 2018-07-25 00:20:03 · 246 阅读 · 0 评论 -
【HDU - 2203】 亲和串 (思维题,可选KMP)
题干:Problem Description人随着岁数的增长是越大越聪明还是越大越笨,这是一个值得全世界科学家思考的问题,同样的问题Eddy也一直在思考,因为他在很小的时候就知道亲和串如何判断了,但是发现,现在长大了却不知道怎么去判断亲和串了,于是他只好又再一次来请教聪明且乐于助人的你来解决这个问题。亲和串的定义是这样的:给定两个字符串s1和s2,如果能通过s1循环移位,使s2包含在s1中,那么我...原创 2018-07-13 17:59:17 · 224 阅读 · 0 评论 -
【POJ - 3494】Largest Submatrix of All 1’s(加一点思维后化成 单调栈)
题干:Given a m-by-n (0,1)-matrix, of all its submatrices of all 1’s which is the largest? By largest we mean that the submatrix has the most elements.InputThe input contains multiple test cases. E...原创 2018-07-20 00:02:26 · 399 阅读 · 0 评论 -
【51NOD - 1523】 非回文(dfs)
题干:一个字符串是非回文的,当且仅当,他只由前p个小写字母构成,而且他不包含长度大于等于2的回文子串。给出长度为n的非回文串s。请找出字典序比s大的,而且字典序要最小的长度为n的非回文。Input单组测试数据。 第一行有两个整数n 和p (1≤n≤1000; 1≤p≤26)。 第二行包含一个字符串s,它的长度是n。输入保证他是非回文的。Output输出字典序比s大的且字典序要最小的长度为n的非回文...原创 2018-07-14 22:45:32 · 1318 阅读 · 0 评论 -
【HihoCoder - 1550】顺序三元组(思维)
题干:给定一个长度为N的数组A=[A1, A2, ... AN],已知其中每个元素Ai的值都只可能是1, 2或者3。请求出有多少下标三元组(i, j, k)满足1 ≤ i < j < k ≤ N且Ai < Aj < Ak。Input第一行包含一个整数N 第二行包含N个整数A1, A2, ... AN。(1 ≤ Ai ≤ 3) 对于30%的数据,1...原创 2018-07-31 20:22:44 · 525 阅读 · 0 评论 -
【51Nod - 1279】 扔盘子(思维)(on-p会超时)
题干:有一口井,井的高度为N,每隔1个单位它的宽度有变化。现在从井口往下面扔圆盘,如果圆盘的宽度大于井在某个高度的宽度,则圆盘被卡住(恰好等于的话会下去)。盘子有几种命运:1、掉到井底。2、被卡住。3、落到别的盘子上方。盘子的高度也是单位高度。给定井的宽度和每个盘子的宽度,求最终落到井内的盘子数量。 如图井和盘子信息如下:井:5 6 4 3 6 2 3盘子:2...原创 2018-08-05 15:56:42 · 266 阅读 · 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 评论 -
【Codeforces - 378C】Maze(dfs,思维)
题干:Pavel loves grid mazes. A grid maze is ann × mrectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common si...原创 2018-08-30 22:36:03 · 653 阅读 · 0 评论 -
【HDU - 5744 】Keep On Movin (回文串性质,贪心思维,不是水题)
题干:Professor Zhang has kinds of characters and the quantity of the ii-th character is aiai. Professor Zhang wants to use all the characters build several palindromic strings. He also wants to maximi...原创 2018-09-01 00:17:26 · 268 阅读 · 0 评论 -
【POJ - 2676】Sudoku (经典深搜,dfs数独)
题干:Sudoku is a very simple task. A square table with 9 rows and 9 columns is divided to 9 smaller squares 3x3 as shown on the Figure. In some of the cells are written decimal digits from 1 to 9. The...原创 2018-09-01 13:40:15 · 732 阅读 · 0 评论 -
【CodeForces - 833A】The Meaningless Game(思维题,数学,可用牛顿迭代法,知识点总结)
题干:Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.The game consists of multiple rounds. Its rules are very simple: in each round, a natural num...原创 2018-09-04 16:05:11 · 561 阅读 · 0 评论 -
【HDU - 6016】Count the Sheep (思维,类似二分图)
题干:Altough Skipping the class is happy, the new term still can drive luras anxious which is of course because of the tests! Luras became worried as she wanted to skip the class, as well as to attend...原创 2018-09-13 11:44:39 · 313 阅读 · 0 评论 -
【CodeForces - 735B】Urbanization (找规律,思维)
题干:Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are n people who plan to move to the cities...原创 2018-09-08 19:37:19 · 383 阅读 · 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 评论