Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing 模拟
来源:互联网 发布:fastboot软件 编辑:程序博客网 时间:2024/05/16 08:36
分析:
把所有的点按照他们所在地斜线分类,斜线形如
比赛的时候快速想出了整个思路,并且紫色渡劫成功。欢迎读者关注Codeforces id:JIBANCANYANG。
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>using namespace std;#define pr(x) cout << #x << ": " << x << " " #define pl(x) cout << #x << ": " << x << endl;const int bias = int(1e5) + 13, maxn = int(2e5 + 30);struct node { int x, y, d;};struct jibancanyang{ vector<node> A[maxn], B[maxn]; int n, m, k; long long ans[bias]; void fun() { scanf("%d%d%d", &n, &m, &k); memset(ans, -1, sizeof(ans)); for (int i = 0; i < k; ++i) { node a; scanf("%d%d", &a.x, &a.y); a.d = i; A[a.y - a.x + bias].push_back(a); B[a.x + a.y].push_back(a); } int s = 0, t = 0, d = 1; long long times = 0; while (true) { int tt = t, ss = s; if (d == 1) { int y1 = t + (n - s); if (y1 <= m) { s = n, t = y1; d = 4; } else { s = s + (m - t), t = m; d = 2; } for (auto c : A[tt - ss + bias]) { if (ans[c.d] == -1) { ans[c.d] = times + abs(c.y - tt); } } } else if (d == 2) { int y1 = t - (n - s); if (y1 >= 0) { s = n, t = y1; d = 3; } else { s = s + t, t = 0; d = 1; } for (auto &c : B[tt + ss]) { if (ans[c.d] == -1) { ans[c.d] = times + abs(c.y - tt); } } } else if (d == 3) { int y1 = t - (s); if (y1 >= 0) { s = 0, t = y1; d = 2; } else { s = s - t, t = 0; d = 4; } for (auto &c : A[tt - ss + bias]) { if (ans[c.d] == -1) { ans[c.d] = times + abs(c.y - tt); } } } else { int y1 = t + (s); if (y1 <= m) { s = 0, t = y1; d = 1; } else { s = s - (m - t), t = m; d = 3; } for (auto &c : B[tt + ss]) { if (ans[c.d] == -1) { ans[c.d] = times + abs(c.y - tt); } } } times += abs(s - ss); if (s == 0 && (t == 0 || t == m)) break; if (s == n && (t == 0 || t == m)) break; } for (int i = 0; i < k; ++i) { printf("%lld\n", ans[i]); } }}ac;int main(){#ifdef LOCAL freopen("inn.txt", "r", stdin); //freopen("out.txt", "w", stdout);#endif ac.fun(); return 0;}
0 0
- 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(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)
- 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 C. Ray Tracing【模拟】
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)【A,B,C,D】
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B(模拟) && codeforce 724B Batch Sort
- 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)
- 第四周项目4-猴子选大王
- Java实现二维码QRCode的编码和解码
- C5-2 数老鼠
- C# VS2010结合SQL server 2008数据库编程方法
- Deepin(Ubuntu)安装rpm软件包 &&& 软件服务器自启动
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing 模拟
- android developer tiny share-20160926
- Arcsde表空间自动增长
- delphi7 TRzCheckTree TImageList 简单应用
- 2、使用hessian上传文件(向外提供文件的上传服务)
- Hbase 启动报org.apache.hadoop.hbase.TableExistsException: hbase:namespace
- 2016-10-9 微博第一篇;
- java如何调用其他系统的web service接口
- 介绍 Android ConstraintLayout 很不错的文章