更新时间2018-10-31 12:25:55
/*503.事件安排 (10分)
题目内容:
小张最近很忙,记事本里有n件事情等待处理,每件事处理完毕后,能得到不同的奖励,而且都有一个截止日。一件事处理需要一整天
时间,并且小张不能同时干其他事情。请你替小张安排一个事情处理的时间表,争取获得最大的奖励。
输入描述
第一行输入整数n,表示n个事情。随后输入n行,每行包括一个事情的截止日(不大于n)和处理收益。
输出描述
输出最大的总收益。
输入样例
5
2 5
2 7
2 6
2 8
3 3
输出样例
18
*/
#include <stdio.h>
#include <algorithm>
using namespace std;
#define MAX 100
typedef struct TAction {
int id;
int s;
int e;
};
bool cmp (const TAction a, const TAction b)
{
return a.e < b.e;
}
TAction GreedyAction(TAction B[],TAction A[], int n)
{
int i,j;
sort(B,B+n,cmp);
A[0]=B[0];
i=1;
j=1;
while(i<n){
if ( B[i].s> A[j-1].e)
A[j++]= B[i];
i++; }
return A[j++];
}
int main()
{
int n,i,j;
TAction B[MAX];
TAction A[MAX];
scanf("%d", &n);
for(int i = 1; i <= n; i++)
scanf("%d %d", &B[i],&A[i]);
printf("%d ",GreedyAction(B,A,n));
}
/*设计一个点的类模板,使用包含的方法设计线段类模板,要求演示构造函数和复制构造函数的设计方法,
并用主程序验证之。*/
#include <iostream>
using namespace std;
template <class T>
class Point
{
public:
T x;T y;
Point(T a=0, T b=0)
{
x=a;
y=b;
}
void show()
{
cout<<"x = "<<x<<", y = "<<y<<endl;
}
};
template <class T>
class Line:public Point
{
protected:
Point p1,p2;
public:
Line(T a,T b,T c,T d)
{
p1.x=a;
p1.y=b;
p2.x=c;
p2.y=d;
}
Line(const Line &);
void show()
{
cout<<"("<< p1.x<<", "<<p1.y<<"); ("<<p2.x<<", "<<p2.y<<")"<<endl;
}
};
template Line::Line(const Line &t)
{
p1=t.p1;
p2=t.p2;
}
int main()
{
Line J1(5,6,7,8);
cout<<"J1 : ";J1.show();
Line J2(J1);
cout<<"J2 : ";J2.show();
return 0;
}
最好是有邮箱的形式,这里不好弄。
我可以帮你修改,你打算出多少
没看懂没看懂没看懂没看懂没看懂