Sample Input 1 // T3 3// n m1 2 3//u v w1 3 42 3 5Sample Output Scenario #1:4 # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # define LL long long using namespace std ; ; c…
题目大意,有两只青蛙,分别在两个石头上,青蛙A想要到青蛙B那儿去,他可以直接跳到B的石头上,也可以跳到其他石头上,再从其他石头跳到B那儿,求青蛙从A到B的所有路径中最小的Frog Distance,我们定义Frog Distance为从A到B的一条路径中最大的一条边假如点0到点1有3条路第一条路径 会经过2个点 3条边 边的值为 1 4 3第二条路径 一条边 5第三条路径 1 3 2 那么 Frog Distance 分别为 4 5 3 则最终输出3 Sample Input 20 03 4 3…
Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tourists' sunscreen, he wants to avoid swimming and instead rea…
用最小的空间复杂度找出一个长度为n的数组且数据中的元素是[0,n-1]中任一个重复的数据. 比如:[1, 2, 3, 3, 2, 2, 6, 7, 8, 9] 中 2 or 3 分析:这道题目,实现比较容易,方法也不少,但要用最小的空间复杂度来看的话, 和充分考虑一下数据的下标和数据元素值的特点,比如如果把第 i 个位置放的值是 i,不是的情况做交换,去循环对比. 时间复杂度O(n),空间复杂度可到常量级 测试代码如下: public static void main(String[] args…
在一个SQL Server表中一行的多个列找出最大值 有时候我们需要从多个相同的列里(这些列的数据类型相同)找出最大的那个值,并显示 这里给出一个例子 IF (OBJECT_ID('tempdb..##TestTable') IS NOT NULL) DROP TABLE ##TestTable CREATE TABLE ##TestTable ( ID ,) PRIMARY KEY, Name ), UpdateByApp1Date DATETIME, UpdateByApp2Date DAT…
当做到某些功能的时候,使用Set能够快速方便地将需要的类型以集合类型保存在一个变量中,Set是最简单的一种集合,集合中的对象不按特定的方式排序,并且没有重复对象. //两个Set比较找出交集.差集.并集 public static void setCompare() { Set<Integer> result = new HashSet<Integer>(); Set<Integer> set1 = new HashSet<Integer>() {{ add…
做到了这个题,感觉网上的博客是真的水,只有kuangbin大神一句话就点醒了我,所以我写这篇博客是为了让最短路的入门者尽快脱坑...... 本题思路:本题是最短路的变形,要求出最短路中的最大跳跃距离,基本思路与最短路一样,dist数组为当前点到源结点最短路的最大距离,这样的话我们知道只需要改变松弛方程就可以了,每次我们选取一个最小值dist[ k ],那么接下来我们就需要将与结点k相邻的结点都更新,如何更新呢,当然是选取之前所走路中的最大值和现在需要走的路中的值的最大值啦即dist[ j ] =…
//数组中排序    int in[] = {1,6,5,8,9};    Arrays.sort(in);    for(int i=0;i<in.length;i++){       System.out.println(in[i]);   }    //数组中取最大值,最小值    int arr[] = {6,3,8,5,7,4,1};          int min2 = arr[0];          int temp = 0;          for(int i=1;i<a…
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 30840   Accepted: 8191 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand…
题目链接: http://poj.org/problem?id=1797 Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has buil…