# [hint] on Algorithm Design: T2 Mr Rahmani

• From: Reith Ameretat <ameretat.reith@xxxxxxxxx>
• To: hint@xxxxxxxxxxxxx
• Date: Mon, 19 Apr 2010 08:59:14 +0430

```Possible answers...

--
Reith
```
```unsigned int power(const int b, const int e)
{
if (e==0)
return 1;
int i=1, r = b;
while (i++<e)
r*=b;
return r;
}

int* A; //array of A indices
int* B; //array of B indices

int C (const int k, const int x, const int* const A, const int* const B)
{
int ck, i;
if (k>=0)
{
for (i=0; i<=k; i++)
ck+=A[i]*B[k-i];
return power(x, i)*ck + c(i-1);

}
return 0;
}
```
```#include <stdio.h>

static short int min = 0x7FFF;
static short int max = 0x8001 - 1;

void find (int* array, int first, int last)
{
if (first <= last)
{

if (array[first] > max)
max = array[first];
if (array[first] < min)
min = array[first];

int mid = (first+last)/2;
find (array, first+1, mid);
find (array, mid+1, last);
}
}

int main()
{
int arr[] = {54, 21, 151, -123 , 21 , 123 , 4, 15};
find (arr, 0, 7);

printf("%d, %d", min, max);
return 0;
}
```
```//Ameretat Reith
//

unsigned int power(const int b, const int e)
{
int i=1, r = b;
while (i++<e)
r*=b;
return r;
}

unsigned int remainder(const int n, const int x, const int p)
{
int xPn;
if (x<p)
if ((xPn=power(x,n))<p)
return xPn;
else
return remainder (1, xPn, p);
return remainder(n, x%p, p);
}
```
```#include <stdio.h>
#define n 4

void showTable(int (* const table)[n])
{
int d,i;
for (d=0; d<n; d++)
{
printf("\nday %d: ", d);
for (i=0; i<n; i++)
if (table[d][i]!=-1)
printf(" team `%d' vs `%d',",i, table[d][i]);
}
puts("");
}
void match(const int t1, const int t2, int (* const table)[n])
{
if (t1==n) {showTable(table); return;}
if (t2==n) {match(t1+1, t1+2, table);}
else
{
int d=0;
while ((table[d][t1]!=-1)||(table[d][t2]!=-1)){d++;}
table[d][t1]=t2;
table[d][t2]=t1;
match(t1,t2+1,table);
}

}
int main()
{
int i, j;
int matchTable [n][n];

for (i=0;i<n;i++)
for (j=0;j<n;j++)
matchTable[i][j]=-1;

match(0,1,matchTable);

return 0;
}
```

### Other related posts:

• » [hint] on Algorithm Design: T2 Mr Rahmani - Reith Ameretat