给你一个这样的图,那些点是舞者,他们每个人会在原地待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的更多相关文章

  1. 【Codeforces Round 431 (Div. 2) A B C D E五个题】

    先给出比赛地址啦,感觉这场比赛思维考察非常灵活而美妙. A. Odds and Ends ·述大意:      输入n(n<=100)表示长度为n的序列,接下来输入这个序列.询问是否可以将序列划 ...

  2. 【推导】【贪心】Codeforces Round #431 (Div. 1) A. From Y to Y

    题意:让你构造一个只包含小写字母的可重集,每次可以取两个元素,将它们合并,合并的代价是这两个元素各自的从‘a’到‘z’出现的次数之积的和. 给你K,你构造的可重集必须满足将所有元素合而为一以后,所消耗 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #431 (Div. 2) C

    From beginning till end, this message has been waiting to be conveyed. For a given unordered multise ...

  8. 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 ...

  9. 【Codeforces Round #431 (Div. 1) D.Shake It!】

    ·最小割和组合数放在了一起,产生了这道题目. 英文题,述大意:     一张初始化为仅有一个起点0,一个终点1和一条边的图.输入n,m表示n次操作(1<=n,m<=50),每次操作是任选一 ...

随机推荐

  1. ASP.NET MVC各个版本区别

    ASP.NET MVC 1 view接收用户输入,把命令传到controller controller处理命令,更新model model被更新后,会通知view需要update view更新后向用户 ...

  2. oracle 的number数据类型

    NUMBER类型细讲:Oracle number datatype 语法:NUMBER[(precision [, scale])]简称:precision --> p      scale   ...

  3. perl HTML::LinkExtor模块(1)

    use LWP::Simple; use HTML::LinkExtor; $html = get("http://www.baidu.com"); $link = HTML::L ...

  4. Vue组件-动态组件

    动态组件 通过使用保留的 <component> 元素,动态地绑定到它的 is 特性,可以让多个组件使用同一个挂载点,并动态切换: <div id="app6"& ...

  5. python基础===基于requests模块上的协程【trip】

    今天看博客get了一个有趣的模块,叫做 trip     #(pip install  trip) 兼容2.7版本 基于两大依赖包:TRIP: Tornado & Requests In Pa ...

  6. 内核抢占实现(preempt) 【转】

    转自:http://blog.chinaunix.net/uid-12461657-id-3353217.html 一.什么叫抢占所谓抢占,说白了就是进程切换.linux的用户空间,进程A在执行中,来 ...

  7. sunos kernel src

    https://github.com/eocallaghan/AuroraUX-SunOS https://github.com/zoyanhui/coroutine-libtask https:// ...

  8. C基础 算法实现层面套路

    引言 - 从实践狗讲起 理论到实践(有了算法到实现) 中间有很多过程. 算法方面本人啥也不懂, 只能说说实现方面. 例如下面 一个普通的插入排序. // // 插入排序默认从大到小 // extern ...

  9. MySQL:按后缀缀批量删除表格

    Select CONCAT( 'drop table ', table_name, ';' ) FROM information_schema.tables Where table_schema='s ...

  10. Mysql 数据库学习笔记04 函数

    一.创建自定义函数 * 使用自定义函数,可以返回字符串.整型.实数或者其他类型: create [aggregate] function 名称 (参数列表) return type begin //函 ...