Codeforces Round #431 (Div. 1) B. Rooter's Song(模拟)
来源:互联网 发布:linux数据库备份命令 编辑:程序博客网 时间:2024/06/15 05:33
题目链接:http://codeforces.com/contest/848/problem/B
很容易能看出来,相遇的情况只有在 y-t=x-t 的情况下才会成立,然后,按照x的坐标排序,从左向右模拟碰撞的情况即可,本代码用了一个循环队列模拟。
代码:
#include<bits/stdc++.h>#define xx first#define yy second#define mp make_pairusing namespace std;const int MAXN=1e5+5;const int ZERO=2e5+5000;int n,w,h;struct node{int id,x,t;node(){}node(int _id,int _x,int _t):id(_id),x(_x),t(_t){}bool operator < (const node &a)const {return x<a.x;}}X[MAXN];vector<node> Y[MAXN*4];int cnt[MAXN*4];pair<int,int> ans[MAXN];int main(){//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);scanf("%d%d%d",&n,&w,&h);int tot=0;for(int i=1;i<=n;i++){int g,p,t;scanf("%d%d%d",&g,&p,&t);if(g==1){X[++tot]=node(i,p,t);}else{Y[p-t+ZERO].push_back(node(i,p,t));}}sort(X+1,X+1+tot);for(int i=0;i<4*MAXN;i++){sort(Y[i].begin(),Y[i].end());}for(int i=1;i<=tot;i++){int pos=X[i].x-X[i].t+ZERO;int sz=Y[pos].size();if(sz){int en=((sz-cnt[pos]-1)%sz+sz)%sz;swap(Y[pos][en].id,X[i].id);cnt[pos]++;}//printf("%d\n",X[i].id);ans[X[i].id]=mp(X[i].x,h);}for(int i=0;i<4*MAXN;i++){int sz=Y[i].size();for(int j=0;j<sz;j++){int pos=(((sz-cnt[i]-1)%sz+sz)%sz+j+1)%sz;ans[Y[i][pos].id]=mp(w,Y[i][j].x);}}for(int i=1;i<=n;i++){printf("%d %d\n",ans[i].xx,ans[i].yy);}return 0;}
阅读全文
0 0
- Codeforces Round #431 (Div. 1) B. Rooter's Song(模拟)
- Codeforces Round #431 (Div. 2) D Rooter's Song
- Codeforces Round #431 (Div. 2) D. Rooter's Song
- Codeforces Round #431 (Div. 2) (Codeforces 849D) D. Rooter's Song
- Codeforces 848B Rooter's Song
- CodeForces #431 849D Rooter's Song 技巧题
- Codeforces 849 D. Rooter's Song (技巧)
- Codeforces849D Rooter's Song
- Codeforces Round #225 (Div. 1) B 模拟:
- Codeforces Round #229 (Div. 2) B. Inna, Dima and Song
- Codeforces Round #229 (Div. 2) B. Inna, Dima and Song
- Codeforces Round #229 (Div. 2)B. Inna, Dima and Song
- Codeforces Round #229 (Div. 2) B. Inna, Dima and Song
- Codeforces Round #229 (Div. 2)B. Inna, Dima and Song
- Codeforces Round #323 (Div. 2) B. Robot's Task(模拟)
- Codeforces Round #339 (Div. 2)-B. Gena's Code(字符串模拟)
- Codeforces Round #343 (Div. 2) -B. Far Relative’s Problem(模拟)
- Codeforces Round #387 (Div. 2)B. Mammoth's Genome Decoding(简单模拟)
- 小白成长记——Android进阶之布局优化
- 大话设计模式之二:在visual studio调用子工程
- js错误码
- 第二篇
- 自定义View之自定义标题栏
- Codeforces Round #431 (Div. 1) B. Rooter's Song(模拟)
- jsday09(table综合练习 通过指针操作数组 部分正则验证)
- leetcode 275. H-Index II
- HttpSession与Hibernate中Session的区别
- CVE-2014-6332浅析-Internet Explorer整数溢出漏洞
- sysctl.conf文件详解
- CodeForces 849B Tell Your World 点线
- HTML5中的data-属性
- 学习shell的知识结构图