最新消息:最新信息可以到系统基本设置里填写,如果不想要这一栏可以修改head.htm,将第53行到55行删除即可

(杭电1406)完数

创意新鲜 dedesos.com

题目描述
there is a collection of n activities e={1,2,..,n}, each of which requires the same resource, such as
a lecture venue, etc., and only one activity at a time use this resource. each activity i has a start
time of si and an end time of fi and si fi. if the activity i is selected, it occupies resources within
the time interval [si,fi). if the interval [si,fi) does not intersect the interval [sj,fj), then the activity i is
said to be compatible with the activity j. that is, when fi =sj or fj =si, the activity i is compatible
with the activity j . choose the largest collection of activities that are compatible with each other.
输入格式
the first line is an integer n;
the next n line, two integers per line, si and fi.
输出格式
excluding mutual and compatible maximum active number.
样例输入1
4
1 3
4 6
2 5
1 7
样例输出1
2




















数据范围与提示
1 =n =1000


 

这道题解法与杭电今年暑假不ac解法相同,采用贪心法

代码实例

#include stdio.h 
struct huodong
 int begin;
 int end;
} j[1002];
int main
 int n,i,j,sum,temp;
 sum = 1;
 scanf
 scanf;
 for
 for
 if
 temp = j[j].end;
 j[j].end = j[j+1].end;
 j[j+1].end = temp;
 temp = j[j].begin;
 j[j].begin = j[j+1].begin;
 j[j+1].begin = temp;
 temp = j[0].end;
 for
 if
 sum++;
 temp = j[i].end;
 printf;
 return 0;
}

 

    与本文相关的文章

    网友最新评论