题目大意:给你一个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. Qt 5.7 > Qt Applications

    本文翻译自Qt官方文档: http://doc.qt.io/qt-5/qmlapplications.html QML 应用 QML是声明式语言,它使得用户界面以及交互行为可以被"描述&qu ...

  2. angular2与VS2015 asp.net core集成使用

    首先,需要在VS2015环境下更新到update2,并安装asp.net core环境,并安装Node.js插件. 新建asp.net core项目: 此时,需要先新建npm配置文件,如图: 并定义n ...

  3. 第七十节,css选择器

    css选择器 学习要点: 1.选择器总汇 2.基本选择器 3.复合选择器 4.伪元素选择器 本章主要探讨 HTML5中  CSS选择器,通过选择器定位到想要设置样式的元素.目前CSS选择器的版本已经升 ...

  4. C#Stopwatch的使用,性能测试

    一,先开启开始或继续测量某个时间间隔的运行时间,然后停止,最后重置时间,输出. using System; using System.Collections.Generic; using System ...

  5. 更好列表页中一个航班.先unset删除数组中一个键值对,再追加,最后按键排序

    <?php $arr = array( '0' => array('item' => array( 'aa' => 'aaa', 'bb' => 'bbb' )), '1 ...

  6. mac下安装composer

    打开命令后 cd /usr/local/bin 然后执行 curl -sS https://getcomposer.org/installer | php 接下来 sudo mv composer.p ...

  7. 可以有效防护XSS,sql注射,代码执行,文件包含等多种高危漏洞。

    http://bbs.aliyun.com/read/137391.html <?php /** * 云体检通用漏洞防护补丁v1.1 * 更新时间:2013-05-25 * 功能说明:防护XSS ...

  8. 星语硬件检测专家 V4.3 官方版

    软件名称: 星语硬件检测专家 软件语言: 简体中文 授权方式: 免费软件 运行环境: Win 32位/64位 软件大小: 15.8MB 图片预览: 软件简介: 星语硬件检测专家是一款功能非常强大的硬件 ...

  9. 【Machine Learning in Action --4】朴素贝叶斯电子邮件垃圾过滤

    摘要:这里用的是词袋模型,即一个词在文档中出现不止一次,每个单词可以出现多次. 1.准备数据:切分文本 前一节过滤网站恶意留言中词向量是给定的,下面介绍如何从文本文档中构建自己的词列表 先举例说明,在 ...

  10. mysql5.7.16安装

    系统:centOS6.5 mysql: 5.7.16 wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.16-linux-glib ...