有两个序列A和B,A=(a1,a2,...,ak),B=(b1,b2,...,bk),A和B都按升序排列.对于1<=i,j<=k,求k个最小的(ai+bj).要求算法尽量高效. int *min_k(int *A, int *B, int len1, int len2, int k) { if (A == NULL || B == NULL || k <= 0) return NULL; int i, j; int *tmp = new int[k]; i = len1; j = len
#coding = utf-8 import sys def Cal_NO(a,b): nums=sorted(a,reverse=True) result=nums[b-1] return result if __name__=='__main__': a=[int(i) for i in sys.stdin.readline().split(' ')] b = int(input()) print(Cal_NO(a,b))
#include<iostream> #include<algorithm> #include<cstring> using namespace std; const int N=510,M=1e4+10; int n,m,k,dis[N],backup[N]; //dis数组表示dis[i]到起点的距离. struct { int a,b,w; }edge[M]; //bellman-ford可以求出来图中有没有负权回路. //迭代k次返回的数表示:从起点经过不超过k
1523. K-inversions Time limit: 1.0 secondMemory limit: 64 MB Consider a permutation a1, a2, …, an (all ai are different integers in range from 1 to n). Let us call k-inversion a sequence of numbers i1, i2, …, ik such that 1 ≤ i1 < i2 < … < ik ≤ n
#include<cstdio> #include<queue> #include<cstring> using namespace std; const int maxn=2e6+5; struct asd{ int from,to,next,val; }b[maxn],b2[maxn]; int head[maxn],tot=1; int h2[maxn],t2=1; int n,m; void ad(int aa,int bb,int cc){ b[tot].fr