Test instructions: There are n examination, for examination I, do not review it can test Si, review it can improve AI points per hour, every hour AI will reduce Di, that is, the continuous review of an account of an increase in the hours of the AI, Ai-di, Ai-2di ..., but the highest score of each exam is not more than 100 points, Given the test time of each exam, and the exam itself does not occupy the time, reasonable arrangement review plan, ask whether to let all exams are not less than 60 points, if possible, the total maximum is how much.
Ideas: More obvious greed, but it is difficult to think of the right greedy strategy. We divide the problem into two steps, all of which pass 60 points and the total score is the largest. For the first step, for not review scores less than 60 points of the subject, first review for a period of time to score 60 points, greedy from the test time to extend to find free time to review (once can not find free time, then no solution). For the second step, chronological order of the processing, for a time t, enumerate all the test time is greater than or equal to T of the account, find an account, so that review it to improve the highest score, then time t is used to review the course.
1 #pragmaComment (linker, "/stack:10240000,10240000")2 3#include <iostream>4#include <cstdio>5#include <algorithm>6#include <cstdlib>7#include <cstring>8#include <map>9#include <queue>Ten#include <deque> One#include <cmath> A#include <vector> -#include <ctime> -#include <cctype> the#include <Set> -#include <bitset> -#include <functional> -#include <numeric> +#include <stdexcept> -#include <utility> + A using namespacestd; at - #defineMem0 (a) memset (a, 0, sizeof (a)) - #defineMem_1 (a) memset (a,-1, sizeof (a)) - #defineLson L, M, RT << 1 - #defineRson m + 1, R, RT << 1 | 1 - #definedefine_m int m = (L + r) >> 1 in #defineRep_up0 (A, b) for (int a = 0; a < (b); a++) - #defineRep_up1 (A, b) for (int a = 1; a <= (b); a++) to #defineRep_down0 (A, b) for (int a = b-1; a >= 0; a--) + #defineRep_down1 (A, b) for (int a = b; a > 0; a--) - #defineAll (a) (a). Begin (), (a). End () the #defineLowbit (x) ((x) & (-(x))) * #defineCONSTRUCTINT4 (name, a, B, C, D) name (int a = 0, int b = 0, int c = 0, int d = 0): A (a), B (b), C (c), D (d) {} $ #defineCONSTRUCTINT3 (name, a, B, c) name (int a = 0, int b = 0, int c = 0): A (a), B (b), C (c) {}Panax Notoginseng #defineConstructInt2 (name, a, b) name (int a = 0, int b = 0): A (a), B (b) {} - #definePCHR (a) Putchar (a) the #definePstr (a) printf ("%s", a) + #defineSstr (a) scanf ("%s", a) A #defineSint (a) scanf ("%d", &a) the #defineSint2 (A, b) scanf ("%d%d", &a, &b) + #defineSint3 (A, B, c) scanf ("%d%d%d", &a, &b, &c) - #definePint (a) printf ("%d\n", a) $ #defineTest_print1 (a) cout << "var1 =" << a << Endl $ #defineTest_print2 (A, b) cout << "var1 =" << a << ", var2 =" << b << Endl - #defineTest_print3 (A, B, c) cout << "var1 =" << a << ", var2 =" << b << ", Var3 =" << c &L t;< Endl - thetypedefLong LongLL; -typedef pair<int,int>PII;Wuyitypedef vector<int>VI; the - Const intdx[8] = {0,0, -1,1,1,1, -1, -1}; Wu Const intdy[8] = {-1,1,0,0,1, -1,1, -1 }; - Const intMAXN = 3e4 +7; About Const intMD =10007; $ Const intINF = 1e9 +7; - ConstLL inf_l = 1e18 +7; - Const DoublePI = ACOs (-1.0); - Const DoubleEPS = 1e-4; A +template<classT>t gcd (t A, T b) {returnb==0? A:GCD (b,a%b);} thetemplate<classT>BOOLMax_update (T &a,ConstT &b) {if(B>a) {a = B;return true;}return false;} -template<classT>BOOLMin_update (T &a,ConstT &b) {if(B<a) {a = B;return true;}return false;} $template<classT>t condition (BOOLF, t A, T b) {returnF?a:b;} thetemplate<classT>voidCopy_arr (t a[], T b[],intN) {rep_up0 (i,n) a[i]=b[i];} the intMAKE_ID (intXintYintN) {returnX * n +y;} the the structNode { - intR, S, a, D; inNode (intR =0,ints =0,intA =0,intD =0): R (R), s (s), A (a), D (d) {} the BOOL operator< (ConstNode that)Const { the returnR <THAT.R; About } the }; theNode node[ -]; the BOOLocc[ +]; + - intMain () { the //freopen ("In.txt", "R", stdin);Bayi intN; the while(Cin >>N) { the intMaxt =0; - BOOLOK =true; - mem0 (OCC); the rep_up0 (i, n) { the intS, T, a, d, tmp =0; theCIN >> s >> T >> a >>D; theNode[i] =Node (t, S, a, d); - max_update (Maxt, t); the } theSort (node, node +n); the rep_up0 (i, n) {94 intCur =NODE[I].R; the while(Node[i].s < -) { the while(Occ[cur] && cur) cur--; the if(!cur | | node[i].a <=0) {98OK =false; About Break; - }101Occ[cur] =true;102Node[i].s + =node[i].a;103NODE[I].A-=node[i].d;104 } the if(!ok) Break;106 }107 rep_down1 (i, maxt) {108 if(!Occ[i]) {109 ints =0, p; the Rep_up0 (j, N) {111 if(NODE[J].R >=i) { the intDAT =node[j].a;113 if(Node[j].s + dat > -) dat = --Node[j].s; the if(Dat >s) { thes =dat; thep =J;117 }118 }119 } - if(s) {121Node[p].s + =s;122NODE[P].A-=node[p].d;123 }124 } the }126 intAns =0;127 rep_up0 (i, n) { -Ans + =Node[i].s;129 } the if(OK) cout << ans <<Endl;131 ElsePuts"You are unlucky"); the }133}View Code
[csu1603] Greed