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.csdn.net/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
*/
时间: 2024-12-23 23:17:09

CSU 1603 Scheduling the final examination(贪心)的相关文章

CSUOJ 1603 Scheduling the final examination

1603: Scheduling the final examination Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 49  Solved: 15 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 subjec

CSU1603: Scheduling the final examination(贪心)

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

【BZOJ3721】PA2014 Final Bazarek 贪心

[BZOJ3721]PA2014 Final Bazarek Description 有n件商品,选出其中的k个,要求它们的总价为奇数,求最大可能的总价. Input 第一行一个整数n(1<=n<=1000000),表示商品数量.接下来一行有n个整数,表示每件商品的价格,范围在[1,10^9].接下来一行有一个整数m(1<=m<=1000000),表示询问数量.接下来m行,每行一个整数k[i](1<=k[i]<=n). Output 对于每个询问,输出一行表示保证奇数的

【BZOJ-3721】Final Bazarek 贪心

3721: PA2014 Final Bazarek Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 610  Solved: 243[Submit][Status][Discuss] Description 有n件商品,选出其中的k个,要求它们的总价为奇数,求最大可能的总价. Input 第一行一个整数n(1<=n<=1000000),表示商品数量.接下来一行有n个整数,表示每件商品的价格,范围在[1,10^9].接下来一行有一个整数m(1&l

hdu4442 Physical Examination(贪心)

这种样式的最优解问题一看就是贪心.如果一下不好看,那么可以按照由特殊到一般的思维方式,先看n==2时怎么选顺序(这种由特殊到一般的思维方式是思考很多问题的入口): 有两个队时,若先选第一个,则ans=a1+a2+b2*a1;若先选第二个,则ans=a2+a1+b1*a2;所以选择顺序就比b2*a1和b1*a2就好了. 那么当有n>2个队时,能不能也这么搞?当然可以,每次剩下那几个队没选,我就两两比,两两之间比较时,之前用的时间都要加上是和顺序无关的,顺序影响的只是b2*a1和b1*a2而已(如果

HDU 4442 Physical Examination (贪心+排序)

Physical Examination Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5985    Accepted Submission(s): 1682 Problem Description WANGPENG is a freshman. He is requested to have a physical examinati

BZOJ 3721 PA 2014 Final Bazarek 贪心

题目大意:有n件商品,选出其中的k个,要求它们的总价为奇数,求最大可能的总价. 思路:一个O(n)的贪心,先排序,然后O(n)预处理每个节点之前出现的最大奇数和偶数,和每一个节点之后出现的最小的奇数或者偶数,之后每个询问O(1)判断一下.注意初值. CODE: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 1000010 #d

BZOJ 3727 PA2014 Final Zadanie 贪心

题目大意:给定n个数,多次询问选择k个数使和为奇数的最大和 首先将所有数排序 对于每个询问,如果最大的k个数之和是奇数,那么答案显然是这k个数的和 如果最大的k个数之和是偶数,那么我可以将后k个数中最小的偶数换成前n-k个数中最大的奇数,或者将后k个数中最小的奇数换成前n-k个数中最大的偶数 二者取最优即可 无法如此做则输出-1 #include <cstdio> #include <cstring> #include <iostream> #include <a

HOJ 题目分类

转自:http://blog.sina.com.cn/s/blog_65f3869301011a1o.html ******************************************************************************* 简单题(包括枚举,二分查找,(复杂)模拟,基础数据结构(栈.队列),杂题等 ****************************************************************************