CSU 1603 Scheduling the final examination(贪心)

1603: Scheduling the final examination

Time Limit: 10 Sec   Memory Limit: 128 MB
Submit: 58   Solved: 18
[ Submit][ Status][ Web Board]

Description

For the most of the university students,what they most want is that they can obtain 60 points from the final examination of every subject. Now, final examination is coming. As an excellent programmer,you are asked for help. The full mark is 100, and it is need greater than or equal to 60 to pass subjects. Given the description of every subject, you should schedule the time of review to every subject in order to pass every subject and at the same time to obtain the higher total scores as possible.

Input

The input consists of multiple test cases. For each test case, the first line is an integer n (1<=n<=50), which is the number of subjects. Then n lines follow, each line has four integers si, ti, ai, di to describe the subject. si(0<=si<=100):the score that he can obtained without reviewing,ti(1<=ti<720):the time of examination,
ai(1<=ai<=40):the first hour reviewing on this subject will improve ai scores,di(0<=di<=4):the improving scores will decrease di every reviewing hour. For example,when ai = 10, di = 2, the first hour viewing will improve 10 scores , and the second hour viewing will only improve 8 scores.

Output

For each test case, to output in one line. If he can pass all the subjects, please output an integer which is the highest total scores, otherwise please output a string “you are unlucky”.

Sample Input

1
58 3 5 3
1
58 1 5 3
4
40 6 10 2
50 9 10 2
60 3 4 2
70 1 4 2
4
42 6 10 2
50 9 10 2
54 3 4 2
70 1 4 2
4
30 6 10 2
50 9 10 2
54 3 4 2
70 1 4 2

Sample Output

65
63
280
274
you are unlucky

HINT

Please noting: every subject’ full scores is 100. So when you get a result of one subject which is bigger than 100, you should regard the result as 100.


Source

参考了一位大神的博客,不过略有不同  http://blog.youkuaiyun.com/libin56842/article/details/45460823

需要注意的一点:a不一定是使分数提高a分数,应该与100-s取最小值

我给出的样例


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>


#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8

#define fre(i,a,b)  for(i = a; i <b; i++)
#define free(i,b,a) for(i = b; i >= a;i--)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define ssf(n)      scanf("%s", n)
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define bug         pf("Hi\n")

using namespace std;

#define INF 0x3f3f3f3f
#define N 1005

struct stud{
int s,t,a,d;
  bool operator < (const stud b)const
 {
 	 if(a==b.a) return t>b.t;
 	 return a<b.a;
 }
 void check(){ a=min(a,100-s);}
}f[N];

int cmp(stud s,stud ss)
{
	return s.t<ss.t;
}

int n;
int used[N];
int ans;

priority_queue<stud>q;

void solve()
{
	int i,j;
	stud cur,next;
	ans=0;
	while(!q.empty()) q.pop();
	fre(i,0,n)
	  {
	    q.push(f[i]);
	    ans+=f[i].s;
	  }

    while(!q.empty())
	{
		cur=q.top();
		q.pop();
		if(cur.a<=0) continue;
		for(i=cur.t;i>=1;i--)
			if(!used[i]) break;
		if(i==0) continue;
		used[i]=1;
		ans+=cur.a;
		cur.s+=cur.a;
		cur.a-=cur.d;
		cur.a=max(0,cur.a);
		cur.check();
		if(cur.a>0)
		q.push(cur);

	}

   printf("%d\n",ans);
}

int main()
{
	int i,j;
	while(~sf(n))
	{
		mem(used,0);
		fre(i,0,n)
		  {
		  	scanf("%d%d%d%d",&f[i].s,&f[i].t,&f[i].a,&f[i].d);
		  	f[i].check();
		  }

		sort(f,f+n,cmp);

		int flag=0;

		fre(i,0,n)
		{
		  while(f[i].s<60)
		  {

			if(f[i].a<=0) break;
            for(j=f[i].t;j>=1;j--)
				if(!used[j])
			      break;
			if(j==0) break;
			used[j]=1;
			f[i].s+=f[i].a;
			f[i].a-=f[i].d;
			f[i].a=max(f[i].a,0);
			f[i].check();
		  }
          if(f[i].s<60) flag=1;
          if(flag) break;
		}

	    if(flag)
		{
			printf("you are unlucky\n");
			continue;
		}
       solve();

	}
  return 0;
}

/*

2
80 1 15 15
90 1 20 10

185
*/





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值