Wednesday 13 April 2016

Solution of URI 1160 :: Population Increase


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int n, c, m;
    int a, b;
    double ac, bc;
    scanf("%d", &n);
    for(m=1; m<=n; m++)
    {
        c = 0;
        scanf("%d %d %lf %lf", &a, &b, &ac, &bc);
        while(a <= b)
        {
            a *= (ac / 100.0) + 1.0;
            b *= (bc / 100.0) + 1.0;
            c++;
            if (c > 100)
            {
                printf("Mais de 1 seculo.\n");
                break;
            }
        }
        if (c <= 100)
            printf("%d anos.\n", c);
    }
    return 0;
}



7 comments:

  1. Hello, why the +1 in a *= (ac / 100.0) + 1.0;
    b *= (bc / 100.0) + 1.0;
    ?
    Is this the same as
    R += ((int)(( (0.01*G1)-(0.01*G2) )*PA)); ?

    ReplyDelete
  2. bujte parlam na formula ta

    ReplyDelete
  3. Can you tell me please what are the differences between your code and my code (given below) ?

    #include

    int main()
    {
    int t,pa,pb,i,count;
    double g1,g2;

    scanf("%d",&t);

    for(i=1;i<=t;i++)
    { count =0;
    scanf("%d %d %lf %lf",&pa,&pb,&g1,&g2);
    while(pa<=pb)
    {

    pa *= (g1/100.0)+1.0;
    pb *= (g2/100.0)+1.0;

    count++;
    if(count>100)
    {
    printf("Mais de 1 seculo.\n");
    break;
    }

    }

    if (count <= 100)
    printf("%d anos\n",count);
    }
    return 0;
    }

    ReplyDelete
  4. #include
    int main()
    {
    int pa,pb,count,i,n;
    double ga,gb;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
    scanf("%d %d %lf %lf",&pa,&pb,&ga,&gb);
    count=0;

    while(pa<=pb)
    {
    pa=(pa+pa*(ga/100.00));

    count++;
    pb=(pb+pb*(gb/100.00));

    if(pa>pb)

    {
    if(count>100)
    {
    printf("Mais de 1 seculo.\n");
    }
    else if(count<=100)
    {
    printf("%d anos.\n",count);
    }

    break;
    }
    }
    }
    return 0;
    }
    What is the problem of my code?
    Oj shows that it is "exceeded Time limit".
    Plz help me..

    ReplyDelete
  5. ami ei problem ta python diye korechi....amar output thik ache...but uri online judge etate error dekhacche..amar problem ta te error ta khuje pacchi na....kindly apni jodi ektu dekhten khub valo hoto....please..!!

    T=int(input())
    if(1<=T<=3000):
    count=0
    PAL=list()
    PBL=list()
    G1L=list()
    G2L=list()
    while(1):
    PA,PB,G1,G2=input().split()
    PAL.append(PA)
    PBL.append(PB)
    G1L.append(G1)
    G2L.append(G2)
    count+=1
    if(count==T):
    break
    for i in range(0,T):
    pcount=0
    pa=int(PAL[i])
    pb=int(PBL[i])
    g1=float(G1L[i])
    g2=float(G2L[i])
    if((100<=pa<=1000000)and(100<=pb<=1000000)and(pag2)and(0.1<=g1<=10.0)and(0.0<=g2<=10.0)):
    while(1):
    pa=pa+int((g1*pa)/100.0)
    pb=pb+int((g2*pb)/100.0)
    pcount+=1
    if(pa>=pb):
    break
    if(pcount>100):
    print("Mais de 1 seculo .")
    else:
    print("%i anos."%pcount)

    ReplyDelete
  6. bro why i got TLE in this program??
    #include
    using namespace std;


    int main()
    {
    int a,b;
    int i=0,n=0,s;
    double ga,gb;
    scanf("%d",&n);
    while(n>0)
    {
    scanf("%d%d%lf%lf",&a,&b,&ga,&gb);
    while(b>=a)
    {
    a+=a*ga/100;
    b+=b*gb/100;
    i++;
    }
    if(i>100)
    printf("Mais de 1 seculo.\n");
    else
    printf("%d anos.\n",i);
    n--;
    i=0;
    }
    return 0;
    }

    ReplyDelete
  7. Bro do you build this website alone or someone else??

    ReplyDelete

Note: only a member of this blog may post a comment.