Pagini recente » Cod sursa (job #2266737) | Cod sursa (job #2252232) | Cod sursa (job #2277555) | Cod sursa (job #3213436) | Cod sursa (job #1490887)
#include<fstream>
using namespace std;
ifstream in("robotei.in");
ofstream out("robotei.out");
const int nmax = 11006, mmax = 700006;
int n, m, x, y, modx, mody, osx, osy, a, lg, b, sol[mmax], urmx[nmax], urmy[nmax], d[nmax][nmax], cate[nmax][nmax];
bool viz[nmax][nmax];
int nextx(int x){
return (1LL * x * x + osx) % modx;
}
int nexty(int y){
return (1LL * y * y + osy) % mody;
}
int distanta(int x, int y){
if(viz[x][y])
return d[x][y];
viz[x][y] = 1;
d[x][y] = distanta(urmx[x] , urmy[y]);
if(d[x][y])
d[x][y]++;
return d[x][y];
}
int main()
{
int player_unu=0;
in>>n>>m>>x>>y>>modx>>mody>>osx>> osy;
n--;
for(int i = 0; i<modx ; i++)
urmx[i] = nextx(i);
for(int j = 0; j<mody ; j++)
urmy[j] = nexty(j);
a = nextx(x);
b = nexty(y);
lg = 1;
while(x!=a || y!=b)
{
a = urmx[a];
b = urmy[b];
++ lg;
if(lg==modx * mody)
break;
}
if(lg==modx * mody)
lg = m + 1;
d[x][y] = 1;
viz[x][y] = 1;
for(int i = 0 ; i<modx ; i++)
for(int j = 0 ; j<mody ; j++)
if(viz[i][j]==0)
d[i][j] = distanta(i , j);
for(int i = 0 ; i<modx ; i++)
for(int j = 0 ; j<mody ; j++)
{
cate[i][j] = (1 + (n - i) / modx) * (1 + (n - j) / mody);
}
for(int i = 0 ; i<modx ; i++)
for(int j = 0 ; j<mody ; j++)
if(d[i][j])
{
-- d[i][j];
if(d[i][j] && d[i][j] <= m)
d[i][j] = 1 + (m - d[i][j]) / lg;
}
d[x][y] = 1 + m / lg;
for(int i = 0 ; i<modx ; i++)
for(int j = 0 ; j<mody ; j++)
sol[d[i][j]] += cate[i][j];
sol[d[x][y]] -= cate[x][y];
++ sol[d[x][y]] ;
sol[d[x][y] - 1] += cate[x][y] - 1;
for(int i = 0 ; i<=m ; i++)
if(sol[i]!=0)
out<<i<<' '<<sol[i]<<'\n';
return player_unu;
}