Codeforces Round #154 (Div. 2)
2012-12-09 22:46
435 查看
转载请注明出处,谢谢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的完成时间
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; }
相关文章推荐
- 单调队列1004 Codeforces Round #154 (Div. 2) 253D. Table with Letters - 2
- [Codeforces Round #154 (Div. 2)]A. Boys and Girls
- Codeforces Round #154 (Div. 2) 总结
- Codeforces Round #154 (Div. 2)——B
- Codeforces Round #154 (Div. 2)
- Codeforces Round #154 (Div. 2) / 253A Boys and Girls(贪心)
- Codeforces Round #154 (Div. 2) : B
- 别样的动态规划 Codeforces Round #154 (Div. 2)——B
- Codeforces Round #154 (Div. 2)
- Codeforces Round #154 (Div. 2)
- Codeforces Round #154 (Div. 2)
- Codeforces Round #154 (Div. 2) A. Boys and Girls
- Codeforces Round #154 (Div. 2)
- Codeforces Round #154 (Div. 2)
- Codeforces Beta Round #69 (Div. 2 Only) E题
- Codeforces Round #427 (Div. 2)B. The number on the board
- Codeforces Round #258 (Div. 2)
- Codeforces Round #191 (Div. 2) D
- Codeforces Round #379 (Div. 2) E Anton and Tree
- Codeforces Round #226 div2(待更新)