Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
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)的更多相关文章
- 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)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) C. Ray Tracing
我不告诉你这个链接是什么 分析:模拟可以过,但是好烦啊..不会写.还有一个扩展欧几里得的方法,见下: 假设光线没有反射,而是对应的感应器镜面对称了一下的话 左下角红色的地方是原始的的方格,剩下的三个格 ...
- 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) 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- django——FBV与CBV
引言 FBV FBV(function base views) 就是在视图里使用函数处理请求. 在之前django的学习中,我们一直使用的是这种方式,所以不再赘述. CBV CBV(class bas ...
- python下的并发编程
阅读目录 一 背景知识 二 python并发编程之多进程 三 python并发编程之多线程 四 python并发编程之协程 五 python并发编程之IO模型 六 补充:paramiko模块 七 作业 ...
- 使用python处理地理数据:Geopandas
说句实话处理地理数据使用python还是比较麻烦的
- XVIII Open Cup named after E.V. Pankratiev. Grand Prix of Saratov
A. Three Arrays 枚举每个$a_i$,双指针出$b$和$c$的范围,对于$b$中每个预先双指针出$c$的范围,那么对于每个$b$,在对应$c$的区间加$1$,在$a$处区间求和即可. 树 ...
- jQuery 对象 等操作
/////////////////////下面为文件夹重命名功能区///////////////////////// $(".wpul .rename").click(functi ...
- 关于Android studio 设置点击打不开的解决
今天早上觉得字体太小了想改下字体发现设置点不开,后来发现是打了汉化包的bug,后来换了一个汉化包就能打开了.
- __x__(46)0910第六天__框架集
框架集frameset 和 内联框架iframe 的作用类似: 在一个页面中,引入其他的外部html页面. 框架集可以同时引入多个页面. 在 html5 中,推荐使用框架集,而不推荐使用iframe ...
- Hadoop-2.9.2单机版安装(伪分布式模式)(一)
一.环境 硬件:虚拟机VMware.win7 操作系统:Centos-7 64位 主机名: hadoopServerOne 安装用户:root软件:jdk1.8.0_181.Hadoop-2.9.2 ...
- WinForm打包或部署
一.新建InstallShield项目 二. 三. 四. 五. 六. 七. 最后重新生成,安装包一般在E\Setup1\Setup1\Express\SingleImage\DiskImages\DI ...
- 构建Dubbo-2.0.7源码
一. 下载源码: git clone --branch dubbo-2.0.7 https://github.com/apache/incubator-dubbo.git 二. 下载依赖 git cl ...