kombinatorik masalalar
Quyidagi dastur natijasini aniqlang
int funk(int *a, int l, int r)
{
return l == r ? a[l] : funk(a, l, (l + r)/2) + funk(a, (l + r)/2 + 1, r);
}
int main()
{
int a[]={1,2,3,4,5,6,7,8,9};
cout<return 0;
}
45
Quyidagi dastur natijasini aniqlang
int funk(int *a, int l, int r)
{
int x1, x2;
if (l == r)
return a[l]; else
{
x1 = funk(a, l, (l + r)/2); x2 = funk(a, (l + r)/2 + 1, r);
return x1 }
}
int main()
{
int a[]={3,9,1,5,6};
cout<}
1
Quyidagi to'plamda nechta element bor:
A={a1,a2,a3, ...a9, b1, b2, ...b9, .. z9}
a dan z gacha 26 ta harf bor.
234
Quydagi tasodifiy algoritm yordamida qidirish usuli qanday nomlanadi?
int a[11]={2,4,5,8,23,4,54,65,3,14,20};
do
{
i++;
b=rand()%11;
if(i>k) break;
cout<} while (c!=a[b]);
if(i>k) cout<<"\nIzlanayotgan son topilmadi ";
else{
cout<Monte-Karlo
srand(seed) funksiyasida seedning qiymati dastlabki holatda nimaga teng? (0,1,2,3,4,...time(0), joriy vaqt)
1
Quyidagi dastur natijasini aniqlang
int funk(int *a, int l, int r)
{
return l == r ? a[l] : funk(a, l, (l + r)/2) + funk(a, (l + r)/2 + 1, r);
}
int main()
{
int a[]={1,2,3,4,5,6,7,8,9};
cout<return 0;
}
15
srand(seed) funksiyasida seedning qiymati dastlabki holatda nimaga teng? (0,1,2,3,4,...time(0), joriy vaqt)
1
Quyidagi dastur natijasini aniqlang
int funk(int *a, int l, int r)
{
int x1, x2;
if (l == r)
return a[l]; else
{
x1 = funk(a, l, (l + r)/2); x2 = funk(a, (l + r)/2 + 1, r);
return x1 < x2 ? x1 : x2;
}
}
int main()
{
int a[]={2,7,7,5,6,5,4,3,6,7,8};
cout<}
2
Quyidagi dastur kodini tahlil qiling.
int Max(int *a, int l, int r)
{
int max1, max2;
if (l == r)
return a[l]; else
{
max1 = Max(a, l, (l + r)/2);
max2 = Max(a, (l + r)/2 + 1, r);
if (max1 > max2)
return max1;
else
return max2;
}
}
Select one:
Dostları ilə paylaş: |