here is only basic implementation of problems for beginners. If you have any problem with any solution or any basic concept of programming or you want more efficient solution you can mail me.
my suggestion is not to copy and paste codes from here try to understand the logic and think why you were not able to solve it.

Tuesday, 9 September 2014

Brodovi

#include <stdio.h>
int main(){
int i, j, d, n, l, c = 0,a[5000],f[5000]={0};
scanf("%d", &n);
for(i = 0; i < n; i++) 
    scanf("%d", &a[i]);
for(i = 1; i < n; i++) {
if(f[i]==0) {
f[i] = 1;
d = a[i] - 1;
l = a[i];
c++;
for(j = i + 1; j < n; j++) {
if(l + d == a[j]) {
f[j] = 1;
l = a[j];
}
}
}
}
printf("%d\n", c);
return 0;
}

No comments:

Post a Comment