【推导】【分类讨论】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),每次操作是任选一 ...
随机推荐
- centos 搭建 ss
download:https://files.cnblogs.com/files/xishaonian/ShadowsocksR-4.7.0-win.7z 使用方法:使用root用户登录,运行以下命令 ...
- Python3 面向对象编程
小案例: #!/usr/bin/env python # _*_ coding:utf-8 _*_ # Author:Bert import sys class Role(object): n=&qu ...
- C++学习之路(四):线程安全的单例模式
(一)简单介绍 单例模式分为两种类型:懒汉模式和饿汉模式. 懒汉模式:在实际类对象被调用时才会产生一个新的类实例,并在之后返回这个实例.多线程环境下,多线程可能会同时调用接口函数创建新的实例,为了防止 ...
- skb管理函数之alloc_skb、dev_alloc_skb、kfree_skb、dev_kfree_skb、consume_skb
alloc_skb--分配skb dev_alloc_skb--分配skb,通常被设备驱动用在中断上下文中,它是alloc_skb的封装函数,因为在中断处理函数中被调用,因此要求原子操作(GFP_AT ...
- [device tree] interrupt
Specifying interrupt information for devices ============================================ 1) Interru ...
- perl 函数参数传递与返回值(一)
perl 函数参数传递与返回值(一) http://www.cnblogs.com/tobecrazy/archive/2013/06/11/3131887.html
- [c++,bson] linux 使用 BSON 编程[www]
[c++,bson] linux 使用 BSON 编程 http://blog.chinaunix.net/uid-28595538-id-4987410.html 1.js db=db.getSib ...
- JDBC数据源连接池(1)---DBCP
何为数据源呢?也就是数据的来源.我在前面的一篇文章<JDBC原生数据库连接>中,采用了mysql数据库,数据来源于mysql,那么mysql就是一种数据源.在实际工作中,除了mysql,往 ...
- thinkphp模板常用的方法
thinkphp模板我是看了3.2的文档,对里面的东西过了一遍,然后在写到需要用到模板的东西的时候就有印象,有的能直接回顾,但是有的就可能只知道有这个东西,但是不知道怎么用,所以就重新查手册,这个的话 ...
- 前趋图和PV操作