面试题:Leetcode 寻找两个正序数组的中位数 题目链接给定两个大小分别为 m 和 n 的正序(从小到大)数组 nums1 和 nums2。请你找出并返回这两个正序数组的 中位数 。示例 1:输入:nums1 = [1,3], nums2 = [2]输出:2.00000解释:合并数组 = [1,2,3] ,中位数 2示例 2:输入:nums1 = [1,2], nums2 = [3,4]输出:2.50000解释:合并数组 = [1,2,3,4] ,中位数 (2 + 3) / 2 = 2.5示例 3:输入:nums1 = [0,
2-SAT讲解+模板 一、定义要知道2-sat是什么我们先要知道什么是适定性问题(Satisfiability)。适定性问题通俗的来说就是确定是否可以满足所有条件,或者说就是确定一个满足所有条件的方案。取英文的前三个字母,简称sat问题。通俗的sat问题表述一般是这样的:有很多个集合,每个集合里面有若干元素,现给出一些取元素的规则,要你判断是否可行,可行则给出一个可行方案。如果所有集合中,元素个数最多的集合有k个,...
HDU 6002 Game Leader 【贪心】 传送门:HDU 6002Game LeaderTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Problem DescriptionRecently Tom is playing an interesting game. The game contains a...
HDU 3791 二叉搜索树 传送门:HDU 3791二叉搜索树Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Problem Description判断两序列是否为同一二叉搜索树序列Input开始一个数n,(1<=n<=20) 表示有n个需要判断,n= 0 的时候输入结束。接...
最长上升子序列的打印【 O(n^2) 】 #include<iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<cmath>#include<stack>#define ll long long#define inf 0x3f3f3f3fusing namespac...
牛客练习赛60 C-操作集锦 【动态规划】 传送门:C-操作集锦题目描述有一款自走棋有26种操作,每种操作我们都用 a,b,c,d,…,x,y,z 的符号来代替.现在牛牛有一个长度为nn的操作序列,他现在可以从里面拿出某些操作来组合成一个操作视频, 比如说操作序列是abcdabcd,那么操作视频就有a,b,c,d,ab,ac,ad 等(也就是操作序列的子序列).他现在想知道长度为k且本质不同的操作视频有多少种.比如对于aba...
牛客练习赛60 B-三角形周长和 【暴力】 B-三角形周长和 解题思路:因为n是1000,所以直接 O(n2) 去枚举所有边,那么每一条边显然会在其他n−2个三角形中出现,这个就是这条边的贡献系数,这题就算完了。AC代码:#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>#inc...
牛客练习赛60 A-大吉大利 【思维】 传送门:A-大吉大利.链接:https://ac.nowcoder.com/acm/contest/4853/A来源:牛客网题目描述给定n个整数,依次为a1 ,a2,…,an。求∑i=1n∑j=1n(ai&aj)\sum_{i = 1}^n\sum_{j = 1}^n(a_i\&a_j)∑i=1n∑j=1n(ai&aj)。“&”是二进制的...
HDU 5573 Binary Tree 【二进制+思维】 传送门:HDU 5573Binary TreeProblem DescriptionThe Old Frog King lives on the root of an infinite tree. According to the law, each node should connect to exactly two nodes on the next level, forming...
HDU 5583 Kingdom of Black and White 【贪心】 传送门:HDU 5583Kingdom of Black and WhiteProblem DescriptionIn the Kingdom of Black and White (KBW), there are two kinds of frogs: black frog and white frog.Now N frogs are standing in a line, so...
HDU 5584 LCM Walk 【数学+思维+逆推】 HDU 5584LCM Walk Problem DescriptionA frog has just learned some number theory, and can’t wait to show his ability to his girlfriend.Now the frog is sitting on a grid map of infinite rows and ...
Codeforces 1325B CopyCopyCopyCopyCopy 传送门:Codeforces 1325B按照题意,我们可以无限复制所给的字符串,要求我们找最长递增子序列的长度。结合样例,我们不难发现,最长的长度就是将所给数组排序、去重后的长度。所以用一个 set 存数组即可。AC代码:#include<iostream>#include<algorithm>#include<cstring>#inclu...
Codeforces 1325A EhAb AnD gCd 传送门:Codeforces 1325A要满足 GCD(a,b)+LCM(a,b)=x ,只要 a=1,b=x-1 即可。AC代码:#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<cmath>#defin...
Codeforces 1312B Bogosort 传送门:Codeforces 1312BB. BogosortYou are given an array a1,a2,…,an. Array is good if for each pair of indexes i<j the condition j−aj≠i−ai holds. Can you shuffle this array so that it becomes go...
Codeforces 1312A Codeforces 1312A签到题,当 n 可以被 m 整除时,输出 YES,否则 NO。AC代码:#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<cmath>#define ll long long#d...
PAT练习题 甲级P1029 Median (25分)【求中位数】 传送门:P1029将两个序列合并,分奇偶找中值AC代码:#include<iostream>#include<algorithm>#include<cstring>#define ll long longusing namespace std;const int N=1e6+10;int n;ll num[N];int main(...
PAT练习题 甲级P1028 传送门:P1028AC代码:#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<string>#define ll long longusing namespace std;int n,c;struct st...
PAT练习题 P1027 Colors in Mars (20分)【进制转换】 传送门:P1027就是将给你的三个十进制的数转换成十三进制输出。AC代码:#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<cmath>#define ll long long#define inf 0x...
PAT练习题 P1025 PAT Ranking (25分)【结构体水题】 传送门:P1025水题,构造一个结构体,存下 考生id ,组号,成绩。每组输入结束都进行一次排序,将每组的排名记下。最后再进行一次排序,将最终成绩记下。AC代码:#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using nam...