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. bzoj 4842 [Neerc2016]Delight for a Cat 最小费用最大流,线性规划

    题意:有n个小时,对于第i个小时,睡觉的愉悦值为si,打隔膜的愉悦值为ei,同时对于任意一段连续的k小时,必须至少有t1时间在睡觉,t2时间在打隔膜.如果要获得的愉悦值尽 量大,求最大的愉悦值和睡觉还 ...

  2. HTML(五)

    HTML5新结构标签 h5新增的主要语义化标签如下: 1.header 页面头部.页眉2.nav 页面导航3.article 一篇文章4.section 文章中的章节5.aside 侧边栏6.foot ...

  3. redis日志格式

    在redis.conf中,在大概65行左右有个loglevel # 指定日志记录级别# Redis总共支持四个级别:debug.verbose.notice.warning,默认为verbose# d ...

  4. 加密传输:每位数字+6,然后用除以9的余数代替该数字, 在把第一位和第四位交换,第二位和第三位交换,例如3276->3840

    /** * @author:(LiberHome) * @date:Created in 2019/3/6 10:00 * @description: * @version:$ */ /*今日目标:5 ...

  5. 2019.4.1 JMeter中文乱码解决方案

    1)添加一个HTTP信息头管理器:添加Accept:application/xml;application/json;charset=utf-8 2)参数为中文:在HTTP请求时设置编码格式为utf- ...

  6. 利用野草weedcmsuseragent盲注漏洞拿shell

    野草网站管理系统(WEEDCMS)是由野草独立基于PHP+MYSQL开发的内容管理系统.面向企业.个人.小门户等中小规模网站使用而开发的.采用国际上比较流行Smarty引擎和敏捷的JQuery JS框 ...

  7. linux基础命令--groupmod 修改组定义

    描述 groupmod命令用于修改系统上的组定义. groupmod命令通过更改组数据库(the group database)里的相关条目来修改指定的组. 语法 groupmod [选项] GROU ...

  8. html转markdown网站

    戳下面的链接,可以直接复制富文本粘贴编程markdown: https://euangoddard.github.io/clipboard2markdown/

  9. allegro17.2 错误记录

    1.网表导入PCB时出现如下错误::error with pin number 'P11'in device ' lfbga176'::Unable to find pin name in adfnc ...

  10. Oracle SQL Loader

    C:/Documents and Settings/WWJD>sqlldr SQL :: Copyright (c) , , Oracle. All rights reserved. 用法: S ...