【推导】【分类讨论】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),每次操作是任选一 ...
随机推荐
- Transformation(线段树+HDU4578+多种操作+鬼畜的代码)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4578 题目: 题意:n个数初始值为0,进行四种操作:1.将区间内的数字加c:2.将区间内的数字乘c:3 ...
- vue双向数据绑定的原理-object.defineProperty() 用法
有关双向数据绑定的原理 关于数据双向绑定的理解:利用了 Object.defineProperty() 这个方法重新给对象定义了新属性,在操作新属性分别为为获取属性值(调用get方法)和设置属性值(调 ...
- hdu 1016 Prime Ring Problem (素数环)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1016 题目大意:输入一个n,环从一开始到n,相邻两个数相加为素数. #include <iost ...
- eclipse执行maven install命令时跳过test
在pom.xml里面配置一下代码,将跳过test. <plugins> <plugin> <groupId>org.apache.maven.plugins< ...
- Bagging和Boosting 概念及区别(转)
Bagging和Boosting都是将已有的分类或回归算法通过一定方式组合起来,形成一个性能更加强大的分类器,更准确的说这是一种分类算法的组装方法.即将弱分类器组装成强分类器的方法. 首先介绍Boot ...
- HashMap 、LinkedHashMap、HashTable、TreeMap 和 Properties 的区别
HashMap 1.线程不安全: 2.允许null value 和 null key: 3.访问效率比较高: 4.Java1.2引进的Map接口的一个实现: 5.轻量级: 6.根据键的HashCode ...
- ftrace 的使用【转】
转自:http://blog.csdn.net/wang6077160/article/details/7814279 ftrace 的使用 ftrace 在内核态工作,用户通过 debugfs 接口 ...
- 64_l3
libguac-client-ssh-0.9.13-3.20170521git6d2cfda...> 23-May-2017 09:58 64570 libguac-client-ssh-0.9 ...
- poj 3404&&poj1700(贪心)
Bridge over a rough river Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4143 Accept ...
- mysql部署后无法远程连接的原因(错误代码10061),服务监听127.0.0.1和0.0.0.0的区别
在Ubuntu上部署mysql服务并添加了一个非root用户后,发现无法远程连接, Navicat连接mysql出现2003——can't connect to mysql server on loc ...