【cf849D】Rooter's Song(思维)
39 思维
2023-09-11 14:19:24 时间
题意
x轴、y轴上有n个人,第i个人\(g_i==1\)则坐标为\((p_i,0)\)否则\((0,p_i)\),\(t_i\)秒后垂直所在坐标轴出发,到达边界x=w,或者y=h停止,速度都是1。
两个人相撞则方向互换。问最后每个人的位置。
题解
t秒后出发等价于位置往后移动t,起点就是x=p,y=-t,或者x=-t,y=p。然后x+y相等的点就是会相撞的,他们的终点位置会发生一些交换。
x+y相等的起点是在一条直线上,每个点撞来撞去其实守住了自己的相对位置,上面的还是在上面,左边的还是在左边。所以分别对应了一样排序好的终点位置。
代码
const int N=201000;
struct node{
int x,y,ex,ey,i;
}a[N],b[N];
int ansx[N],ansy[N];
bool cmp(node a,node b){
return a.x+a.y<b.x+b.y || a.x+a.y==b.x+b.y && a.x-a.y<b.x-b.y;
}
bool cmp2(node a,node b){
return a.x+a.y<b.x+b.y || a.x+a.y==b.x+b.y && a.ex-a.ey<b.ex-b.ey;
}
int main() {
int n,w,h;
sf(n);sf(w);sf(h);
rep(i,0,n){
int g,p,t;
sf(g);sf(p);sf(t);
if(g==1)
a[i]=(node){p,-t,p,h,i};
else
a[i]=(node){-t,p,w,p,i};
b[i]=a[i];
}
sort(a,a+n,cmp);
sort(b,b+n,cmp2);
rep(i,0,n){
ansx[a[i].i]=b[i].ex;
ansy[a[i].i]=b[i].ey;
}
rep(i,0,n) printf("%d %d\n",ansx[i],ansy[i]);
return 0;
}
相关文章
- 遇到ImportError: cannot import name ‘soft_unicode’ from 'markupsafe’问题
- What's vmware horizon client?
- ASP.NET's Data Storage Objects
- User control's property loses value after a postback
- Could not load file or assembly 'System.Web.Http Fuslogvw.exe (Assembly Binding Log Viewer)
- Can't find PHP headers in /usr/include/php
- mysql客户端(Navicat)远程登录操作遇到问题1142 - XXX command denied to ×××
- Mac下遇到 'reading initial communication packet’ 问题
- HDU 3966 Aragorn's Story
- FZU 1980 AbOr's story
- npm启动报错Module not found: Error: Can't resolve 'fs'
- SSL/TLS 加密新纪元 - Let's Encrypt
- 富文本编辑保存的时候报错Data truncation: Data too long for column 'content' at row 1
- ubuntu执行普通用户或root用户执行apt-get update时报错"Couldn't create temporary file /tmp/apt.conf.sssss for passing config to apt-key" 如何处理?
- Avoid using implementation types like 'HashMap'; use the interface instead
- HDU 3729 I'm Telling the Truth (二分匹配)
- 为了让vi命令也可以使用vim的配置,需要修改 vi /etc/bashrc 增加一行 alias vi='vim'此时,经过上面配置已经可以显示语法高亮了
- 转 sh脚本格式错误 unexpected EOF while looking for matching ``'
- 【 HDU3294 】Girls' research (Manacher)
- org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported
- springboot Consider defining a bean of type 'xxx' in your configuration
- Visual Studio® 2010 Web Deployment Projects站点编译生成bin同时发表插件
- Error reading relay log event for channel '10.18.51.35': slave SQL thread was killed
- 解决 django.db.utils.OperationalError: (1051, "Unknown table 'mydorm.users_studen t'")
- 'gitclone报错fatal:protocolerror:badpackheader'
- PhpStorm配置svn:Can't use Subversion command line client:svn
- TypeError: 'module' object is not callable(“模块”对象不可调用)