Pagini recente » Cod sursa (job #3287603) | Cod sursa (job #1683481) | Cod sursa (job #2107687) | Cod sursa (job #2416523) | Cod sursa (job #1970484)
#include <fstream>
using namespace std;
int t[23][23];
int main()
{
ifstream f("robinson.in");
ofstream g("robinson.out");
int i,j,m,n,l,c;
f>>m>>n>>l>>c;
for(j=1;j<=m;j++)
{
t[j][1]=n+j-1;
t[1][j]=n+j-1;
}
for(i=2;i<=m;i++)
for(j=2;j<=m;j++)
{
t[i][j]=t[i-1][j]+t[i][j-1];
if(t[i][j]>999)
t[i][j]-=1000;
}
g<<t[m][m]<<'\n'<<l<<" "<<c<<'\n';
while(l<=m and c<=m and t[l][c]!=-1)
{
if(t[l][c]%4==0)
{
if(l-1>0 and t[l][c]!=-1)
{
t[l][c]=-1;
l--;
}
else
break;
}
else if(t[l][c]%4==1)
{
if(c+1<=m and t[l][c]!=-1)
{
t[l][c]=-1;
c++;
}
else
break;
}
else if(t[l][c]%4==2)
{
if(l+1<=m and t[l][c]!=1)
{
t[l][c]=-1;
l++;
}
else
break;
}
else if(t[l][c]%4==3)
{
if(c-1>0 and t[l][c]!=1)
{
t[l][c]=-1;
c--;
}
else
break;
}
if(t[l][c]!=-1)
g<<l<<" "<<c<<'\n';
}
return 0;
}