Cod sursa(job #1709956)

Utilizator alexandra_paticaAndreea Alexandra Patica alexandra_patica Data 28 mai 2016 14:35:10
Problema Consecutive Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 1.05 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f ("consecutive.in");
ofstream g ("consecutive.out");
struct punct
{
    int x, y, d;
}x[10001];
int t, l, k, a, j, aux, nr, i, n;
int cmp (punct u, punct v)
{
    return (u.d<v.d || (u.d==v.d && u.x<v.x) || (u.d==v.d && u.x==v.x && u.y<v.y));
}
int main ()
{
    f >> t;
    for (l=1; l<=t; l++){
        f >> nr;
        k=0;
        for (a=1; a<nr; a++){
            for (j=a+1; j<=nr; j++){
                n=j-a;
                aux=(n+1)*(a+n/2);
                if (aux==nr) {
                    k++;
                    x[k].x=a;
                    x[k].y=j;
                    x[k].d=j-a;
                }
            }
            if (a+a+1==nr){
                    k++;
                    x[k].x=a;
                    x[k].y=a+1;
                    x[k].d=1;
                }
        }
        sort(x+1,x+k+1, cmp);
        g << k << '\n';
        for (i=1; i<=k; i++)
            g << x[i].x << " " << x[i].y << '\n';
    }
    return 0;
}