sgu 150 分类: sgu 2015-04...


算是数学题吧。


#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;           
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/dashgua/p/4723034.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值