Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing
来源:互联网 发布:淘宝商城客服 编辑:程序博客网 时间:2024/05/16 01:53
我不告诉你这个链接是什么
分析:模拟可以过,但是好烦啊。。不会写。还有一个扩展欧几里得的方法,见下:
假设光线没有反射,而是对应的感应器镜面对称了一下的话
左下角红色的地方是原始的
假设光线没有经过反射,那么用函数可以表示为
对于一个点,光线的真实情况是可能会经过多次,这意味着一个点以及它的镜像点可能有多个在
代码:
/*****************************************************///#pragma comment(linker, "/STACK:1024000000,1024000000")#include <map>#include <set>#include <ctime>#include <stack>#include <queue>#include <cmath>#include <string>#include <vector>#include <cstdio>#include <cctype>#include <cstring>#include <sstream>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;#define offcin ios::sync_with_stdio(false)#define sigma_size 26#define lson l,m,v<<1#define rson m+1,r,v<<1|1#define slch v<<1#define srch v<<1|1#define sgetmid int m = (l+r)>>1#define LL long long#define ull unsigned long long#define mem(x,v) memset(x,v,sizeof(x))#define lowbit(x) (x&-x)#define bits(a) __builtin_popcount(a)#define mk make_pair#define pb push_back#define fi first#define se secondconst int INF = 0x3f3f3f3f;const LL INFF = 1e18;const double pi = acos(-1.0);const double inf = 1e18;const double eps = 1e-9;const LL mod = 1e9+7;const int maxmat = 10;const ull BASE = 31;/*****************************************************///对于不定整数方程pa+qb=c,若 c mod Gcd(a, b)=0,则该方程存在整数解,否则不存在整数解//p = p1 + b/Gcd(a, b) * t //q = q1 - a/Gcd(a, b) * t(其中t为任意整数,正负皆可)LL exgcd(LL a,LL b,LL &x,LL &y) { if(!b) {x=1; y=0; return a; } LL r=exgcd(b,a%b,y,x); y-=a/b*x; return r;}bool solve_equ(LL a,LL b,LL ca,LL cb,LL &x,LL &y,LL &d,LL &ans) { LL c = ca + cb; d = exgcd(a, b, x, y); if(c % d) return false; LL k = c / d; LL g = b / d; if (g < 0) g = -g; g *= a; x *= k; y *= k; ans = a * x - cb; ans = (ans % g + g) % g; return true;}int main(int argc, char const *argv[]) { int N, M, K; cin>>N>>M>>K; LL over = INFF; for (int i = 0; i < 3; i ++) { LL a, b; if (i == 0) a = N, b = M; else if (i == 1) a = 0, b = M; else a = N, b = 0; LL x, y, d, res, ans = INFF; for (int k = 0; k < 4; k ++) { LL tmpa = a, tmpb = b; if (k & 1) tmpa = -tmpa; if ((k >> 1) & 1) tmpb = -tmpb; if (solve_equ(2 * M, -2 * N, tmpa, tmpb, x, y, d, res)) ans = min(ans, res); } over = min(over, ans); } while (K --) { LL a, b; cin>>a>>b; LL ans = INFF, x, y, d, res; for (int k = 0; k < 4; k ++) { LL tmpa = a, tmpb = b; if (k & 1) tmpa = -tmpa; if ((k >> 1) & 1) tmpb = -tmpb; if (solve_equ(2 * M, -2 * N, tmpa, tmpb, x, y, d, res)) ans = min(ans, res); } if (ans == INFF || (over != INFF && ans > over)) puts("-1"); else cout<<ans<<endl; } return 0;}
0 0
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) -- C. Ray Tracing(STL乱搞)
- 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
- 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 模拟+预处理、几何
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing 数学
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)【A,B,C,D】
- Codeforces Round Intel Code Challenge Final Round C. Ray Tracing
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
- Coderforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- 算法之乐:一个算法解决3道经典二叉树面试题(深度、长度、直径)
- android volley封装及源码解析
- 2、lib7z-Memory从内存或网络解压数据(分析源码,修改源码)
- 【原创】有向图的搜索
- cocoa pods的安装与使用
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing
- Linux内存管理之mmap详解
- Java 中 synchronized的用法详解(四种用法)
- 两个链表的第一个公共结点
- TensorFlow之深入理解Neural Style
- 链表简述
- Android include和merge标签、ViewStub控件的使用总结
- 第一章html练习3:家用电器排行榜
- Ubuntu创建android studio桌面图标