-
I. 1.
C. !( (n % 5 != 0) || (n % 20 == 0) )
II. 2.
a) 26
b) 511
c)
subprogram FRec(n, t)
DACA n = 0 ATUNCI
RETURNEAZA 0
ALTFEL
DACA n % 2 = 0 ATUNCI
RETURNEAZA t + FRec(n / 2, t * 2)
ALTFEL
RETURNEAZA F(n / 2, t * 2)
d)
#include <iostream>
using namespace std;
int F(int n){
int p = 0, t = 1;
while(n != 0){
if(n % 2 == 0)
p = p + t;
n = n / 2;
t = t * 2;
}
return p;
}
II. 1.
B. 94
II. 2.
C. (1,1,2,3,4,5)
II. 3.
#include <iostream>
using namespace std;
int compute(int a){
int cnt = 0, cp = a, o = 0;
while(cp > 0){
cnt++;
if(cp % 10 == 0)
return -1;
o = o * 10 + cp % 10;
cp /= 10;
}
if(cnt < 4)
return -1;
int n = 0, m = 0;
cnt = 0;
while(o > 0){
cnt++;
if(cnt % 2 == 1)
n = n * 10 + o % 10;
else
m = m * 10 + o % 10;
o /= 10;
}
int uc1 = 0, uc2 = 0;
uc1 = n * n % 10;
for(int i = 3; i <= m; i++)
uc1 = uc1 * n % 10;
uc2 = n % 10;
n--;
while(n > 1){
uc2 = uc2 * n % 10;
n--;
}
if((uc1 - uc2 - 1) % 10 == 0)
return 1;
return 0;
}
int main(){
int a;
cin>>a;
cout<<compute(a);
}
II. 4.
a)
0 0 1 0 0 0 0
0 0 0 0 1 0 1
0 0 0 1 0 0 0
1 0 0 0 0 0 0
0 0 0 0 0 1 0
0 1 0 0 0 0 0
0 1 0 0 0 0 0
b)
int pre(int D[105][105], int m, int n int i){
for(int j = 0; j < m + n; j++)
if(D[j][i] == 1)
return j;
}
c)
int garages(int D[105][105], int m, int n, int i){
for(int x = m; x < m + n; x++){
int pre = prev(D, m, n, x);
while(pre >= m){
pre = prev(D, m, n, x);
}
cout<<pre<<" ";
}
}
III. 1.
12
III. 2.
A. 11
III. 3.
a) Nodurile 1, 3, 6 au fiecare cate 3 culori accesibile distincte.
b)
void dfs(int k, int nrc, int n, int a[105][105], int col[105], int f[105], int cnt, int cc[105]){
cc[k] = nrc;
for(int i = 0; i < n; i++)
if(a[k][i] == 1 && cc[i] == 0){
if(f[col[i]] == 0)
cnt++, f[col[i]] = 1;
dfs(i, nrc, n, a, col, f, cnt, cc);
}
}
int maxColor(int n, int c, int a[105][105], int col[105]){
int cntmax = -1, cnt = -1, sol = -1;
int f[c + 1], cc[n + 1], nrc = 0;
for(int i = 0; i < n; i++){
if(!cc[i]){
cnt = 0;
nrc++;
for(int j = 0; j < n; j++)
f[j] = 0;
dfs(i, nrc, n, a, col, f, cnt);
if(cntmax < cnt || cntmax == -1)
sol = i, cntmax = cnt;
}
}
}
b)
int maxConnect(int n, int c, int a[105][105], int col[105]){
int cntmax = maxColor(n, c, a, col);
int cnt_i = cntmax;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if(i != j && a[i][j] == 0){
a[i][j] = a[j][i] = 1;
int cnt = maxColor(n, c, a, col);
if(cntmax < cnt)
cntmax = cnt;
a[i][j] = a[j][i] = 0;
}
}