Codeforces Round #154 (Div. 2)

转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 

唔,又玩脱了,哎,太弱

A:水题

B:枚举+二分  nlgn

      维护两个指针 O(n)

C:范围不大,直接BFS可搞

      显然中间段不会左右移动,所以枚举某个中间行r,顺序为r1->r->r2,到了r2行才左右移动

       ps:卡了半天,从a->b与b->a是一样的,我为了简便,交换了下,sad

D:DP预处理出a的个数,dp[i][j]表示以i,j为右下角的矩阵里有多少个a

然后枚举两列,类似B题,维护两个指针


E:想歪了,显然x的优化级越高,完成的越早

   单调性啊,直接二分优化级,然后模拟一遍,记录x的完成时间

#include<iostream>  
#include<cstdio>  
#include<map>  
#include<cstring>  
#include<cmath>  
#include<vector>  
#include<algorithm>  
#include<set>  
#include<string>  
#include<queue>  
#define inf 1600005  
#define M 40  
#define N 200000 
#define maxn 300005  
#define eps 1e-12
#define zero(a) fabs(a)<eps  
#define Min(a,b) ((a)<(b)?(a):(b))  
#define Max(a,b) ((a)>(b)?(a):(b))  
#define pb(a) push_back(a)  
#define mp(a,b) make_pair(a,b)  
#define mem(a,b) memset(a,b,sizeof(a))  
#define LL unsigned long long  
#define MOD 1000000007
#define lson step<<1
#define rson step<<1|1
#define sqr(a) ((a)*(a))  
#define Key_value ch[ch[root][1]][0]  
#define test puts("OK");  
#define pi acos(-1.0)
#define lowbit(x) ((-(x))&(x))
#pragma comment(linker, "/STACK:1024000000,1024000000")  
using namespace std;
struct Node{
    int s,t,p,id;
    Node(){}
    Node(int _t,int _s,int _p,int _i):t(_t),s(_s),p(_p),id(_i){}
    bool operator<(const Node n)const{
        return t<n.t;
    }
};
struct work{
    int s,p,id;
    work(){}
    work(int _s,int _p,int _i):s(_s),p(_p),id(_i){}
    bool operator<(const work w)const{
        return p<w.p;
    }
};
vector<Node>a;
int n,pos;
LL T;
LL ans[50005];
LL check(int p){
    a[pos].p=p;
    vector<Node> b(a);
    sort(b.begin(), b.end());
    priority_queue<work>que;
    while(!que.empty()) que.pop();
    que.push(work(b[0].s,b[0].p,b[0].id));
    LL st=0;
    for(int i=1;i<n;i++){
        st=b[i-1].t;
        LL tmp=b[i].t-b[i-1].t;
        while(!que.empty()&&tmp){
            work u=que.top();
            que.pop();
            LL cnt=min(tmp,(LL)u.s);
            st+=cnt;
            u.s-=cnt;
            tmp-=cnt;
            if(u.s==0) ans[u.id]=st;
            else que.push(u);
        }
        st=b[i].t;
        que.push(work(b[i].s,b[i].p,b[i].id));
    }
    while(!que.empty()){
        work u=que.top();
        que.pop();
        st+=u.s;
        ans[u.id]=st;
    }
    return ans[pos];
}
int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    while(scanf("%d",&n)!=EOF){
        a.clear();
        for(int i=0;i<n;i++){
            int t,s,p;
            scanf("%d%d%d",&t,&s,&p);
            a.pb(Node(t,s,p,i));
            if(a[i].p==-1) pos=i;
        }
        scanf("%I64d",&T);
        int low=1,high=1e9,mid;
        while(low<=high){
            mid=(low+high)>>1;
            LL tmp=check(mid);
            if(tmp==T) break;
            if(tmp<T) high=mid-1;
            else low=mid+1;
        }
        printf("%d\n",mid);
        for(int i=0;i<n-1;i++) printf("%I64d ",ans[i]);
        printf("%I64d\n",ans[n-1]);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值