sgu 150 分类: sgu 2015-04-28 17:42 38人阅读 评论(0) 收藏


算是数学题吧。


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

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

posted @ 2015-04-28 17:42  <Dash>  阅读(214)  评论(0编辑  收藏  举报