Cod sursă (job #513418)

Utilizator avatar rinnaa irina focsa rinnaa IP ascuns
Problemă Romb2 (clasele 9-10) Compilator cpp | 1,37 kb
Rundă Arhiva de probleme Status evaluat
Dată 16 dec. 2019 20:32:27 Scor 0
{\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf600
{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fmodern\fcharset0 Courier;}
{\colortbl;\red255\green255\blue255;}
{\*\expandedcolortbl;;}
\paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0

\f0\fs24 \cf0 \
\pard\pardeftab720\partightenfactor0

\f1\fs26 \cf0 \expnd0\expndtw0\kerning0
#include <stdio.h>\
\
int X[4], Y[4];\
\
int main()\{\
    int t;\
    FILE *fin = fopen("romb2.in", "r");\
    FILE *fout = fopen("romb2.out", "w");\
    fscanf(fin, "%d", &t);\
    for (int i=0;i<t;++i) \{\
        int dx, dy, steps, xcity, ycity;\
        fscanf(fin, "%d%d%d%d%d", &dx, &dy, &steps, &xcity, &ycity);\
        xcity *= dy;\
        ycity *= dx;\
        dx *= dy;\
        Y[0] = -dx;\
        X[1] =  dx;\
        Y[2] =  dx;\
        X[3] = -dx;\
        long long ans = 0;\
        for (int j=0;j<steps;++j) \{\
            int a = (xcity > ycity);\
            int b = (xcity + ycity > 0);\
            int q = (a << 1) ^ (a == b);\
            xcity <<= 1;\
            ycity <<= 1;\
            xcity += X[q];\
            ycity += Y[q];\
            ans = (ans << 2) ^ q;\
        \}\
        fprintf(fout, "%lld\\n", ans + 1);\
    \}\
    fclose(fin);\
    fclose(fout);\
    return 0;\
\}\
}