Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing
2016-10-09 16:21
531 查看
比赛写了一小时还是改不出来有bug就弃疗回寝室了
自己其实是很怕写这种题的
虽然状态不好昨晚,但是还是不熟练
自己其实是很怕写这种题的
虽然状态不好昨晚,但是还是不熟练
#include<bits/stdc++.h> using namespace std; const int N = 1e5+5; const int INF = 0x3f3f3f3f; typedef long long ll; #define sz(x) ((int)(x).size()) int n,m,k; vector<int> m1 , m2 ; int vis[2] ; int ans ; int u , v ; int fl; void add(int &po) { if(fl) { po += m; if(po >= n){ po = 2*n - po; fl = 0; } }else { po -= m; if(po <= 0) { po = -po; fl = 1; } } } int main(){ while(~scanf("%d %d %d",&n,&m,&k)) { memset(vis,0,sizeof(vis)); memset(ans,-1,sizeof(ans)); for(int i = 1; i <= k; ++i) { scanf("%d %d",&u[i],&v[i]); } if(n < m) { swap(n,m); for(int i = 1; i <= k; ++i) swap(u[i], v[i]); } for(int i = 0; i <= n; ++i) m1[i].clear(), m2[i].clear(); for(int i = 1; i <= k; ++i) { if(u[i]-v[i] >= 0) m1[u[i]-v[i]].push_back(i); else m2[v[i]-u[i]].push_back(i); if(u[i]+v[i] < n) m2[u[i]+v[i]].push_back(i); else m1[2*n-v[i]-u[i]].push_back(i); } int po = 0; ll ti = 0; fl = 1; while(1) { if(vis[fl][po]) break; // printf("%d %d\n",po,fl); vis[fl][po] = 1; for(int i = 0; i < sz(m1[po]); ++i) { int x = m1[po][i]; if(ans[x] == -1) { if(fl) ans[x] = ti + v[x]; else ans[x] = ti - v[x]; } } for(int i = 0; i < sz(m2[po]); ++i) { int x = m2[po][i]; if(ans[x] == -1) { if(fl && po != 0) ans[x] = ti-v[x]; else ans[x] = ti+v[x]; } } add(po); add(po); ti += 2*m; } for(int i = 1; i <= k; ++i) printf("%lld\n",ans[i]); } return 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 (模拟或扩展欧几里得)
- 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
- Coderforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort(暴力)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar(水题)
- Intel Code Challenge Final Round C. Ray Tracing【模拟】
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) -- C. Ray Tracing(STL乱搞)
- codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) 题解(A-D)
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar(水题)
- Codeforces Round Intel Code Challenge Final Round C. Ray Tracing
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)题解报告
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) -- B. Batch Sort(暴力枚举)
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E. Goods transportation 动态规划