【HNOI2011】【BZOJ2336】任务调度

来源:互联网 发布:黑马程序员全套视频 编辑:程序博客网 时间:2024/06/05 05:53

Description
这里写图片描述
Input
Output
Sample Input
Sample Output
HINT

无数据,请不要提交!

Source

Day2

其实早就有数据了.
我的退火跑的超级慢…强行卡过速度倒数第一
在Codevs上测单点还会TLE…
调的我快哭了
(但是好理解而且写的短不是吗

#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<ctime>#include<algorithm>#define MAXN 1010#define MAXINT 0x7fffffffusing namespace std;int n,ans=MAXINT;int t[MAXN],a[MAXN],b[MAXN];int staa[MAXN],stab[MAXN],sta[MAXN],topa,topb,top;bool cmpa(int A,int B){    return ((b[A]>b[B])||(b[A]==b[B]&&a[A]<=a[B]));}bool cmpb(int A,int B){    return ((a[A]>a[B])||(a[A]==a[B]&&b[A]<=b[B]));}void solve(){    int tmp=MAXINT,suma=0,sumb=0,topa=0,topb=0;    for (int i=1;i<=n;i++)        if (t[i]==1)    staa[++topa]=i,suma+=a[i];        else    stab[++topb]=i,sumb+=b[i];    sort(staa+1,staa+topa+1,cmpa);sort(stab+1,stab+topb+1,cmpb);    double T=20000;    while (T>0.1)    {        int tima=suma,timb=sumb,temp=0,x1=0,y1=0,x2=0,y2=0;        if (topa)   x1=rand()%topa+1,y1=rand()%topa+1;        if (topb)   x2=rand()%topb+1,y2=rand()%topb+1;        swap(staa[x1],staa[y1]),swap(stab[x2],stab[y2]);        for (int i=1;i<=topa;i++)    temp+=a[staa[i]],timb=max(temp,timb)+b[staa[i]];        temp=0;        for (int i=1;i<=topb;i++)    temp+=b[stab[i]],tima=max(temp,tima)+a[stab[i]];        temp=max(tima,timb);        if (temp<=tmp||(temp>tmp&&rand()%10000>T)) tmp=temp;        else    swap(staa[x1],staa[y1]),swap(stab[x2],stab[y2]);        T*=0.995;    }    ans=min(ans,tmp);}void divide(int x){    if (x>top)   {solve();return;}    t[sta[x]]=1;    if (rand()%32767<20000)  divide(x+1);    t[sta[x]]=2;    if (rand()%32767<20000)  divide(x+1);}int main(){    scanf("%d",&n);    for (int i=1;i<=n;i++)    {        scanf("%d%d%d",&t[i],&a[i],&b[i]);        if (t[i]==3)    sta[++top]=i;    }    for (int i=1;i<=1000;i++)    divide(1);    cout<<ans<<endl;}
0 0
原创粉丝点击