[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 ...
随机推荐
- JavaScript事件代理入门
事件代理(Event Delegation),又称之为事件委托.是 JavaScript 中常用绑定事件的常用技巧. 顾名思义,“事件代理”即是把原本需要绑定的事件委托给父元素,让父元素担当事件监听的 ...
- sql server 查询本年的每个月的数据
一.以一行数据的形式,显示本年的12月的数据,本示例以2017年为例,根据CreateDate字段判断,计算总和,查询语句如下: end) as '1月', end) as '2月', end) as ...
- JS设计模式——11.适配器模式
适配器模式概述 适配器模式可用来在现有接口和不兼容的类之间进行适配.使用这种模式的对象又叫包装器(wrapper). 适配器特点 从表面看,适配器模式很像门面模式.她们都要对别的对象进行包装并改变其呈 ...
- 自动检测SOCKET链接断开
如何判断SOCKET已经断开 最近在做一个服务器端程序,C/S结构.功能方面比较简单就是client端与server端建立连接,然后发送消息给server.我在server端会使用专门的线程处理一条s ...
- jQuery选择器——(三)
1.基本元素选择器 id选择器:$(“#id名称”); 元素选择器:$(“元素名称”); 类选择器:$(“.类名”); 通配符:* 多个选择器共用(并集) 2.层级选择器 ancestor desce ...
- 【LinuxC】GCC编译C程序,关闭随机基址
1.编译.链接和运行程序 C代码示例: #include <stdio.h> #include <stdlib.h> int main() { printf("hel ...
- ActiveMQ 使用场景
ActiveMQ 安装测试就不做介绍了,下面我说说ActiveMQ 使用场景.(松耦合与ActiveMQ) 1.非均匀应用集成 ActiveMQ 中间件用Java语言编写,因此自然提供Java客户端 ...
- WebApi Owin SelfHost OAuth2 - 授权服务和资源服务分离方案
使用JWT 参考:http://www.cnblogs.com/grissom007/p/6294746.html
- 缓存数据库-redis数据类型和操作(string)
Redis支持五种数据类型:string(字符串),hash(哈希),list(列表),set(集合)及zset(sorted set:有序集合) 一:String(字符串) string是redis ...
- Isolate randomforest检测异常点的非监督方法
由于异常数据的两个特征(少且不同: few and different) 异常数据只占很少量; 异常数据特征值和正常数据差别很大. iTree的构成过程如下: l 随机选择一个属性Attr: l ...