程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> HDU 4620 Fruit Ninja Extreme(2013多校第二場 剪枝搜索)

HDU 4620 Fruit Ninja Extreme(2013多校第二場 剪枝搜索)

編輯:C++入門知識

今年暑假不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
12
1 3
3 4
0 7
3 8
15 19
15 20
10 15
8 18
6 12
5 10
4 14
2 9
0

Sample Output
5
 

 

 

import java.util.*;
import java.io.*;

public class Main {
	public static int m = 0;

	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedInputStream(System.in));
		while (sc.hasNextInt()) {
			int k = sc.nextInt();
			if (k == 0)
				System.exit(0);
			int start[] = new int[k];
			int end[] = new int[k];
			for (int i = 0; i < k; i++) {
				start[i] = sc.nextInt();
				end[i] = sc.nextInt();
			}
			for (int i = 0; i < k; i++) {
				for (int j = 0; j < k; j++) {
					if (end[j] > end[i]) {
						int t = end[j];
						end[j] = end[i];
						end[i] = t;
						int m = start[j];
						start[j] = start[i];
						start[i] = m;
					}
				}
			}
			int count = 1;
			int num = end[0];
			for (int i = 0; i < k; i++) {
				if (start[i] >= num) {
					count++;
					num = end[i];
				}
			}
			System.out.println(count);
		}
	}
}

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved