模拟。。。 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 ...
随机推荐
- PAT 团体程序设计天梯赛-练习集 L1-018. 大笨钟
微博上有个自称“大笨钟V”的家伙,每天敲钟催促码农们爱惜身体早点睡觉.不过由于笨钟自己作息也不是很规律,所以敲钟并不定时.一般敲钟的点数是根据敲钟时间而定的,如果正好在某个整点敲,那么“当”数就等于那 ...
- CSS3的基础知识点
面临找工作之际,又将CSS3的基础知识撸了一把,做了相应的笔记,主要是方便自己查阅,参考的是W3C的知识. 1.CSS背景 (1).background-size 属性 background-s ...
- Java 反射 Method的invoke回调调用任意方法
Java 反射 Method的invoke回调调用任意方法 @author ixenos 关键子:Method.Field.invoke方法指针/函数指针.回调函数 invoke回调流程示例 0.由C ...
- 监控自定义信息 —— ESFramework 4.0 快速上手(10)
在ESFramework 4.0 进阶(02)-- 核心:消息处理的骨架流程一文中,我们介绍了通过挂接IMessageSpy到骨架流程,我们就可以监控到所有收发的消息.由于Rapid引擎已经为我们组装 ...
- ASP.NET MVC 实现AJAX跨域请求的两种方法
通常发送AJAX请求都是在本域内完成的,也就是向本域内的某个URL发送请求,完成部分页面的刷新.但有的时候需要向其它域发送AJAX请求,完成数据的加载,例如Google. 在ASP.NET MVC 框 ...
- 关于WM_NCHITTEST消息
我为了移动一个无标题栏的窗体,使用了WM_NCHITTEST消息,这个消息大概如下: 通常,我们拖动对话框窗口的标题栏来移动窗口,但有时候,我们想通过鼠标在客户区上拖动来移动窗口. 一个容易想到的方案 ...
- clion idea jetbrain windows下搞c/c++
安装 clion 把MinGW(搜MinGW.zip)放到c盘根目录下 ok
- EXEC 和 SP_EXECUTESQL的区别
摘要: MSSQL为我们提供了两种动态执行sql语句的命令:EXEC 和 SP_EXECUTESQL.通常SP_EXECUTESQL更具优势,因为它提供了输入输出的接口,且能够重用执行计划,大大提高执 ...
- zendstudio 安装 手册
安装 http://jingyan.baidu.com/article/b907e627b14fbb46e6891c65.html 选择baidu官方32bit安装 补丁破解网址 http://dwt ...
- Urbanization
Urbanization time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...