sgu 150 分类: sgu 2015-04-28 17:42 38人阅读 评论(0) 收藏
2015-04-28 17:42
344 查看
算是数学题吧。
#include<map> #include<queue> #include<stack> #include<ctime> #include<cmath> #include<string> #include<cstdio> #include<utility> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> const int INF = 1<<30; struct Vector{int x,y;Vector(int x = 0,int y = 0):x(x),y(y){}}; bool flag = false; int cmp(int a,int b) { if(b > a) return 1; else if(b < a) return -1; else return 0; } int main() { Vector move; int x1,x2,y1,y2,n; int ansx,ansy; int sx,sy,cnt = 0; #ifndef ONLINE_JUDGE freopen("sgu150.in","r",stdin); freopen("sgu150.out","w",stdout); #endif std::cin >> x1 >> y1 >> x2 >> y2 >> n; sx = cmp(x1,x2), sy = cmp(y1,y2); move = Vector(abs(x2-x1),abs(y2-y1)); if(move.x && move.y) for(int x = 1, yl = 0, yn, yt; x <= abs(x2-x1) && !flag ; x ++) { yn = (long long)x*move.y/move.x; yt = (long long)x*move.y%move.x; cnt += yn - yl + (yt?1:0); if(cnt >= n) { flag = true; ansx = x - 1, ansy = yn - (cnt-n) - (yt?0:1); if(sx < 0) ansx = -(ansx + 1); if(sy < 0) ansy = -(ansy + 1); ansx += x1, ansy += y1; } yl = yn; } if(flag) std::cout << ansx << ' ' << ansy << std::endl; else std::cout << "no solution" << std::endl; #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0; }
相关文章推荐
- sgu143 分类: sgu 2015-03-11 22:11 38人阅读 评论(0) 收藏
- sqoop 和mysql相关操作 分类: Linux hadoop 2015-06-02 22:42 38人阅读 评论(0) 收藏
- sgu 259 分类: sgu 2015-06-17 01:50 19人阅读 评论(0) 收藏
- sgu 218 分类: sgu 2015-06-21 17:04 22人阅读 评论(0) 收藏
- sgu 128 分类: sgu 2015-03-13 13:56 44人阅读 评论(0) 收藏
- sgu 152 分类: sgu 2015-03-16 13:11 35人阅读 评论(0) 收藏
- PC端 java 开发蓝牙所遇到的问题 分类: Java 2015-07-30 09:12 150人阅读 评论(0) 收藏
- sgu 177 分类: sgu 2015-04-25 22:38 28人阅读 评论(0) 收藏
- winform DataGridView双击修改单元格的值 分类: DataGridView 2014-08-04 19:39 150人阅读 评论(0) 收藏
- sgu220&sgu221 分类: sgu 2015-06-15 22:01 24人阅读 评论(0) 收藏
- sgu122 分类: sgu 2015-02-15 11:39 71人阅读 评论(0) 收藏
- sgu 133 分类: sgu 2015-03-07 22:19 31人阅读 评论(0) 收藏
- sgu 175 分类: sgu 2015-03-08 16:35 53人阅读 评论(0) 收藏
- uclibc和glibc的差别 分类: arm-linux-Ubuntu 2013-08-21 17:42 499人阅读 评论(0) 收藏
- sgu239 分类: sgu 2015-06-24 22:18 22人阅读 评论(0) 收藏
- sgu 246 分类: sgu 2015-06-27 13:40 20人阅读 评论(0) 收藏
- C++疑难求解 分类: C/C++ 2015-04-17 11:36 38人阅读 评论(0) 收藏
- sgu 153 分类: sgu templates 2015-04-26 16:35 32人阅读 评论(0) 收藏
- spark原理介绍 分类: B8_SPARK 2015-04-28 12:33 1039人阅读 评论(0) 收藏
- sgu 225 分类: sgu 2015-06-15 19:24 16人阅读 评论(0) 收藏