atcoder之A Mountaineer,atcodermountaineer

來源:互聯網
上載者:User

atcoder之A Mountaineer,atcodermountaineer

Time limit : 2sec / Stack limit : 256MB / Memory limit : 256MB

Problem

Dave is a mountaineer. He is now climbing a range of mountains.

On this mountains, there are N huts located on a straight lining from east to west..

The huts are numbered sequentially from 1 to N. The west most hut is 1, the east most hut is N. The i-th hut is located at an elevation of hi meters.

Dave wants to know how many huts he can look down and see from each hut.

He can see the j-th hut from the i-th hut if all huts between the i-th hut and the j-th hut including the j-th one are located at equal or lower elevation than hi.

Note that the i-th hut itself is not included in the hut he can see from the i-th hut.

Input

The input will be given in the following format from the Standard Input.

Nh1h2:hN
  • On the first line, you will be given N(1≦N≦105), the number of huts.
  • Then N lines follow, each of which contains hi(1≦hi≦105) the elevation of the i-th hut.
Achievements and Points

Your answer will be checked for two levels.

  • When you pass every test case which satisfies 1≦N≦3,000, you will be awarded 30 points.
  • In addition, if you pass all the rest test cases which satisfy 1≦N≦105, you will be awarded 70 more points, summed up to 100points.
Output

On the i-th line, output the number of huts Dave can see from the i-th hut. Make sure to insert a line break at the end of the output.

Input Example 1
  1. 3
  2. 1
  3. 2
  4. 3
Output Example 1
  1. 0
  2. 1
  3. 2

From each hut he can see every huts on the west.

Input Example 2
  1. 5
  2. 1
  3. 2
  4. 3
  5. 2
  6. 1
Output Example 2
  1. 0
  2. 1
  3. 4
  4. 1
  5. 0

From the 1st and 5th hut he can't see any other huts.

From the 2nd hut he can only see the 1st hut.

From the 4th hut he can only see the 5th hut.

From the 3rd hut he can see every other huts.

Input Example 3
  1. 5
  2. 3
  3. 2
  4. 1
  5. 2
  6. 3
Output Example 3
  1. 4
  2. 2
  3. 0
  4. 2
  5. 4

Note that he can see the huts on the equal elevation.

Input Example 4
  1. 8
  2. 4
  3. 3
  4. 2
  5. 3
  6. 4
  7. 3
  8. 2
  9. 1
Output Example 4
  1. 7
  2. 2
  3. 0
  4. 2
  5. 7
  6. 2
  7. 1
  8. 0
思路:本題是個簡單題,我卻一直面對大資料時TLE,直接上TLE源碼
import java.util.Scanner; public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int count = sc.nextInt();int num[] = new int[count];int flag[] = new int[count];for (int i = 0; i < count; i++) {num[i] = sc.nextInt();}for (int i = 0; i < count; i++) {for (int j = i - 1; j >= 0 && num[i] >= num[j]; j--,flag[i]++);for (int j = i + 1; j < count && num[i] >= num[j]; j++,flag[i]++);System.out.println(flag[i]); }}}
下面是AC源碼,根據上面的源碼做了一定程度上的最佳化,從某種程度上來說,更改了部分思路,和https://oj.leetcode.com/problems/candy/有點像。
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int count = sc.nextInt();int num[] = new int[count];int[] back = new int[count];int[] forward = new int[count];for (int i = 0; i < count; i++) {num[i] = sc.nextInt();}for (int i = 0; i < count; i++) {for (int j = i - 1; j >= 0 && num[i] >= num[j]; back[i] = back[i]+ back[j] + 1, j = j - back[j] - 1);}for (int i = count - 1; i >= 0; i--) {for (int j = i + 1; j < count && num[i] >= num[j];forward[i] = forward[i]+ forward[j] + 1, j = j + forward[j] + 1);}for (int i = 0; i < count; i++) {System.out.println(back[i] + forward[i]);}}}



owl city--《hello seattle》中文歌詞

Hello Seattle, I am a mountaineer
In the hills and highlands
I fall asleep
in hospital parking lots
And awake in your house
Hello Seattle, I am a
manteray
Deep beneathe the blue waves
I'll crawl the sandy bottom of Puget
Sound
And construct a summer home
Hello Seattle, I am the cresant
moon
Shining down on your face
I will disguise myself as a sleeping
pill
And descend inside of you
Hello Seattle, I am a cold
seahorse
Feeling warm in your sand
I sing about the tide and the ocean
surf
Rolling in the evening breeze
Hello Seattle, I am an
albatross
On the docks and your boats
I sail above your inlets and
interstates
Through the rain and open wind
Hello Seattle, I am an old
lighthouse
Throwing beams of bright lights
Red in the morning, blue in the
evening sun
Taken heed from everyone
Hello Seattle, I am a
mountaineer
In the hills and highlands
I fall asleep in hospital parking
lots
Take me above your light
Carry me through the night
Hold me
secure in flight
Sing me to sleep tonight
Take me above your
light
Carry me through the night
Hold me secure in flight
Sing me to
sleep tonight
你好西雅圖,我是一個登山者
跋涉在丘陵與高原
在醫院停車場入睡
在你的嘴裡醒來
你好西雅圖,我是一隻蝠鱝(動物名,軟骨魚類中鰩目的蝠鱝科動物,跟巨翅飛魚長的一樣)
深深潛行在蔚藍海浪下
在普捷灣的海底沙灘蠕動
築造夏日的家園
你好西雅圖,我是一輪新月
在你的臉龐上灑下清光
我會變成一枚安眠藥
落入你心裏面
你好西雅圖,我是一隻冰冷的海馬
被你的沙粒溫暖
在傍晚的微風中搖晃
歌唱著潮汐和浪花
你好西雅圖,我是一隻信天翁
翱翔在碼頭和船舶之上
我在你的港灣和公路上滑翔
不管風吹雨打
你好西雅圖,我是古老的燈塔
放射出明亮的光
清晨絳紅,傍晚蒼藍
注視著每一個人
帶我飛向你的光芒
帶我穿越黑夜
帶我穩穩地飛翔
今夜用歌聲伴我入眠...餘下全文>>
 
(3/6) and mountaineer ,had been on a two -day climb away from the others and it warn 't until la

(1/6)(2/6)(3/6)two teenagers had to be saved from a steep mountain -side in Scotl and earlier today .they were member of a party of youngsters who were in the second week of a fortnight 's camping in the mountains .the two boys ,both from Birmingham ,had been with a party of ten others who ,with an experienced guide and mountaineer ,had been on a two -day climb away from the others and it warn 't until late yesterday afternoon that the alarm was raised and a search
今天早些時候從Scotl一個陡峭山坡上營救兩個少年。他們都是為期兩周青少年登山露營的成員,目前是第二周。兩個男孩都是來自伯明翰,一直是與十人的大部隊在一起,還有一個經驗豐富的嚮導登山員,他們倆已脫離他人單獨爬山兩天了,但直至昨天下午很晚才發出警報並開始搜尋。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.