模拟。。。 Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C
题目大意:给你一个n*m的矩阵,再给你一个小球,从(0,0)以sqrt(2)/s的速度向右上角出发,遇到边框会反弹,遇到角落就直接停止,给你一些点,问小球第一次经过这些点所需要的时间。
思路:模拟一下即可。。。注意爆int
//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha printf("haha\n")
const int maxn = 5e5 + ;
map<pair<LL, LL>, int> line;
map<pair<LL, LL>, int> ID;
vector<LL> v[maxn];
bool vis[maxn];
LL X[maxn], Y[maxn];
LL ans[maxn];
int n, m, k;
int cnt; int get_id(LL k, LL b){
if (ID.count(mk(k, b))) return ID[mk(k, b)];
ID[mk(k, b)] = ++cnt;
return cnt;
} bool check(LL k, LL b){
if (line.count(mk(k, b))) return true;
line[mk(k, b)] = ; return false;
} void cal_time(int k, int b, LL x, LL y, LL colck){
if (ID.count(mk(k, b)) == ) return ;
for (int i = ; i < v[ID[mk(k, b)]].size(); i++){
int pos = v[ID[mk(k, b)]][i];
if (vis[pos]) continue;
vis[pos] = true;
LL tx = abs(X[pos] - x), ty = abs(Y[pos] - y);
ans[pos] = colck + min(tx, ty);
}
}
void solve(){
memset(ans, -, sizeof(ans));
LL colck = ;
int ty = ;
int x = , y = ;
while(true){
int nx, ny;
if (ty == ){
if(check(, y - x)) break;
cal_time(, y - x, x, y, colck);
nx = n - x, ny = m - y;
if (nx < ny) x = n, y = y + nx, ty = ;
if (nx > ny) x = x + ny, y = m, ty = ;
}
else if (ty == ){
if(check(-, y + x)) break;
cal_time(-, y + x, x, y, colck);
nx = x, ny = m - y;
if (nx < ny) x = , y = y + nx, ty = ;
if (nx > ny) x = x - ny, y = m, ty = ;
}
else if (ty == ){
if(check(, y - x)) break;
cal_time(, y - x, x, y, colck);
nx = x, ny = y;
if (nx < ny) x = , y = y - nx, ty = ;
if (nx > ny) x = x - ny, y = , ty = ;
}
else if (ty == ){
if(check(-, y + x)) break;
cal_time(-, y + x, x, y, colck);
nx = n - x, ny = y;
if (nx < ny) x = n, y = y - nx, ty = ;
if (nx > ny) x = x + ny, y = , ty = ;
}
colck += min(nx, ny);
if(nx == ny) break;
}
} int main(){
cin >> n >> m >> k;
for (int i = ; i <= k; i++){
scanf("%lld%lld", X + i, Y + i);
int t1 = get_id(-, X[i] + Y[i]);
int t2 = get_id(, Y[i] - X[i]);
v[t1].push_back(i);
v[t2].push_back(i);
}
solve();
for (int i = ; i <= k; i++){
printf("%lld\n", ans[i]);
}
return ;
}
模拟。。。 Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C的更多相关文章
- CF Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
1. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort 暴力枚举,水 1.题意:n*m的数组, ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C.Ray Tracing (模拟或扩展欧几里得)
http://codeforces.com/contest/724/problem/C 题目大意: 在一个n*m的盒子里,从(0,0)射出一条每秒位移为(1,1)的射线,遵从反射定律,给出k个点,求射 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing
我不告诉你这个链接是什么 分析:模拟可以过,但是好烦啊..不会写.还有一个扩展欧几里得的方法,见下: 假设光线没有反射,而是对应的感应器镜面对称了一下的话 左下角红色的地方是原始的的方格,剩下的三个格 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
C 模拟 题意:给的是一个矩形,然后√2 的速度走,如果走到边上就正常反射,走到角上,暂停反射,我们知道要不循环要不暂停,记录走到的点最短时间 /*************************** ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar 水题
A. Checking the Calendar 题目连接: http://codeforces.com/contest/724/problem/A Description You are given ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)D Dense Subsequence
传送门:D Dense Subsequence 题意:输入一个m,然后输入一个字符串,从字符串中取出一些字符组成一个串,要求满足:在任意长度为m的区间内都至少有一个字符被取到,找出所有可能性中字典序最 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort
链接 题意:输入n,m,表示一个n行m列的矩阵,每一行数字都是1-m,顺序可能是乱的,每一行可以交换任意2个数的位置,并且可以交换任意2列的所有数 问是否可以使每一行严格递增 思路:暴力枚举所有可能的 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E. Goods transportation (非官方贪心解法)
题目链接:http://codeforces.com/contest/724/problem/E 题目大意: 有n个城市,每个城市有pi件商品,最多能出售si件商品,对于任意一队城市i,j,其中i&l ...
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar(水题)
传送门 Description You are given names of two days of the week. Please, determine whether it is possibl ...
随机推荐
- ZZNU 1163: 在线判题(指针专题)
题目描述 Ignatius is building an Online Judge, now he has worked out all the problems except the Judge S ...
- python之~利用PIL模块在图片上写写画画
借鉴了教程: http://yxnt.github.io/2016/05/15/Pillow-Python3.5/ 完成作业如下: 后来学着写给自己的图片加了水印. from PIL import I ...
- 工艺成型及仿真、铸造工艺及仿真ProCAST软件入门认识介绍
视频源:技术邻 关键词:ProCAST.工艺成型及仿真.铸造工艺及仿真 简介:ProCAST 软件是由美国 USE 公司开发的铸造过程的模拟软件采用基于有限元(FEM)的数值计算和综合求解的方法,对铸 ...
- 设计模式 -- 责任链模式或者叫职责链模式(Chain of Responsibility(CoR))
什么是链?前后相连,一个连接下一个,其中包括多个节点,其实责任链模式也类似,他是多个对象之间相互关联,下一个对象的操作由上一个对象关联下来,上一个对象有个方法用于指向其他对象.职责链之间的前后关系是可 ...
- SimpleDateFormat类
/* * DateFormat类概述 * DateFormat是日期时间格式化子类的抽象类,它以与语言无关的方式格式化并解析日期或时间 * 是抽象类,所以使用其子类SimpleDateFormat * ...
- 如何区分javascript中的方法(method)、函数(function)、事件(event)三个概念?
方法是程序对某操作的处理,比如show(),你可以在触发单击事件的时候调用show(),也可以在双击的时候调用. 函数是由事件驱动的或者当它被调用时执行的可重复使用的代码块.比如自己写的倒计时函数,触 ...
- 第六十一节,html超链接和路径
html超链接和路径 学习要点: 1.超链接的属性 2.相对与绝对路径 3.锚点设置 本章主要探讨HTML5中文本元素 ...
- 2016GIAC全球互联网架构大会日程分享
GIAC全球互联网架构大会是中国互联网技术领域一年一度的行业盛事,每年从互联网架构最热门高压应对.云计算.大数据.机器学习.分布式架构等领域甄选前沿的有典型代表的技术创新及研发实践的架构案例,分享他们 ...
- 安卓.点击头像-->编辑个人姓名-->提交后.同时调用js关闭页面-->返回上一层
$(document).ready(function() { $('#selfbtn').click(function(){ var u = navigator.userAgent; if (u.in ...
- 3.通过js代码设置css样式
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...