Jim and the Skyscrapers
来源:互联网 发布:淘宝企业c店开店流程 编辑:程序博客网 时间:2024/05/16 02:09
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the
environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another
skyscraper of same height! So much fun! But unfortunately, new skyscrapers have been built recently.
Let us describe the problem in one dimensional space. We have in total skyscrapers aligned from left to right. The
skyscraper has a height of . A flying route can be described as with , which means, Jim starts his HZ42 at the top of
the skyscraper and lands on the skyscraper . Since HZ42 can only fly horizontally, Jim will remain at the height only. Thus
the path can be valid, only if each of the skyscrapers is not strictly greater than and if the height of
the skyscraper he starts from and arrives on have the same height. Formally, is valid iff and .
Help Jim in counting the number of valid paths represented by ordered pairs .
Input Format
The first line contains , the number of skyscrapers. The next line contains space separated integers representing the
heights of the skyscrapers.
Output Format
Print an integer that denotes the number of valid routes.
Constraints
and no skyscraper will have height greater than and lesser than .
Sample Input #00
63
2 1 2 3 3
Sample Output #00
8
Sample Input #01
31
1 000 1
Sample Output #01
0
Explanation
First testcase: (1, 5), (1, 6) (5, 6) and (2, 4) and the routes in the opposite directions are the only valid routes.
Second testcase: (1, 3) and (3, 1) could have been valid, if there wasn't a big skyscraper with height 1000 between them.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class skyscrapers {
public static void main(String[] args) throws IOException {
String str = null;
Integer num = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Input the Skyscrapers number and highs");
num = Integer.parseInt(br.readLine());
str = br.readLine();
System.out.println("Skyscrapers num: " + num + "\n" + "highs: " + str);
System.out.println("***************************************************");
// get the Skyscrapers highs
List<Integer> skyscraperLisy = new ArrayList<Integer>();
List<Integer> comskyscraperLisy = new ArrayList<Integer>();
String[] a = str.split(" +");
for (int i = 0; i < a.length; i++) {
skyscraperLisy.add(Integer.valueOf(a[i]).intValue());
}
// Iterator遍历
comskyscraperLisy = skyscraperLisy;
Iterator<Integer> iterator = skyscraperLisy.iterator();
int HZ42 = 0;
while (iterator.hasNext()) {
int i = (Integer) iterator.next();
System.out.println("skyscraperLisy " + "i:" + i);
Iterator<Integer> comIterator = comskyscraperLisy.iterator();
while (comIterator.hasNext()) {
int beCompare = (Integer) comIterator.next();
if (i >= beCompare) {
if (i == beCompare) {
System.out.println("i:" + i + "beCompare:" + beCompare
+ "can fly");
HZ42++;
}
} else {
System.out.println("faied to fly" + "i:" + i + "beCompare:"
+ beCompare);
continue;
}
}
if (HZ42 > 0) {
HZ42 = HZ42 - 1;
System.out.println("-----------" + "HZ42:" + HZ42
+ "-----------");
}
}
HZ42 = HZ42 * 2;
System.out.println("the HZ42 has air line:" + HZ42 );
}
}
- Jim and the Skyscrapers
- The Adventures of Huckleberry Finn——3、Huck and Jim travel south
- [Hackerrank题目选做] Jim And Challenges
- Configuring Windows Time Service - Jim DeVries' Infrastructure and Technology Blog
- Jim Weirich Discusses Rake, the Ruby Make Tool
- Jim Weirich Discusses Rake, the Ruby Make Tool
- The Adventures of Huckleberry Finn——5、The plan to free Jim
- BNUOJ 1094 Skyscrapers
- SERC 2013 E Skyscrapers
- Skyscrapers 组合数学
- Skyscrapers Aren’t Scalable
- CF335E Counting Skyscrapers
- Introduction to Process Definition and Process Improvement -by Jim D. Hart
- Protect your applications against advanced reverse engineering and software cracking by AntiDebugLIB By Jim Charles
- [转]Orcle and SQL Functions (http://jim.blueidea.com/archives/2006/3715.shtml)
- [构造] UNR #1 Jakarta Skyscrapers
- 寫給JIM 的話
- 巨星陨落 - Jim Gary
- 在web项目中添加自定义配置文件
- MySQL主从复制与读写分离
- 用Maven创建第一个web项目
- 蓝桥杯<算法训练> 出现次数最多的整数 2015/03/19
- (hdu step 8.1.2)Train Problem I(站的基本应用——判断一个序列经过栈后是否能够得到第二个序列)
- Jim and the Skyscrapers
- 尽量不要使用塑料制品
- Android ActionBar完全解析,使用官方推荐的最佳导航栏(上)
- JVM自动内存管理机制分析
- joomla component学习笔记(一)--创建自己的组件
- 源码编译安装 MySQL 5.5.x
- MATLAB读写文件汇总
- keeper
- Spring控制器注解