الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

المساعدة في حل مسألة تتعلق المصفوفات ...

بدأه hamany-pirlo في 1 يوليو 2011 · 1 رد · 506 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ...

لدي مسألة (في المرفقات) ، و هذه محاولتي ...

#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;
}

هل بإمكان أحدكم مساعدتي wacko.gif

anarc2008-matrix.pdf

تم تعديل هذه المشاركة بواسطة hamany-pirlo في 1 يوليو 2011 في 06:05

Program every day for 20 years and you will become a good programmer. Program every day for 10 years and study algorithms on the side and you will become a great programmer !

على الأقل هذا اللي سمعته ...

#2

شكرا للمساعدة wink.gif

تم بعون الله القضاء على المسألة cool.gif

Program every day for 20 years and you will become a good programmer. Program every day for 10 years and study algorithms on the side and you will become a great programmer !

على الأقل هذا اللي سمعته ...

مواضيع مشابهة