Greedy title

Dynamic programming ideas:

https://blog.csdn.net/huang1600301017/article/details/81022658

Greedy algorithm training:

https://blog.csdn.net/EliminatedAcmer/article/details/88402667

 

https://blog.csdn.net/gyhguoge01234/article/details/78156417

 

 

Thinking: Johnson algorithm:
1: divided into two tasks, task A class t1 <t2, the task class B t1> t2 =
2: two tasks are ordered by class A wherein Ascending t1, t2 in descending order according to category B
3: merging two types, the type of task to the second task after the first class, then the sequence of tasks best
4: through all the tasks, calculate total time
under say I understand it, it is definitely a job for t1 been running, then there will be idle for the job t2 and piled two kinds of circumstances, in accordance with the minimum time-consuming, apparently not allowed idle situation, so the first job t1 <t2 t1 according to increasing order of execution, thus Availability does not appear, to the remaining operations is t1> = t2 the job, then the job is still in the buildup, t2, when for each job, since t1 = t2, t2 job stacked jobs> Processed will getting smaller and smaller, so the first will be the first implementation of a large t2, t2 or greater increase retention in the final will be time-consuming, so then t1> = t2 job execution in order of decreasing t2, so it is the smallest time consuming.

/ * 
Johnson algorithm: 
1: divided into two tasks, task A class t1 <t2, the task class B t1> t2 = 
2: two tasks are ordered by class A wherein Ascending t1, t2 in descending order according to category B 
3: merge two, the second type behind the first type of task to task, at this time the sequence of tasks best 
4: through all tasks, computing total time 
* / 
#include <the iostream> 
#include <algorithm> 
 the using  namespace STD; 
typedef Long  Long LL; 
 
struct Node {
     int Time;
     int ID;
     BOOL Group;
     BOOL  operator <( const Node & P) {
         return Time < p.time; 
    } 
}; 
 
const  int MAX_N=50005;
int n;
int a[MAX_N],b[MAX_N];
node d[MAX_N];
int best[MAX_N];
 
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i]>>b[i];
    for(int i=0;i<n;i++){
        d[i].time=a[i]>b[i]?b[i]:a[i];
        d[i].id=i;
        d[i].group=a[i]<=b[i];
    }
    sort(d,d+n);
    int l=0,r=n-1;
    for(int i=0;i<n;i++)
        if(d[i].group) best[l++]=d[i].id;
        else    best[r--]=d[i].id;
    LL sum=0,ans=0;
    for(int i=0;i<n;i++)
    {
        sum+=a[best[i]];
        ans=max(ans,sum)+b[best[i]];
    }
    cout<<ans<<endl;
//    for(int i=0;i<n;i++)
//        printf("%d ",best[i]+1);
//    printf("\n");
    return 0;
} 

https://blog.csdn.net/qq_39382769/article/details/81396518

 

Guess you like

Origin www.cnblogs.com/Aiahtwo/p/11351377.html