【推导】【分类讨论】Codeforces Round #431 (Div. 1) B. Rooter's Song

给你一个这样的图,那些点是舞者,他们每个人会在原地待ti时间之后,以每秒1m的速度向前移动,到边界以后停止。只不过有时候会碰撞,碰撞之后的转向是这样哒:

让你输出每个人的停止位置坐标。
①将x轴上初始坐标记为(pi,0),y轴上的初始坐标记为(0,pi)。只有pi-ti相同的才有可能发生碰撞。于是可以按照这一点将人划分为很多组,不同组之间绝对不会互相影响。
②假设一组内每个人都不会发生碰撞,那么所有的路线交叉点都是碰撞点。所以碰撞次数可能达到n^2次,暴力不可行。
③对于一组内,形成了一个网格图,每个人往哪走其实可以O(1)推算。

如图这是同一组内的情况,可以看到,对于x轴上的初始点,它走到的位置只与其右侧的竖线数和上方的横线数的大小关系有关。y轴上的初始点同理可得。
于是对于一组内,可以把x轴上的和y轴上的分别按p从小到大排序,然后讨论一下就能获得答案啦。
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
struct Point{
int p,id;
Point(const int &p,const int &id){
this->p=p;
this->id=id;
}
Point(){}
};
bool cmp(const Point &a,const Point &b){
return a.p<b.p;
}
vector<Point>v[200005][2];
typedef pair<int,int> pii;
pii anss[100005];
int n,w,h;
int main(){
//freopen("b.in","r",stdin);
int op,P,K;
scanf("%d%d%d",&n,&w,&h);
for(int i=1;i<=n;++i){
scanf("%d%d%d",&op,&P,&K);
v[P-K+100000][op-1].push_back(Point(P,i));
}
for(int i=1;i<200000;++i){
sort(v[i][0].begin(),v[i][0].end(),cmp);
sort(v[i][1].begin(),v[i][1].end(),cmp);
for(int j=0;j<v[i][0].size();++j){
if(v[i][0].size()-j-1>=v[i][1].size()){
anss[v[i][0][j].id]=make_pair(v[i][0][j+v[i][1].size()].p,h);
}
else{
anss[v[i][0][j].id]=make_pair(w,v[i][1][v[i][0].size()-1-j].p);
}
}
for(int j=0;j<v[i][1].size();++j){
if(v[i][0].size()>=v[i][1].size()-j){
anss[v[i][1][j].id]=make_pair(v[i][0][v[i][1].size()-1-j].p,h);
}
else{
anss[v[i][1][j].id]=make_pair(w,v[i][1][j+v[i][0].size()].p);
}
}
}
for(int i=1;i<=n;++i){
printf("%d %d\n",anss[i].first,anss[i].second);
}
return 0;
}
【推导】【分类讨论】Codeforces Round #431 (Div. 1) B. Rooter's Song的更多相关文章
- 【Codeforces Round 431 (Div. 2) A B C D E五个题】
先给出比赛地址啦,感觉这场比赛思维考察非常灵活而美妙. A. Odds and Ends ·述大意: 输入n(n<=100)表示长度为n的序列,接下来输入这个序列.询问是否可以将序列划 ...
- 【推导】【贪心】Codeforces Round #431 (Div. 1) A. From Y to Y
题意:让你构造一个只包含小写字母的可重集,每次可以取两个元素,将它们合并,合并的代价是这两个元素各自的从‘a’到‘z’出现的次数之积的和. 给你K,你构造的可重集必须满足将所有元素合而为一以后,所消耗 ...
- Codeforces Round #431 (Div. 1)
A. From Y to Y time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #431 (Div. 2) B. Tell Your World
B. Tell Your World time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #431 (Div. 2) C. From Y to Y
题目: C. From Y to Y time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #431 (Div. 2)
A. Odds and Ends Where do odds begin, and where do they end? Where does hope emerge, and will they e ...
- Codeforces Round #431 (Div. 2) C
From beginning till end, this message has been waiting to be conveyed. For a given unordered multise ...
- Codeforces Round #431 (Div. 2) B
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a c ...
- 【Codeforces Round #431 (Div. 1) D.Shake It!】
·最小割和组合数放在了一起,产生了这道题目. 英文题,述大意: 一张初始化为仅有一个起点0,一个终点1和一条边的图.输入n,m表示n次操作(1<=n,m<=50),每次操作是任选一 ...
随机推荐
- mysql中的enum型
enum设置后 值只能是给出的值中的其中一个 mysql> create table enum(e enum('1','2','3','4','5','6','7','8','9','10')) ...
- sublime在搜索的时候排除js文件
代码审计的时候sublime是一个神器.所以.... Ctrl + Shift + F /home/i3ekr/Desktop/coding/phpcms,*.php 这样就可以直接搜索所有的php文 ...
- java===java基础学习(15)---抽象,接口
抽象 //这就是一个抽象类 abstract class Animal { String name; int age; abstract public void cry(); } //当一个类继承的父 ...
- Linux内核【链表】整理笔记(2) 【转】
转自:http://blog.chinaunix.net/uid-23069658-id-4725279.html 关于链表我们更多时候是对其进行遍历的需求,上一篇博文里我们主要认识了一下和链表操作比 ...
- linux 系统调用fork()
头文件: #include<unistd.h> #include<sys/types.h> 函数原型: pid_t fork( void); (pid_t 是一个宏定义,其实质 ...
- SQL语句获取时间的方法
1. 当前系统日期.时间select getdate() 2. dateadd 在向指定日期加上一段时间的基础上,返回新的 datetime 值例如:向日期加上2天select dateadd(day ...
- [bugfix]copy属性参数将NSMutableArray变为NSArray类型
问题:NSMutableArray 声明为 copy 属性参数后即使接受NSMutableArray变量依然为NSArray变量 测试: 属性申明为: 1 @property (nonatomic, ...
- Fastcgi协议定义解释与说明
1 响应格式如(十六进制方式显示) 序列 0 1 2 3 4 5 6 7 ... 数值 01 06 00 01 01 1D 03 00... 序列0(值01)为version,固定取1即可序列1(值0 ...
- Find Peak Element——二分查找的变形
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
- vConsole ~ 移动开发调试工具
在开发移动端项目时,有时候在PC端好好的,但是到了手机上出bug,很难调试,这时候可以用vConsole调试工具 使用方式 1.直接引入 <script src="vconsole.m ...