题目大意:给你一个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的更多相关文章

  1. 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的数组, ...

  2. 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个点,求射 ...

  3. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing

    我不告诉你这个链接是什么 分析:模拟可以过,但是好烦啊..不会写.还有一个扩展欧几里得的方法,见下: 假设光线没有反射,而是对应的感应器镜面对称了一下的话 左下角红色的地方是原始的的方格,剩下的三个格 ...

  4. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)

    C 模拟 题意:给的是一个矩形,然后√2 的速度走,如果走到边上就正常反射,走到角上,暂停反射,我们知道要不循环要不暂停,记录走到的点最短时间 /*************************** ...

  5. 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 ...

  6. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)D Dense Subsequence

    传送门:D Dense Subsequence 题意:输入一个m,然后输入一个字符串,从字符串中取出一些字符组成一个串,要求满足:在任意长度为m的区间内都至少有一个字符被取到,找出所有可能性中字典序最 ...

  7. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort

    链接 题意:输入n,m,表示一个n行m列的矩阵,每一行数字都是1-m,顺序可能是乱的,每一行可以交换任意2个数的位置,并且可以交换任意2列的所有数 问是否可以使每一行严格递增 思路:暴力枚举所有可能的 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 常用几种Java Web容器

    Web服务器是运行及发布Web应用的容器,只有将开发的Web项目放置到该容器中,才能使网络中的所有用户通过浏览器进行访问.开发Java Web应用所采用的服务器主要是与JSP/Servlet兼容的We ...

  2. 1.rs.first()、rs.last()、rs.next()、rs.getRow()

    rs.first()获取第一条数据的信息rs.last()获取最后一条数据的信息rs.next()获取下一条数据的信息rs.getRow()获取当前信息的行数 import java.sql.*; p ...

  3. 【LeetCode】3. Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  4. asp.net javascript客户端调用服务器端方法

    如何用js调用服务器端方法.首先服务器端方法的格式如下 [System.Web.Services.WebMethod]        public static void serverMethod(s ...

  5. Android LayoutInflater解析

    在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById(). 不同点是LayoutInflater是用来找res/layout/下的xml布局文件,并且实 ...

  6. 大规模Schedule任务实现方案

    package com.itlong.bjxizhan.support.web.job.base; import com.itlong.bjxizhan.common.DbContext; impor ...

  7. MVC3+EF4.1学习系列(三)-----排序 刷选 以及分页

    上篇文章 已经做出了基本的增删改查    但这远远不足以应付实际的项目  今天讲下实际项目中 肯定会有的 排序 刷选  以及分页. 重点想多写点分页的 毕竟这个是任何时候都要有的 而且 我会尽量把这个 ...

  8. 第三次冲刺spring会议(第五次会议)

    [例会时间]2014/5/24 21:15 [例会地点]9#446 [例会形式]轮流发言 [例会主持]马翔 [例会记录]兰梦 小组成员:兰梦 ,马翔,李金吉,赵天,胡佳奇

  9. iOS之文件解析

    JSON JSON – OC 转换对照表 JSON OC {} NSDictonary [] NSArray "" NSString 数字 10,10.5 NSNumber NSJ ...

  10. sql优化原则

    尽量使用性能高的比如left join等,尽量减少数据查询的column,尽量不要查询冗余数据,like的话“%%”是没有 办法使用索引的,但是“%”是可以使用索引的 having以前一直不知道到底真 ...