HDU 2037 今年暑假不AC

來源:互聯網
上載者:User
今年暑假不AC

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20752 Accepted Submission(s): 10848

Problem Description“今年暑假不AC?”
“是的。”
“那你幹什麼呢?”
“看世界盃呀,笨蛋!”
“@#$%^&*%...”

確實如此,世界盃來了,球迷的節日也來了,估計很多ACMer也會拋開電腦,奔向電視了。
作為球迷,一定想看盡量多的完整的比賽,當然,作為新時代的好青年,你一定還會看一些其它的節目,比如新聞聯播(永遠不要忘記關心國家大事)、非常6+7、超級女生,以及王小丫的《開心辭典》等等,假設你已經知道了所有你喜歡看的電視節目的轉播時間表,你會合理安排嗎?(目標是能看盡量多的完整節目)

Input輸入資料包含多個測試執行個體,每個測試執行個體的第一行只有一個整數n(n<=100),表示你喜歡看的節目的總數,然後是n行資料,每行包括兩個資料Ti_s,Ti_e (1<=i<=n),分別表示第i個節目的開始和結束時間,為了簡化問題,每個時間都用一個正整數表示。n=0表示輸入結束,不做處理。

Output對於每個測試執行個體,輸出能完整看到的電視節目的個數,每個測試執行個體的輸出佔一行。

Sample Input

121 33 40 73 815 1915 2010 158 186 125 104 142 90

Sample Output

5

 

 

import java.io.*;import java.util.*;public class Main {int n;public static void main(String[] args) {new Main().work();}void work(){Scanner sc=new Scanner(new BufferedInputStream(System.in));while(sc.hasNext()){n=sc.nextInt();if(n==0) break;Node[] node=new Node[n];for(int i=0;i<n;i++){int s=sc.nextInt();int e=sc.nextInt();node[i]=new Node(s,e);}Arrays.sort(node);int num=node[0].end;int ans=1;for(int i=0;i<n;i++){if(node[i].start>=num){ans++;num=node[i].end;}}System.out.println(ans);}}class Node implements Comparable<Node>{int start;int end;Node(int start,int end){this.start=start;this.end=end;}public int compareTo(Node o) {return this.end>o.end?1:-1;}}}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.