Cod sursa(job #854561)

Utilizator costel93FMI - Dumea Eduard Constantin costel93 Data 13 ianuarie 2013 18:56:26
Problema Order Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include<fstream>

using namespace std;
ifstream f("order.in");
ofstream g("order.out");

int suma[65600], poz, val;

void actualizare(int nod, int st,int dr)
{
	if(st==dr)
		suma[nod]=val;
	else
	{
		int m;
		m=(st+dr)/2;
		if(poz<=m)
			actualizare(nod*2,st,m);
		else 
			actualizare(nod*2+1,m+1,dr);
		suma[nod]=suma[nod*2]+suma[nod*2+1];
	}
}

void cauta(int nod,int st,int dr,int cat)
{
	if(st==dr)
		poz=st;
	else
	{ 
		int m;
		m=(st+dr)/2;
		if(cat<=suma[nod*2])
			cauta(nod*2,st,m,cat);
		else 
			cauta(nod*2+1,m+1,dr,cat-suma[nod*2]);
	}
                 
}

int main()
{
    int n, i, cat;

    f>>n;

    for(poz=1;poz<=n;poz++)
    { 
        val=1;
        actualizare(1,1,n);
    }

	cat=1;

	for(i=1;i<=n;i++)
    {            
		cat=(cat+i+suma[1])%suma[1];
        if(cat==0)
			cat=suma[1];
        cauta(1,1,n,cat);
        g<<poz<<" ";
        val=0;
        cat--;

    }
     
    return 0;
}