UVA 11876 – N + NOD (N)

 

Description:

For a number N, first have to calculate  N-1+divisors(N-1) & store it in array (e.g. arr[i]=arr[i-1]+divisors(arr[i-1])).
Make a sequence from 1 to until arr[i] becomes greater than 1000000.  Then you will be given two numbers A & B,  and you will have to find the number of integers from the above sequence which lies within the range [A,B].

Hints = No critical case. Easy problem.
Continue reading

Advertisements

UVA 573 The Snail

Link: https://uva.onlinejudge.org/external/5/573.pdf

Algorithm:
Simple! Just follow the instructions. Check this line carefully “If the fatigue factor drops the snail’s climbing distance below zero, the snail does not climb at all that day. ” in input section. Because of this I suffered for a while.
Continue reading

UVA 10107 What is the Median?

UVA 10107 What is the Median?

 

Median plays an important role in the world of statistics. By definition, it is a value which divides an array into two equal parts. In this problem you are to determine the current median of some long integers. Suppose, we have five numbers {1,3,6,2,7}. In this case, 3 is the median as it has exactly two numbers on its each side. {1,2} and {6,7}. If there are even number of values like {1,3,6,2,7,8}, only one value cannot split this array into equal two parts, so we consider the average of the middle values {3,6}. Thus, the median will be (3+6)/2 = 4.5. In this problem, you have to print only the integer part, not the fractional. As a result, according to this problem, the median will be 4 !

Continue reading

UVA 11879 – Multiple of 17

11879 – Multiple of 17

Problem Link: https://uva.onlinejudge.org/external/118/11879.pdf

Algorithm: This problem is quite easy. In this, there will be a number which is greater at most 100 digits. So, Its not possible to store it in “long long int” in c++.
We will write a program which will take input a string. If the string contains only 0 then the program will be break, otherwise it will enter in another loop. Before entering I will declare two integer variables ‘reminder’ and ‘i’. I will initialize the reminder variable to 0;

 
Continue reading

414 – Machined Surfaces

Problem Link: https://uva.onlinejudge.org/external/4/414.pdf

 

#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

int main(){

    int t,i,j;
    while(1){
        scanf("%d%*c",&t);

        if(t==0)
            break;

        char a[t][25];
        for(i=0;i<t;i++)
            gets(a[i]);

        int b[t];
        for(i=0;i<t;i++)
            b[i]=0;

        for(i=0;i<t;i++){
            for(j=0;j<25;j++){
                if(a[i][j]!='X')
                    b[i]++;
            }
        }

        sort(b,b+t);
        int x=b[0];
        for(i=0;i<t;i++)
            b[i]=b[i]-x;

        int sum=0;
        for(i=0;i<t;i++)
            sum=sum+b[i];

        printf("%d\n",sum);


    }

    return 0;
}