C 模拟

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

/*************************************************************************
> File Name: c.cpp
> Author: opas_chenxin
> Mail: 1017370773@qq.com
> Created Time: 2016年10月08日 星期六 22时01分54秒
************************************************************************/
#include<stdio.h>
#include<string.h>
#include<map>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
struct point{
ll x,y,d;
point(ll x1 = , ll y1 = , ll d1 = ) {
x = x1; y = y1; d = d1;
}
bool operator < (point const&A) const{
if(x != A.x) return x < A.x;
if(y != A.y) return y < A.y;
return d < A.d;
}
//bool operator == (point &A){
// return x == A.x && y == A.y && d == A.d;
//}
};
map<point,ll> G;
ll n,m,k;
ll edg_w[]={,,,};
bool GetNextPoint(int loc, point A, ll &t, point &B, int fu) {
ll b = A.y - A.d * A.x;
if(loc&) {
B.y = edg_w[loc];
B.x = (B.y - b) * A.d;
t = abs(A.y - edg_w[loc]);
} else {
B.x = edg_w[loc];
B.y = B.x * A.d + b;
t = abs(A.x - edg_w[loc]);
}
B.d = A.d * fu;
if(B.x < || B.x > n || B.y < || B.y > m || (B.x == A.x && B.y == A.y) )
return false;
return true;
}
point GetNextLoc(point &A, ll &t ) {
point next_loc;
ll tt;
for(int i = ; i < ; ++ i) {
if(GetNextPoint(i, A, tt, next_loc, -)) {
t += tt;
return next_loc;
}
}
return next_loc;
}
bool JudEnd(point &A){
if(A.x == && A.y == ) return true;
if(A.x == && A.y == m) return true;
if(A.x == n && A.y == ) return true;
if(A.x == n && A.y == m) return true;
return false;
}
ll GetAns(point &A){
ll t=;
ll ans = -;
for(int i = ; i < ; ++ i) {
A.d = -A.d;
for(int j = ; j < ; ++ j) {
point B;
if(GetNextPoint(j, A, t, B, )) {
if(G.count(B) > ) {
if(ans == -)
ans = G[B]+t;
else
ans = min(G[B]+t, ans);
}
}
}
}
if(ans != -) ans = ans -;
return ans;
}
int main() {
freopen("in", "r", stdin);
while( cin>>n>>m>>k ) {
edg_w[] = n;
edg_w[] = m;
G.clear();
point now = point(,,);
ll t = ;
G.insert(pair<point,ll>(now,t));
while(true) {
point next_loc = GetNextLoc(now, t);
if(JudEnd(next_loc)) break;
if(G.count(next_loc) > ) break;
else G.insert(pair<point,ll>(next_loc,t));
now = next_loc;
G.insert(pair<point,ll>(now,t));
}
for(int i = ; i < k; ++ i) {
ll x, y;
cin>>x>>y;
point A = point(x, y, );
cout<<GetAns(A)<<endl;
}
}
return ;
}

d

Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)的更多相关文章

  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)D Dense Subsequence

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

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

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

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

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

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

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

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

  8. Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort(暴力)

    传送门 Description You are given a table consisting of n rows and m columns. Numbers in each row form a ...

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

    Description You are given a table consisting of n rows and m columns. Numbers in each row form a per ...

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

    Description You are given names of two days of the week. Please, determine whether it is possible th ...

随机推荐

  1. PBRT笔记(1)——主循环、浮点误差

    PBRT2与3之间的改动 增加了一个功能完备的BRDF模型,支持体积光照与重要性多重路径采样. 次表面散射,基于光线追踪技术,无需预处理. 解决浮点数四折五入的问题 光子映射 样本生成 第一章多了讲并 ...

  2. LOJ.2865.[IOI2018]狼人(Kruskal重构树 主席树)

    LOJ 洛谷 这题不就是Peaks(加强版)或者归程么..这算是\(IOI2018\)撞上\(NOI2018\)的题了? \(Kruskal\)重构树(具体是所有点按从小到大/从大到小的顺序,依次加入 ...

  3. Torch功能点记录

    1. Numpy矩阵转换Tensor: tensor_num = torch.from_numpy(numpy_arr)

  4. ubantu16.04安装ns2.34 错误

    把ns2.34解压缩之后,sudo ./install 出现的错误: 错误一:安装NS2.34过程中出现如下的错误:tools/ranvar.cc: In member function ‘virtu ...

  5. [LeetCode] Sliding Puzzle 滑动拼图

    On a 2x3 board, there are 5 tiles represented by the integers 1 through 5, and an empty square repre ...

  6. VIm快捷操作

    vim快捷操作 移动 行级移动 $ 行尾 0 行头 段级移动 { 段首 } 段尾 屏幕级别 L: 屏幕尾部 H: 屏幕头部 文档级别 G: 文档尾部 1G:头部 nG:文档n行 删除 dd: 删除当前 ...

  7. QQ机器人

    先说下整体思路1.首先要借助一个QQ 插件,用来接收消息 发送消息2.要用个QQ 小号,这个QQ 你不能用来登,因为他相当于那个机器人3.要借助大神开发的SDK ,就是别人写的底层交互 ,我们只需要关 ...

  8. (Linux)CentOS7下安装JDK 1.8

    参考:http://www.cnblogs.com/sxdcgaq8080/p/7492426.html 1.首先查看CentOS7是否有自带的JDK ,一般Linux会自动下载安装Open JDK ...

  9. tesseract库

    1.简介 # -*-coding:utf8 -*- #图形验证码识别技术 ''' 阻碍我们爬虫的,有时候是在登录或者请求一些数据时候的图形验证码.因此这里我们讲解 一种能将图片翻译成文字的技术.将图片 ...

  10. 创建存储过程 in,out,inout

    in: 输入参数,存储过程如果修改了参数值,那么不能被返回. out:输出参数,存储过程中修改了参数值,可以被返回.inout:输入参数,存储过程如果修改了参数值,可以被返回 注意参数格式:  in  ...