按边长从小到大排序...再逐个加入(就像MST一样)最先联通的点之间最长路径中的最小值就是新加入的边的长.... Count The Pairs Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 266 Accepted Submission(s): 140 Problem Description With the 60th…
Count The Pairs Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 277 Accepted Submission(s): 150 Problem Description With the 60th anniversary celebration of Nanjing University of Science…
hdu5901题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5901 code vs 3223题目链接:http://codevs.cn/problem/3223/ 思路:主要是用了一个Meisell-Lehmer算法模板,复杂度O(n^(2/3)).讲道理,我不是很懂(瞎说什么大实话....),下面输出请自己改 #include<bits/stdc++.h> using namespace std; typedef long long LL;…
Description: Count the number of prime numbers less than a non-negative number, n Hint: The number n could be in the order of 100,000 to 5,000,000. #define NO 0 #define YES 1 class Solution { public: int countPrimes(int n) { if(n == 1) return 0; int…
Problem Description With the 60th anniversary celebration of Nanjing University of Science and Technology coming soon, the university sets n tourist spots to welcome guests. Of course, Redwood forests in our university and its Orychophragmus violaceu…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4750 题意:Q个询问t,求在一个无向图上有多少对点(i,j)满足 i 到 j 的所有路径上的最长边的最小值大于等于t. (i,j)所有路径上的最长边的最小值,容易想到就是 i, j之间的瓶颈路,瓶颈路也就是最小生成树上的边了.注意到每条边的权值都是不相等的,那么MST就是确定的.假设当前MST的边的权值是f[i],Kruskal的并查集中维护一个cnt[i],表示以节点 i 为根的集合的节点个数,那…
Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones. Your task is counting the segments of different colors you can see at last. 输入: The first line of each data set contains exactly on…
思路:容易得到s[n]=s[n-1]+s[n-2],也就是fib数. 求第k小的fib质数的也就是第k个质数数-2,当k>2时. 在就是s[n]/x%m=s[n]%(x*m)/x. 代码如下: #include<cstdio> #include<algorithm> #include<cstring> #define ll long long #define M 1000005 using namespace std; ll k,x,m; int prime[M]…