LightOJ - 1323 - Billiard Balls(模拟)
链接:
https://vjudge.net/problem/LightOJ-1323
题意:
You are given a rectangular billiard board, L and W be the length and width of the board respectively. Unlike other billiard boards it doesn't have any pockets. So, the balls move freely in the board. Assume that initially some balls are in the board and all of them are moving diagonally. Their velocities are same but their direction may be different. When one or more balls bounce off, their position changes but their velocity remains same.
You are given the initial positions of the balls and their directions; your task is to find the position of the balls after K seconds. The board is placed in the 2D plane such that the boundaries are (0, 0), (L, 0), (L, W) and (0, W). The positions of balls are given as 2D co-ordinates and they all lie inside the board. And the directions are given as one of the following {NE, SE, SW, NW}, N, E, S and W denote North, East, South and West respectively. NE means North-East so both x and y are increasing. The balls are so small that their radiuses can be said to be 0. In each second, the balls advance one unit in their direction. Here one unit doesn't mean Euclidean one unit. For example, if the current position of a ball is (x, y) and its direction is NW then in the next second its position will be (x-1, y+1).
When two or more balls bounce off, they may change their directions as shown in the pictures. You can rotate the pictures to get all possible results. Remember that the balls may bounce at non-integer points.、
思路:
因为输出是排序后的,考虑两个球相撞,路径不会改变,改变编号,就可以忽略碰撞。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
const int INF = 1e9;
const int MAXN = 1e6+10;
const int MOD = 1e9+7;
struct Node
{
int x, y;
}node[1010];
int n;
int l, w, k;
bool cmp(Node a, Node b)
{
if (a.x != b.x)
return a.x < b.x;
return a.y < b.y;
}
int Up(int x, int bor)
{
int less = k%(2*bor);
if (less > (bor-x))
{
less = less-(bor-x);
if (less > bor)
return less-bor;
return bor-less;
}
else
return x+less;
}
int Down(int x, int bor)
{
int less = k%(2*bor);
if (less > x)
{
less -= x;
if (less > bor)
return bor-(less-bor);
return less;
}
else
return x-less;
}
int main()
{
int t, cnt = 0;
scanf("%d", &t);
while(t--)
{
printf("Case %d:", ++cnt);
scanf("%d%d%d%d", &l, &w, &n, &k);
int x, y;
char op[10];
for (int i = 1;i <= n;++i)
{
scanf("%d%d", &x, &y);
node[i].x = x, node[i].y = y;
scanf("%s", op);
if (op[0] == 'N')
node[i].y = Up(y, w);
if (op[0] == 'S')
node[i].y = Down(y, w);
if (op[1] == 'E')
node[i].x = Up(x, l);
if (op[1] == 'W')
node[i].x = Down(x, l);
//cout << node[i].x << ' ' << node[i].y << endl;
}
sort(node+1, node+1+n, cmp);
for (int i = 1;i <= n;i++)
printf("\n%d %d", node[i].x, node[i].y);
puts("");
}
return 0;
}
LightOJ - 1323 - Billiard Balls(模拟)的更多相关文章
- LightOJ 1323 Billiard Balls(找规律(蚂蚁爬木棍))
题目链接:https://vjudge.net/contest/28079#problem/M 题目大意: 一个边界长为L宽为W的平面同时发射n个台球,运动K秒,台球碰到桌面及两(多)个台球相撞情况如 ...
- lightOJ 1317 Throwing Balls into the Baskets
lightOJ 1317 Throwing Balls into the Baskets(期望) 解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/ ...
- Uva 679 Dropping Balls (模拟/二叉树的编号)
题意:有一颗二叉树,深度为D,所有节点从上到下从左到右编号为1,2,3.....在结点一处放一个小球,每个节点是一个开关,初始全是关闭的,小球从顶点落下,小球每次经过开关就会把它的状态置反,现在问第k ...
- LightOJ - 1317 Throwing Balls into the Baskets 期望
题目大意:有N个人,M个篮框.K个回合,每一个回合每一个人能够投一颗球,每一个人的命中率都是同样的P.问K回合后,投中的球的期望数是多少 解题思路:由于每一个人的投篮都是一个独立的事件.互不影响.所以 ...
- ural1494 Monobilliards
Monobilliards Time limit: 1.0 secondMemory limit: 64 MB A monobilliards table set up in a gaming hou ...
- KUANGBIN带你飞
KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题 //201 ...
- [kuangbin带你飞]专题1-23题目清单总结
[kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...
- ACM--[kuangbin带你飞]--专题1-23
专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find T ...
- Codeforces Round #158 (Div. 2) C. Balls and Boxes 模拟
C. Balls and Boxes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
随机推荐
- 第二篇:彻底搞清楚 Spring Boot 的配置文件 application.properties
前言 在Spring Boot中,配置文件有两种不同的格式,一个是properties,另一个是yaml. 虽然properties文件比较常见,但是相对于properties而言,yaml更加简洁明 ...
- STL源码剖析——序列式容器#2 List
list就是链表的实现,链表是什么,我就不再解释了.list的好处就是每次插入或删除一个元素,都是常数的时空复杂度.但遍历或访问就需要O(n)的时间. List本身其实不难理解,难点在于某些功能函数的 ...
- Redis-缓存有效期与淘汰策略
Redis-缓存有效期与淘汰策略 有效期 节省空间 做到数据弱一致性,有效期失效后,可以保证数据的一致性 过期策略 Redis过期策略通常有三种: 1.定时过期: 每个设置过期时间的Key,系统还要生 ...
- H5新特性 本地存储---cookie localStorage sessionStorage
本地存储的作用 :避免登录网站时,用户在页面浏览时重复登录,也可以实现快速登录,一段时间内保存用户的登录效果,提高页面访问速率 在html5中提供三种数据持久化操作的方法: 1.cookie 可看作是 ...
- quartz2.3.0(二)触发器Trigger花式Scheduler调度job
任务类 package org.quartz.examples.example2; import java.util.Date; import org.slf4j.Logger; import org ...
- Disruptor与Netty实现百万级(十)
实体对象: import java.io.Serializable; public class TranslatorData implements Serializable { private sta ...
- PDA日常问题
一.连接网络异常 1.摩托摩拉3190连接wifi时报错,提示:scan error adapter unavailable 确认网卡是不是禁用状态,CE是右下角有个蓝色的图,上面有个X,点一下,然后 ...
- 安装Windows 2008 操作系统时加载ServeRAID-MR10系列阵列卡驱动
安装Windows 2008 操作系统时加载ServeRAID-MR10系列阵列卡驱动 适用机型: 所有System x3200 M2; 所有System x3250 M2; 所有System x33 ...
- VMware下载及安装(含破解码)永久使用
VMware(纽约证交所代码:VMW)在虚拟化和云计算基础架构领域处于全球领先地位,所提供的经客户验证的解决方案可通过降低复杂性以及更灵活.敏捷地交付服务来提高IT效率.VMware使企业可以采用能够 ...
- viewer 图片点击放大 用法汇总
A 不用viewer插件 1弹出框 https://www.cnblogs.com/web1/p/8989967.html 2表格中 https://www.jianshu.com/p/c17f4f6 ...