CF Gym100548 K Last Defence 解题报告】的更多相关文章

先特判掉特殊情况: $a=b,Ans=2$ $ab=0,a+b>0,Ans=2$ $a=b=0,Ans=1$ 考虑剩下的非特殊情况.记$Solve(a,b)$为数列中除了$a,b$外的不同的数的个数,分两种情况: $b|a$,设$a=kb$,那么数列会出现的数有:$0,b,2b,3b,\cdots,kb$,那么$Solve(a,b)=k-1$. $b\nmid a$,设$a=kb+r$,那么数列中会出现的与$a$在对$b$取模下同余的数有:$r,r+b,r+2b,\cdots,r+kb$,那么可…
CF Round #600 (Div 2) 解题报告(A~E) A:Single Push 采用差分的思想,让\(b-a=c\),然后观察\(c\)序列是不是一个满足要求的序列 #include<bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int T, n; int a[maxn], b[maxn]; int c[maxn]; int main() { cin >> T; while(T--) { s…
[剑指Offer]链表中倒数第k个节点 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://www.nowcoder.com/ta/coding-interviews 题目描述: 输入一个链表,输出该链表中倒数第k个结点. Ways 这个题的做法大家应该都知道了,就是使用两个指针,走在前面的指针比走在后面的指针优先k-1步,这样当走在前面的指针走到头的时候,走在后面的指针正好到了倒数第k个节点. 需要注意的是代码的鲁棒性.有以下三点: 头结点不存在 k为0…
[LeetCode]692. Top K Frequent Words 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/top-k-frequent-words/description/ 题目描述: Given a non-empty list of words, return the k most frequent elements. Your answer should be sorted by frequency f…
[剑指Offer]二叉搜索树的第k个结点 解题报告(Python) 标签(空格分隔): 剑指Offer 题目地址:https://www.nowcoder.com/ta/coding-interviews 题目描述: 给定一颗二叉搜索树,请找出其中的第k大的结点. 例如, 5 / \ 3 7 / \ / \ 2 4 6 8 中,按结点数值大小顺序第三个结点的值为4. 解题方法 遇到BST想中序遍历.这个题先中序遍历,然后找出第k个节点. 代码: # -*- coding:utf-8 -*- #…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/find-k-closest-elements/description/ 题目描述: Given a sorted array, two integers k and x, find the k closest elements to x in the array. The result should also b…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/rearrange-string-k-distance-apart 题目描述: Given a non-empty string str and an integer k, rearrange the string such that the same characters are at least distanc…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 解题方法 字典 优先级队列 日期 题目地址:https://leetcode.com/problems/top-k-frequent-elements/description/ 题目描述 Given a non-empty array of integers, return the k most frequent elements. For example,…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters/description/ 题目描述: Find the length of the longest substring T of a given string (consists of lowercase…
题目地址: https://oj.leetcode.com/problems/merge-k-sorted-lists/ 题目内容: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ Merge k sorted linked lists and return it a…