思维
文章平均质量分 64
阿.荣.
勿弃
展开
-
leetcode 1576. 替换所有的问号
class Solution: def modifyString(self, s: str) -> str: n = len(s) s = list('?' + s + '?') for i in range(1, n + 1): if s[i] != '?': continue else: l = s[i - 1] .原创 2022-01-06 00:20:18 · 279 阅读 · 0 评论 -
leetcode 794. 有效的井字游戏【数组+思维】
思路:计算正确的可能情况。第一种:O 走最后一步,X和O的个数相等,X则没有形成三连串, O可能形成0~2条三连串。第二种:X 走最后一步,X个数比O多1,O则没有形成三连串,X可能形成0~2条三连串。code:class Solution: def validTicTacToe(self, board: List[str]) -> bool: def judge(board, ch): cnt = 0 for i...原创 2021-12-09 23:52:03 · 174 阅读 · 0 评论 -
leetcode 423.从英文中重建数字【哈希表+字符串】
思路:找出每个数字的英文单词中独特的字符,或独特字符的个数的差。code:"""找出每个数字的英文单词中独特的字符,或独特字符的个数的差"""class Solution: def originalDigits(self, s: str) -> str: ch = ["e","g","f","i","h","o","n","s","r","u","t","w","v","x","z"] # 哈希表。存储每个字符的个数 num = d.原创 2021-11-24 23:46:15 · 174 阅读 · 0 评论 -
leetcode medium 845. 数组中的最长山脉 【双指针】
思路:将序列分为三种阶段:递增阶段. 持续递增,或者遇到新的递增序列 重置起点。递减阶段. 在前一段是递增的情况下,持续计算起点到当前点的距离。平缓阶段. 重置起点为-1,不可以重置为当前点,否则进入阶段2会产生无峰值的单调递减序列。code:class Solution: def longestMountain(self, arr: List[int]) -> int: start = -1 ans = 0 for i in .原创 2021-11-09 11:13:37 · 191 阅读 · 0 评论 -
leetcode 492.构造矩形
作为一位web开发者, 懂得怎样去规划一个页面的尺寸是很重要的。 现给定一个具体的矩形页面面积,你的任务是设计一个长度为 L 和宽度为 W 且满足以下要求的矩形的页面。要求:你设计的矩形页面必须等于给定的目标面积。宽度 W 不应大于长度 L,换言之,要求 L >= W 。长度 L 和宽度 W 之间的差距应当尽可能小。你需要按顺序输出你设计的页面的长度 L 和宽度 W。示例:输入: 4输出: [2, 2]解释: 目标面积是 4, 所有可能的构造方案有 [1,4], [2原创 2021-10-23 22:53:17 · 83 阅读 · 0 评论 -
leetcode 229.求众数 II【摩尔投票法】
给定一个大小为 n 的整数数组,找出其中所有出现超过 ⌊ n/3 ⌋ 次的元素。示例 1:输入:[3,2,3]输出:[3]示例 2:输入:nums = [1]输出:[1]示例 3:输入:[1,1,1,3,3,2,2,2]输出:[1,2]提示:1 <= nums.length <= 5 * 104-109 <= nums[i] <= 109思路:摩尔投票法,分为两盒阶段:配对阶段和计数阶段。如果至多选一个代表,那他的票数至少要超过一半(⌊ 1/2 ⌋)的票数原创 2021-10-23 10:00:26 · 87 阅读 · 0 评论 -
codeforces 501 C. Misha and Forest (思维)
C. Misha and Foresttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define a forest as a non-directed原创 2016-09-24 11:50:00 · 421 阅读 · 0 评论 -
poj 1703 Find them, Catch them (并查集,思维)
Find them, Catch themTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 42026 Accepted: 12919DescriptionThe police office in Tadu City decides to say ends原创 2016-09-24 19:03:02 · 321 阅读 · 0 评论 -
codeforces C. Queue (思维)
C. Queuetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the Main Berland Bank n people stand in a queue原创 2016-12-10 21:19:49 · 346 阅读 · 0 评论 -
codefoeces C.Buggy Sorting
C. Beauty Pageanttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGeneral Payne has a battalion of n soldie原创 2016-12-10 21:30:23 · 468 阅读 · 0 评论 -
codeforces 734 (思维 暴力)
D. Anton and Chesstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnton likes to play chess. Also, he like原创 2016-12-06 18:22:36 · 333 阅读 · 0 评论 -
codeforces 743 B. Chloe and the sequence (规律题)
B. Chloe and the sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputChloe, the same as Vladik, is a co原创 2016-12-20 17:32:17 · 727 阅读 · 0 评论 -
codeforces 777D. Cloud of Hashtags (逆序思维)
D. Cloud of Hashtagstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya is an administrator of a public原创 2017-02-27 18:16:41 · 246 阅读 · 0 评论 -
hdoj 6106 Count the Sheep (思维)
Count the SheepTime Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 632 Accepted Submission(s): 270Problem DescriptionAltough Skip原创 2017-02-27 19:59:16 · 329 阅读 · 0 评论 -
hdoj 5635 LCP Array (模拟)
LCP ArrayTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1564 Accepted Submission(s): 480Problem DescriptionPeter has a str原创 2017-03-12 17:42:55 · 261 阅读 · 0 评论 -
code forces 791 C. Bear and Different Names (思维)
C. Bear and Different Namestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the army, it isn't easy to fo原创 2017-03-29 22:17:37 · 289 阅读 · 0 评论 -
poj 2718 Smallest Difference (STL 暴力枚举)
Smallest DifferenceTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 10413 Accepted: 2844DescriptionGiven a number of distinct decimal digits, you can f原创 2017-03-14 21:04:47 · 231 阅读 · 0 评论 -
codeforces 705 B. Spider Man (思维)
B. Spider Mantime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPeter Parker wants to play a game with Dr. Oc原创 2016-08-14 21:01:51 · 235 阅读 · 0 评论 -
codeforces 699 B. One Bomb (思维)
B. One Bombtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a description of a depot. It is a原创 2016-08-25 08:55:39 · 242 阅读 · 0 评论 -
hdoj 1220 Cube
CubeTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1773 Accepted Submission(s): 1407Problem DescriptionCowl is good at solvi原创 2016-04-14 20:53:22 · 403 阅读 · 0 评论 -
13周练J - Little Artem and Presents【规律】
J - Little Artem and PresentsTime Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64uSubmit StatusDescriptionLittle Artem got n stones on his birthday and now wa原创 2016-05-29 20:55:49 · 269 阅读 · 0 评论 -
CF Watchmen 【思维+数学】
E - WatchmenTime Limit:3000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64uSubmit StatusDescriptionWatchmen are in a danger and Doctor Manhattan together with his fri原创 2016-05-30 23:39:02 · 427 阅读 · 0 评论 -
(二)O-O Bear and Three Balls
O - OTime Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64uSubmit StatusDescriptionLimak is a little polar bear. He has n balls, the i-th ball has size ti.原创 2016-06-01 09:08:50 · 465 阅读 · 0 评论 -
A. Dima and Guards 【思维 好题】
Dima and GuardsDescriptionNothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a d原创 2016-05-31 19:11:00 · 336 阅读 · 0 评论 -
lightoj 1010 - Knights in Chessboard (找规律思维)
1010 - Knights in Chessboard PDF (English)StatisticsForumTime Limit: 1 second(s)Memory Limit: 32 MBGiven an m x n chessboard where you want to place c原创 2016-08-16 08:41:06 · 927 阅读 · 0 评论 -
lightoj 1349 - Aladdin and the Optimal Invitation (中位数的运用)
1349 - Aladdin and the Optimal Invitation PDF (English)StatisticsForumTime Limit: 4 second(s)Memory Limit: 32 MBFinally Aladdin reached home, with the原创 2016-08-16 09:04:49 · 384 阅读 · 0 评论 -
lightoj 1369 - Answering Queries (思维规律)
1369 - Answering Queries PDF (English)StatisticsForumTime Limit: 3 second(s)Memory Limit: 32 MBThe problem you need to solve here is pretty simple. Yo原创 2016-08-16 09:08:49 · 492 阅读 · 0 评论 -
codeforces 703B. Mishka and trip
B. Mishka and triptime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Mishka is a great traveller and sh原创 2016-08-18 16:36:46 · 337 阅读 · 0 评论 -
codeforces 703 C. Chris and Road
C. Chris and Roadtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnd while Mishka is enjoying her trip...原创 2016-08-18 16:51:48 · 297 阅读 · 0 评论 -
hdoj 5480 Conturbatio (思维)
ConturbatioTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 975 Accepted Submission(s): 439Problem DescriptionThere are many rook原创 2016-08-19 18:56:46 · 285 阅读 · 0 评论 -
zzulioj 1902: 985的因子对难题 [思维]
1902: 985的因子对难题Time Limit: 2 Sec Memory Limit: 128 MBSubmit: 142 Solved: 38SubmitStatusWeb BoardDescription985有n个正整数,他想知道存在多少个不同的因子对(a[i], a[j])使得1 特别地,他认为(a[i],a[j])与(a[j],a[i原创 2016-08-09 18:33:15 · 244 阅读 · 0 评论 -
zzulioj 1898: 985的数字难题 [思维]
1898: 985的数字难题Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 281 Solved: 102SubmitStatusWeb BoardDescription985有n个数,已知每次操作可以将其中不相同的两个数一个加一、一个减一,操作次数不限。问他最多可以得到多少个相同的数。Input原创 2016-08-09 18:41:50 · 334 阅读 · 0 评论 -
zzulioj 1899: 985的最大和难题 [规律]
1899: 985的最大和难题Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 307 Solved: 35SubmitStatusWeb BoardDescription985有2 * n - 1个整数,他每次可以将其中n个数变号,操作次数不限,问他可以得到的最大和。Input第一行输入一个整数原创 2016-08-09 18:45:57 · 230 阅读 · 0 评论 -
hdoj 5100 Chessboard (思维规律)
ChessboardTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1086 Accepted Submission(s): 463Problem DescriptionConsider the problem原创 2016-08-22 14:08:37 · 299 阅读 · 0 评论 -
codeforces 701 A. Cards
A. Cardstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cards (n is even) in the deck. Each c原创 2016-08-23 12:28:02 · 294 阅读 · 0 评论 -
poj 1852 Ants (思维)
AntsTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 13918 Accepted: 6072DescriptionAn army of ants walk on a horizontal pole of length l cm, each with a原创 2016-04-14 12:20:16 · 267 阅读 · 0 评论