Thursday, January 24, 2008

Back To High School Physics : Problem No.10071

#include<iostream>

using namespace std;

int main()
{
int a,b;

cin>>a>>b;

while(cin>>a>>b)
{
cout<<2*a*b<<endl;
if(a==-1 && b==-1)
{
break;
}
}
}

Problem submitted with runtime = 0.410

Do comment for better algorithm or lesser runtime solution.

Box of bricks : Problem No.591

#include<iostream>
#include<cmath>
using namespace std;

int main()
{
int total,x,k=0,t=0,j=1,i=0;
int nos[50];

cin>>total;

while(total!=0)
{

for(i=0;i<total;i++)
{
cin>>x;
nos[i]=x;

t=t+nos[i];
}
t=t/total;

for(i=0;i<total;i++)
{
if((nos[i]>t) || (nos[i]<t))
{
k = k + abs(nos[i]-t);
}
}

cout<<"Set #"<<j<<endl<<"The minimum number of moves is "<<k/2<<"."<<endl<<endl;

t=0;
k=0;
j++;
cin>>total;

}
}

Problem submitted with runtime = 0.000

Do comment for better algorithm.

3n+1 problem : Problem No.100

#include<iostream>

using namespace std;

int cyc(int);

int main()

{

int a,b,i,t;

while(cin>>a>>b)

{

if(a==0 && b==0)

{

break;

}

else

{

t=0;

if(b>a)

{

for(i=a;i<=b;i++)

{

if(cyc(i)>t)

{

t=cyc(i);

}

}

}

else

{

for(i=b;i<=a;i++)

{

if(cyc(i)>t)

{

t=cyc(i);

}

}}

cout<<a<<" "<<b<<" "<<t<<endl;

}

}

}

int cyc(int n)

{

int i=1;

while(n!=1)

{

if((n%2)!=0)

{

n=3*n+1;

}

else

{

n=n/2;

}

i++;

}

return i;

}



Problem submitted with runtime = 0.860

Do comment for better algorithm or lesser runtime solution.


What this blog is all about ??

In this blog I will discuss problems from ACM archive, both from 'Problem Set Volumes' and 'Contest Volumes'. I will discuss here the problems I submitted and their solutions. Any other or better algorithm for any problem is always welcome.

Problem Set Archive

Problem Set Archive can be found at --->

http://acm.uva.es/problemset/


Register at new site --->

http://icpcres.ecs.baylor.edu/onlinejudge/index.php

What is acm?

ACM(Association for computing machinery) is widely recognized as the premier membership organization for computing professionals, delivering resources that advance computing as a science and a profession; enable professional development; and promote policies and research that benefit society.

Know more about it at

http://www.acm.org
or
http://www.en.wikipedia.org/wiki/Association_for_Computing_Machinery