السلام عليكم ...
لدي مسألة (في المرفقات) ، و هذه محاولتي ...
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;
ifstream in("matrix.in");
int result(int N, int R, int S, int E, int inverse)
{
const int half = pow(2, N-1);
// reached the base case
if (N==0)
return inverse;
// if R is in the upper half
else if (R < half)
{
if (E<half) /*if the sum required is in the first quarter*/
return result(N-1, R, S, E, inverse);
if (S>=half) /*if the sum required is in the second quarter*/
return result(N-1, R, S-half, E-half, inverse);
else /*if the sum required is shared between the first and the second quarter*/
return ( result(N-1, R, S, half-1, inverse)+result(N-1, R, half, E, inverse) );
}
// if R is in the lower half
else
{
if (E<half) /*if the sum required is in the third quarter*/
return result(N-1, R-half, S, E, inverse);
else if (S>=half) /*if the sum required is in the fourth quarter*/
return result(N-1, R-half, S-half, E-half, inverse*-1);
else /*if the sum required is shared between the third and the fourth quarter*/
return ( result(N-1, R-half, S, half-1, inverse)+result(N-1, R-half, half, E, inverse*-1) );
}
}
int main()
{
int N, R, S, E;
in>>N>>R>>S>>E;
while (N!=-1 && R!=-1 && S!=-1 && E!=-1)
{
cout<<result(N, R, S, E, 1)<<endl;
in>>N>>R>>S>>E;
}
return 0;
}هل بإمكان أحدكم مساعدتي ![]()