http://codeforces.com/problemset/problem/848/B

给定一个二维坐标系,点从横轴或纵轴垂直于发射的坐标轴射入(0,0)-(w,h)的矩形空间。给出点发射的坐标轴,位置,延迟时间,发生碰撞则交换方向。求最后每个点的射出位置。

首先我们观察能得出两个结论,1. 类似蚂蚁爬树枝的问题,相遇只会交换方向,所以最后的射出点集只会因为碰撞而改变动点与射出点的对应关系,而不会增加减少射出点集。2.我们根据其射入位置和延迟时间可以计算出一个值v=pos-time,只有这个值相等才可能发生碰撞。

这样我们可以把所有点根据值v分成若干个集合,每个集合互不干涉,对于一个集合的射出点集,我们只要处理内部的对应关系即可。

首先画一张图片,代表一个集合的所有点,因为v相等,只要在图中的射线可以相遇一定会碰撞。

可见一个点从出发后,将依次交替遭遇另一个轴的点(数量为siz0)和本轴坐标大于等于本身的点(数量为siz1)。最终不再碰撞时的方向我们可以很容易地通过siz0,siz1推出来,而方向与最后一次碰撞的点相同(当与当前方向的平行的坐标轴发射的动点数量用尽时就不再碰撞了)。

这样每个点都可以在O(1)或O(log(n))下求出射出位置。因为需要排序预处理,所以要不要优化到O(1)并不是很重要。

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#define LL long long
using namespace std;
const LL N = 100005;
LL n, w, h;
struct node
{LL g, p, t;
};
map<LL, vector<LL> > g[2];
node v[N];
int main()
{cin.sync_with_stdio(false);while (cin >> n>>w>>h){g[0].clear(), g[1].clear();for (int i = 0; i < n; i++){node temp;cin >> temp.g >> temp.p >> temp.t;temp.g--;g[temp.g][temp.p - temp.t].push_back(temp.p);v[i] = temp;}for (map<LL, vector<LL> >::iterator it = g[0].begin(); it != g[0].end(); it++)sort(it->second.begin(), it->second.end());for (map<LL, vector<LL> >::iterator it = g[1].begin(); it != g[1].end(); it++)sort(it->second.begin(), it->second.end());for (int i = 0; i < n; i++){node e = v[i];int dg;if (e.g == 0){dg = 1;LL siz[2];siz[e.g]= g[e.g][e.p - e.t].end() - lower_bound(g[e.g][e.p - e.t].begin(), g[e.g][e.p - e.t].end(), e.p);siz[dg] = g[dg][e.p - e.t].size();LL miz = min(siz[0], siz[1]);if (siz[e.g] <= siz[dg])cout << w << ' ' << g[dg][e.p - e.t][miz-1] << endl;elsecout << g[e.g][e.p - e.t][g[e.g][e.p - e.t].size()-siz[e.g]+miz] << ' ' << h << endl;}else{dg = 0;LL siz[2];siz[e.g] = g[e.g][e.p - e.t].end() - lower_bound(g[e.g][e.p - e.t].begin(), g[e.g][e.p - e.t].end(), e.p);siz[dg] = g[dg][e.p - e.t].size();LL miz = min(siz[0], siz[1]);if (siz[e.g] <= siz[dg])cout << g[dg][e.p - e.t][miz-1]<<' '<<h << endl;elsecout << w<<' '<<g[e.g][e.p - e.t][g[e.g][e.p - e.t].size() - siz[e.g] + miz]<<endl;}}}return 0;
}

转载于:https://www.cnblogs.com/LukeStepByStep/p/7469559.html

codeforces 848B Rooter's Song 思维题相关推荐

  1. Codeforces 1077B Disturbed People(思维题)

    Codeforces 1077B Disturbed People(思维题) There is a house with nn flats situated on the main street of ...

  2. Codeforces 675C Money Transfers (思维题)

    There are n banks in the city where Vasya lives, they are located in a circle, such that any two ban ...

  3. codeforces 有意思的思维题 1 ~ 15

    codeforces 思维题 1.给定数组,求满足i < j and ai * aj = i + j的数对数量 2.第 i 步向前跳 i 步或后退 1 步 3.给两个点,求正方形的另两个点 4. ...

  4. CF--思维练习-- CodeForces - 215C - Crosses(思维题)

    ACM思维题训练集合 There is a board with a grid consisting of n rows and m columns, the rows are numbered fr ...

  5. CodeForces - 1102A(思维题)

    https://vjudge.net/problem/2135388/origin Describe You are given an integer sequence 1,2,-,n. You ha ...

  6. 【CodeForces - 215C 】Crosses (思维,图形题)

    题干: There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 fr ...

  7. ☆【CodeForces - 764C】Timofey and a tree (思维题,树的性质)

    题干: Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After tha ...

  8. 【CodeForces - 707B】Bakery(思维水题)

    Bakery Descriptions 玛莎想在从1到n的n个城市中开一家自己的面包店,在其中一个城市烘焙松饼. 为了在她的面包房烘焙松饼,玛莎需要从一些储存的地方建立面粉供应.只有k个仓库,位于不同 ...

  9. Educational Codeforces Round 67 (Rated for Div. 2)(D思维题 线段树/E树形dp(换根dp) 二次扫描与换根法)

    心得 D写了个假算法被hack了wtcl- E据涛神说是二次扫描与换根法,看了看好像和树形dp差不多 F概率dp G费用流 回头再补 思路来源 马老师 归神 贤神等代码 http://www.mami ...

最新文章

  1. oracle定时器定时删除30天前的数据_Redis-数据淘汰策略持久化方式(RDB/AOF)Redis与Memcached区别...
  2. 【控制】第九章-线性系统的状态空间描述
  3. 变种GandCrab样本分析
  4. 鸿蒙开发-实现页面跳转与页面返回
  5. 【机器学习】逻辑回归特征的离散化与交叉
  6. 不知道路由器工作原理?没关系,来这看看!看不懂你捶我 | 原力计划
  7. 用PowerShell收集服务器日检报告,并发邮件给管理员
  8. 蒙提霍尔问题(三门问题)的思考与贝叶斯分析
  9. 使用代理服务器隐藏电脑上网真实IP地址
  10. Python爬虫实现无限刷不背单词app的酷币!很有意思!
  11. 第二篇:Cydia添加源和安装软件
  12. 139邮箱注册收费吗,什么VIP的邮箱安全又好用呢
  13. 模仿猫眼电影App一个动画效果
  14. 2022高教杯数学建模E思路 超详细文字内容 数模E题
  15. 微信小程序开发一定要服务器么,该怎么选择小程序服务器?
  16. python画一个点_python中画散点图
  17. 计算机专业创新项目,计算机科学学院喜获2018年大学生创新创业项目多个立项...
  18. 碉堡了,一个专注于效率的开源编程语言
  19. 本地字节序与网络字节序的相互转换(IP地址、端口号)
  20. Objective-C向面向对象编程中添加了一个新概念:类别(categor)。

热门文章

  1. 香蕉派开源硬件 Banana PI
  2. WPF RichTextBox的Document属性的序列化与反序列化
  3. Linux系统各文件、目录介绍
  4. 流畅的python 函数
  5. ROS学习笔记4(编译一个ROS Package)
  6. 元宇宙是个啥?送4本科普好书
  7. Mac上的IDEA安装配置maven
  8. 9.6.1 三维数据可视化之平面图
  9. Delphi无法修改Clientdataset的字段的解决方法
  10. 调查:拉丁美洲25%的信用卡用户希望使用加密货币付款