[CodeForces - 848B] Rooter's Song 思维 找规律
大致题意:
有一个W*H的长方形,有n个人,分别站在X轴或Y轴,并沿直线向对面走,第i个人在ti的时刻出发,如果第i个人与第j个人相撞了
那么则交换两个人的运动方向,直到走到长方形边界停止,问最后每个人的坐标。
题解:
两个人要相撞,当且仅当Xi-Ti=Xj-Tj,所以可以将Xi-Ti分组,对于同一组里的人会互相碰撞,不同组的不会,这样就只要考虑同一组里
的人,画个图可以发现,
规律
然后根据规律化坐标即可
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define eps 1e-6
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fr freopen
#define pi acos(-1.0)
#define Vector Point
typedef pair<int,int> pii;
const long long linf=1LL<<;
const int iinf=<<;
const double dinf=1e17;
const int Mod=1e9+;
typedef long long ll;
typedef long double ld;
const int maxn=;
struct node{
int x,t,g;
int id;
};
bool cmp(node a,node b){
if(a.g==b.g){
if(a.g==) return a.x<b.x;
if(a.g==) return a.x>b.x;
}
return a.g<b.g;
}
bool cmp2(node a,node b){
if(a.g==b.g) {
if(a.g==) return a.x<b.x;
return a.x>b.x;
}
return a.g>b.g;
}
const int maxt=;
vector<node>vc[maxn];
vector<pair<int,int> >vcc;
pii p,ans[maxn];
node nd;
int n,w,h;
void solve(){
iossy;
cin>>n>>w>>h;
For(i,,n){
cin>>nd.g>>nd.x>>nd.t;nd.id=i;
vc[maxt+nd.x-nd.t].pb(nd);
}
For(i,,maxt+maxt){
vcc.clear();
if(!vc[i].sz)continue;
sort(vc[i].begin(),vc[i].end(),cmp);
For(j,,vc[i].sz){
if(vc[i][j-].g==) vcc.pb(mkp(vc[i][j-].x,h));
else vcc.pb(mkp(w,vc[i][j-].x));
}
sort(vc[i].begin(),vc[i].end(),cmp2);
For(j,,vc[i].sz){
ans[vc[i][j-].id]=vcc[j-];
}
}
For(i,,n)
cout<<ans[i].first<<" "<<ans[i].second<<endl;
}
int main(){
int t=;
while(t--) solve();
return ;
}
[CodeForces - 848B] Rooter's Song 思维 找规律的更多相关文章
- codeforces 848B Rooter's Song 思维题
http://codeforces.com/problemset/problem/848/B 给定一个二维坐标系,点从横轴或纵轴垂直于发射的坐标轴射入(0,0)-(w,h)的矩形空间.给出点发射的坐标 ...
- Codeforces D. Little Elephant and Interval(思维找规律数位dp)
题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes ...
- Codeforces Gym 100114 A. Hanoi tower 找规律
A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...
- codeforces Gym 100418D BOPC 打表找规律,求逆元
BOPCTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?c ...
- Codeforces Round #242 (Div. 2)C(找规律,异或运算)
一看就是找规律的题.只要熟悉异或的性质,可以秒杀. 为了防止忘记异或的规则,可以把异或理解为半加运算:其运算法则相当于不带进位的二进制加法. 一些性质如下: 交换律: 结合律: 恒等律: 归零律: 典 ...
- codeforces Round #440 B Maximum of Maximums of Minimums【思维/找规律】
B. Maximum of Maximums of Minimums time limit per test 1 second memory limit per test 256 megabytes ...
- Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律
Another Rock-Paper-Scissors Problem 题目连接: http://codeforces.com/gym/100015/attachments Description S ...
- Codeforces H. Malek Dance Club(找规律)
题目描述: Malek Dance Club time limit per test 1 second memory limit per test 256 megabytes input standa ...
- The Bits (思维+找规律)
Description Rudolf is on his way to the castle. Before getting into the castle, the security staff a ...
随机推荐
- 一个菜鸟的ASP.NET观光路线图
作为一个成长的"菜鸟".我的习惯是,每过一个阶段,都对自己的知识体系进行一次概括. 这篇博文是一个总结帖,我将把我的学到的东西,按照一定顺序串联在一起. ...
- TIP协议
1. TIP是什么? CISCO给TIP的定义如下: The TIP protocol specifications describe how to multiplex multiple screen ...
- 25、LinkedList特有方法
LinkedList特有方法 public void addFirst(E e)及addLast(E e) public E getFirst()及getLast() public E removeF ...
- php 传递赋值和地址赋值 &
更多内容推荐微信公众号,欢迎关注: 1.传递赋值 $a = 1; $b = 2; $a = $b; echo $a,$b; //结果为:5 5 2.地址赋值 $a = 1; $b = 2; $a = ...
- GreenTrend
ExpertforSQLServer(4.7.2)和ZhuanCloud(1.0.0)工具收集内容(在个人笔记本上测试) --SZC_Info.txt :: SQL专家云 v1. :: 开始收集 :: ...
- PHP在引号前面添加反斜杠的原因及PHP去除反斜杠的办法
昨天用PHP做了个读写html文档的小程序,本地测试正常但是传到网站后发现,提交内容保存的时候会自动在双引号前面增加一个反斜杠“\”,而且每保存一次增加一个反斜杠,很是郁闷. 当然做这个只是为了参加电 ...
- error while loading shared libraries: libtest.so: cannot open shared object file: No such file or directory
一般我们在Linux下执行某些外部程序的时候可能会提示找不到共享库的错误, 比如: tmux: error while loading shared libraries: libevent-1.4.s ...
- 29 A Quick Guide to Go's Assembler 快速指南汇编程序:使用go语言的汇编器简介
A Quick Guide to Go's Assembler 快速指南汇编程序:使用go语言的汇编器简介 A Quick Guide to Go's Assembler Constants Symb ...
- Mysql Limit操作
oracle : || mysql: contact contact_ws 拼接 Font Size: Large | Medium | Small select * from tabl ...
- Nginx - 日志格式及输出
1. 前言 在 Nginx 服务器中,如果想对日志输出进行控制还是很容易的.Nginx 服务器提供了一个 HttpLogModule 模块,可以通过它来设置日志的输出格式. 2. HttpLogMod ...