Interval Intersections
来源:互联网 发布:iphone 改铃声 mac 编辑:程序博客网 时间:2024/05/16 15:01
Interval Intersections
Time Limit: 1000 MS Memory Limit: 65536 KbTotal Submission: 484 Accepted: 178Description
给定x 轴上n 个闭区间。去掉尽可能少的闭区间,使剩下的闭区间都不相交。给定n 个闭区间,编程计算去掉的最少闭区间数。
Input
多组测试数据。每组测试数据第一行是正整数n(n≤100),表示闭区间数。接下来的n行中,每行有2 个整数,分别表示闭区间的2个端点。
Output
输出每组测试数据的去掉的最小区间数,每组测试数据输出单独一行。
Sample Input
3
10 20
10 15
20 15
Sample Output
2
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <string>#include <algorithm>using namespace std;const int MAXN = 100 + 10;int start[MAXN], finish[MAXN];int main(){ int n; while(cin >> n) { memset(start, 0, sizeof start); memset(finish, 0, sizeof finish); for(int i = 0; i < n; i++) { cin >> start[i]; cin >> finish[i]; if(start[i] > finish[i]) swap(start[i], finish[i]); } int cnt; int selected; for(int i = 0; i < n; i++) { for(int j = 0; j + 1 < n; j++) { if(finish[j] > finish[j + 1]) { swap(finish[j], finish[j + 1]); swap(start[j], start[j + 1]); } } } selected = 0; cnt = 1; for(int i = 1; i < n; i++) { if(start[i] > finish[selected]) { selected = i; cnt++; } } cout << (n - cnt) << endl; } return 0;}
(贪心算法)
- Interval Intersections
- Counting Intersections
- interval
- INTERVAL
- interval
- HDU 5862 Counting Intersections
- HDU - 5862 Counting Intersections
- HDU 5862 Counting Intersections
- hdu5862Counting Intersections(树状数组)
- HDU 5862 Counting Intersections
- hdu5862 Counting Intersections
- HDU5862-Counting Intersections
- Counting Intersections HDU
- Codility -- Number-of-disc-intersections
- [codility]Number-of-disc-intersections
- sweeping line algorithm -- calculate line segment intersections
- 多校训练10&&HDU5862 Counting Intersections
- hdu5862Counting Intersections 扫描线+线段树
- Ogre中mesh的顶点数据与索引数据
- 本地mysql链接远程数据库
- 别浪费自己的高学历
- initWithNibName 和 loadNibNamed 的区别
- DOS命令之path
- Interval Intersections
- 静态网站全站搜索功能
- 【高手分享】熟知Win7系统(英文版)分区14个小步骤
- ORACLE数据库学习03
- php对应C hmac sha1算法 (OAuth 1.0 加密生成oauth_signature 需要)
- Java 单例模式详解
- [Pro.android.3][读书笔记]Android 03 理解Android资源 连载
- wcf 传送大数据,需要改配置文件app.config
- 01 背包的C实现