oj
Ljosalfar
这个作者很懒,什么都没留下…
展开
-
leetcode 1346. Check If N and Its Double Exist 排序,双指针扫描,注意正负;哈希表
leetcode 1346. Check If N and Its Double Exist 如果都是非负数的从小到大有序序列,从左往右i,j两个指针扫描,j为不满足2*a[i]<a[j]的下一个j。 排序O(nlogn),扫描O(n) 如果有正有负,分成两个序列,把负数序列反转、取相反数。 class Solution { public: bool check_sorted(vector<int>& arr) { // sort(arr.begin(),arr.end()原创 2020-09-05 16:54:25 · 137 阅读 · 0 评论 -
leetcode 313. Super Ugly Number
313. Super Ugly Number 遍历 从小到大找ugly number,每个新的ugly number是primes中的素数乘积,必然是某个素数乘之前的某个ugly number。每个primes中的素数记录一个下标,对应将要乘的ugly number。每个primes中的素数,乘以之前的尽量小的ugly number,但如果之前某个ugly number能和该素数生成之前某个ugly number,则给该素数记录的接下来将要乘的ugly number下标+1。 注意INT_MAX和long原创 2020-09-01 00:15:12 · 163 阅读 · 0 评论 -
leetcode 714. Best Time to Buy and Sell Stock with Transaction Fee 遍历、递推、状态转移
leetcode 714. Best Time to Buy and Sell Stock with Transaction Fee (未完待续) 一开始的想法:遍历,低买高卖,考虑手续费,所以价差不超过手续费不卖,先跌后涨但跌幅不超过手续费不卖,示例正确但Wrong Answer。 class Solution { public: int maxProfit(vector<int>& prices, int fee) { int len=prices.原创 2020-08-29 22:13:38 · 94 阅读 · 0 评论 -
leetcode 1171. Remove Zero Sum Consecutive Nodes from Linked List 前缀和
leetcode 1171. Remove Zero Sum Consecutive Nodes from Linked List /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullp原创 2020-08-28 00:11:20 · 82 阅读 · 0 评论 -
leetcode 189. Rotate Array
leetcode 189. Rotate Array 调库: class Solution { public: void rotate(vector<int>& nums, int k) { int len=nums.size(); k=k%len; vector<int> vec_a(nums.end()-k,nums.end()); vector<int> vec_b(nums原创 2020-08-26 22:37:29 · 68 阅读 · 0 评论 -
洛谷 P1309 瑞士轮 归并
洛谷 P1309 瑞士轮 https://www.luogu.com.cn/problem/P1309 每一轮快排,超时: # include<iostream> # include<fstream> # include<vector> # include<algorithm> using namespace std; class Athlete { public: int id,competence,score; Athlete(){} //原创 2020-08-26 19:47:39 · 112 阅读 · 0 评论 -
leetcode 1371. Find the Longest Substring Containing Vowels in Even Counts
Find the Longest Substring Containing Vowels in Even Counts 用state表示[0,i]子字符串的状态,状态有5个二进制位,对应5个元音字母的奇偶性 class Solution { public: int findTheLongestSubstring(string s) { int str_len...原创 2020-04-16 16:20:54 · 124 阅读 · 0 评论 -
洛谷 P1896 [SCOI2005]互不侵犯 递推/动归 (可状态压缩)
洛谷 P1896 [SCOI2005]互不侵犯 题目描述 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案。国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子。 输入格式 只有一行,包含两个数N,K ( 1 <=N <=9, 0 <= K <= N * N) 输出格式 所得的方案数 递推/动态规划 只考虑一行,一行合法状态必须...原创 2020-04-19 00:06:03 · 168 阅读 · 0 评论