Cod sursă (job #241840)

Utilizator avatar bureaalex alexburea bureaalex IP ascuns
Problemă Romb2 (clasele 9-10) Compilator cpp | 1.37 kb
Rundă Arhiva de probleme Status evaluat
Dată 31 mai 2016 12:28:32 Scor 100
#include<stdio.h>
typedef struct {double x;double y;} point;
inline int parte(point nr1,point nr2,point nr3)
{
    double a=nr1.y-nr2.y,b=nr2.x-nr1.x,c=nr2.x*nr1.y-nr2.y*nr1.x;
    double nr=nr1.x*nr2.y+nr2.x*nr3.y+nr3.x*nr1.y-nr2.y*nr3.x-nr3.y*nr1.x-nr1.y*nr2.x;
	if(nr>0)
        return 1;
    return -1;
}
int main(){
    FILE *fin,*fout;
    fin=fopen("romb2.in","r");
    fout=fopen("romb2.out","w");
    int t;
    fscanf(fin,"%d",&t);
    while(t){
        int k;
        double dx,dy;
        point c;
        fscanf(fin,"%lf%lf%d%lf%lf",&dx,&dy,&k,&c.x,&c.y);
        long long cur=1;
        double slope=dy/dx;
        while(k){
            int or1,or2;
            if(slope*c.x<c.y)
                or1=1;
            else
                or1=0;
            if(-(slope*c.x)<c.y)
                or2=1;
            else
                or2=0;
            dx/=2;
            dy/=2;
            if(or1==1&&or2==1){
                cur=cur*4LL-3LL;
                c.y-=dy;
            }
            else if(or1==1&&or2==0){
                cur=cur*4LL-2LL;
                c.x+=dx;
            }
            else if(or1==0&&or2==0){
                cur=cur*4LL-1LL;
                c.y+=dy;
            }
            else{
                c.x-=dx;
                cur=cur*4LL;
            }
            k--;
        }
        fprintf(fout,"%lld\n",cur);
        t--;
    }
    return 0;
}