by Jesmin Akther | Jan 14, 2019 | Problem Solving, UVa
UVA Problem 640 ( Self Numbers): Is a basic UVa problem.
Details link:
Problem Details:
This is a Straightforward problem.
problem solution:
#include <stdio.h>
#include <math.h>
int d[1000010];
int generator(int num)
{
int sum = num;
while(num > 0)
{
sum += num%10;
num /= 10;
}
return sum;
}
int main()
{
int i;
//for(i=1;i<=100;i++)
for(i=1;i<=1000000;i++)
{
if(d[i] == 0)
printf("%d\n",i);
d[generator(i)] = 1;
}
return 0;
}
by Jesmin Akther | Jan 14, 2019 | Problem Solving, UVa
#include<bits/stdc++.h>
#define PI acos(-1)
using namespace std;
int main ()
{
double dis_of_sate ,angle,r;
char s[4];
while(cin>>dis_of_sate>>angle>>s) // circle (arc) length s=r*theta. (chord) length = 2*rsin(C/2)
{
if(s[0]=='m') angle/=60;
if(angle>180)
angle=360-angle; // tribhujer kono kon 180 er boro hoy na
r=dis_of_sate + 6440;
angle=PI*angle/180;
printf("%.6lf %.6lf\n",r*angle,2*r*sin(angle/2));
}
return 0;
}
by Jesmin Akther | Jan 14, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
#include <math.h>
#define pi acos(0.0)
//#define pi 3.1416
int main()
{
double n;
while(scanf("%lf",&n) != EOF )
{
//poligon_inte_angle = (3/5)*180=(108 degree)as figure sides n=5;
//square_inte_angle = (2/4)*90=(63 degree) as figure sides n=4;
printf("%.10lf\n",( n*sin(108*pi/90 ) / sin(63*pi/90) ));//* pi/90
}
return 0;
}
by Jesmin Akther | Jan 14, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main()
{
double a,b,c,ans,s;
while(scanf("%lf %lf %lf",&a,&b,&c) == 3 )
{
s=(a+b+c)/2;
ans=sqrt(s*(s-a)*(s-b)*(s-c));
if(ans>0)
printf("%.3lf\n",ans*(4.0/3.0));
else
{
ans=-1;
printf("%.3lf\n",ans);
}
}
return 0;
}
by Jesmin Akther | Jan 14, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
#include<iostream>
#include<math.h>
#define pi 2*acos(0.0)
using namespace std;
int main()
{
double n,x,y,a,R,r,A,A1,A2,spect,offic;
int c=0;
while(scanf("%lf %lf",&n,&A)==2 && n>=3)
{
r=sqrt((2*A)/(n*sin(2*pi/n))); //2. Given the radius (circumradius); area(A)=((r^2)nsin(360/n)/2)
R=sqrt( A/(n*tan(pi/n))); //Given the apothem (inradius) area=a^2 ntan(180/n);
//printf("Case %d: %.5lf %.5lf\n",i,R,r);
A1=pi*r*r;
A2=pi*R*R;
spect = A1-A;
offic = A-A2;
printf("Case %d: %.5lf %.5lf\n",c+1,spect,offic);
c++;
}
return 0 ;
}
by Jesmin Akther | Jan 14, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main()
{
int tc;
cin>>tc;
while (tc) {
double ha, hb, hc,a,b,c;//s,s1,a1,b1,c1,a,b,c;
scanf("%lf%lf%lf", &ha, &hb, &hc);
a=1/ha,b=1/hb,c=1/hc;
double s1=(a + b + c);
double a1=(-a + b + c);
double b1=(a - b + c);
double c1=(a + b - c);
double s=s1*a1*b1*c1;
if (s <= 0)
{
printf("These are invalid inputs!\n");
tc--;
}
else if (ha == 0 || hb == 0 || hc == 0)
{
printf("These are invalid inputs!\n");
tc--;
}
else {
printf("%.3f\n", 1 / sqrt(s));
}
}
return 0;
}
by Jesmin Akther | Jan 14, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
#define PI 2*acos(0)
using namespace std;
int main()
{
int n,tc,i,j;
char t[2];
cin>>tc;
while(tc--)
{
int a,b;
cin>>a;
if(getchar()=='\n')
{
printf("%.4lf\n", (2*a*a*PI)/16);
}
else
{
cin>>b;
printf("%.4lf\n", 2*a*b*PI);
}
}
return 0;
}
by Jesmin Akther | Jan 14, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N,a,M,rr;
double x,y;
while(scanf("%d %d",&N,&a)!=EOF && N)
{
bool f = true;
M = 0;
rr = a*a;
for(int i = 0;i<N;++i)
{
scanf("%lf %lf",&x,&y);
f = true;
if((x-0)*(x-0)+(y-0)*(y-0)>rr) //(x1,y1)(x2,y2) bindu gula: (0,0)(0,0)
f = false; //(0,a)(0,a);(a,0)(a,0);(a,a)(a,a)
if((x-0)*(x-0)+(y-a)*(y-a)>rr)
f = false;
if((x-a)*(x-a)+(y-0)*(y-0)>rr)
f = false;
if((x-a)*(x-a)+(y-a)*(y-a)>rr)
f = false;
if(f)
{
M++;
}
}
printf("%.5f\n",(double)M*(a*a)/N);
}
return 0;
}
by Jesmin Akther | Jan 14, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
#define PI 2*acos(0)
using namespace std;
int main()
{
double d,l,D,L,i,r1,r2;
int tc;
double ans;
cin>>tc;
while(tc--)
{
cin>>D>>L;
d=D/2.0;
l=L/2.0;
r1=sqrt((L/2 * L/2) - (D/2 * D/2));
printf("%.3f\n",PI*r1*l);
}
return 0;
}
by Jesmin Akther | Jan 14, 2019 | Problem Solving, UVa
#include<bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
double c1,c2,c3,a,b,c,s,ang1,ang2,ang3,arc1,arc2,arc3,area,area1,area2;
int tc;
scanf("%d",&tc);
while(tc--){
scanf("%lf%lf%lf",&c1,&c2,&c3);
a=c1+c2;
b=c2+c3;
c=c1+c3;
s =(a+b+c)/2.0;
area1 = sqrt(s*(s-a)*(s-b)*(s-c));
ang1 = acos((b*b+c*c-a*a)/(2*b*c));
ang2 = acos((c*c+a*a-b*b)/(2*c*a));
ang3 = acos((a*a+b*b-c*c)/(2*a*b));
arc1 =(c3*c3*ang1) ;
arc2 =(c2*c2*ang3);//arc2 =(c3*c3*ang3) ;//arc2 =(c2*c2*ang3) ;
arc3 =(c1*c1*ang2); //arc3 =(c2*c2*ang2);*///arc3 =(c1*c1*ang2);
area2 = (arc1 +arc2 +arc3 )/2;
printf("%.6lf\n",area1-area2);
}
return 0;
}
by Jesmin Akther | Jan 14, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int s,n;
int first_term,last_term;
while (scanf("%d", &s), s != -1)
{
int n_sum =(int)sqrt(2*s);
for (n = n_sum ; n > 0; n--)
{
if ( (2 * s + n - n * n) % (2 * n) == 0 )
{
first_term = (2 * s + n - n * n) / (2 * n);
last_term = first_term + n - 1;
break;
}
}
printf("%d = %d + ... + %d\n", s, first_term, last_term);
// return 0* printf("%d = %d + ... + %d\n", s, a, last_term);
}
return 0;
}
by Jesmin Akther | Jan 14, 2019 | Problem Solving, UVa
#include <stdio.h>
long int arr[1000002];
void array ()
{
long int k=0,i;
arr[3]=0;
for( i = 4; i <= 1000000; i++)
{
k = k + ((i-2)/2);
arr[i] = arr[i-1] + k;
}
}
int main()
{
//array();
long int n;
array();
while(scanf("%ld",&n) && n >= 3)
printf("%ld\n",arr[n]);
return 0;
}
by Jesmin Akther | Jan 14, 2019 | Problem Solving, UVa
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
int T,p,q,r,s,t,u;
double lo,hi,mi,f;
while(scanf("%d %d %d %d %d %d",&p,&q,&r,&s,&t,&u)==6)
{
if(p*exp(-1)+q*sin(1)+r*cos(1)+s*tan(1)+t+u>1e-9 || p+r+u<0)
{
printf("No solution\n");
continue;
}
lo=0.0; hi=1.0;
for(int i=0;i<30;i++){
mi=(lo+hi)/2;
f=p*exp(-mi)+q*sin(mi)+r*cos(mi)+s*tan(mi)+t*mi*mi+u;
if(f>0) lo=mi;
else hi=mi;
}
printf("%.4f\n",lo);
}
return 0;
}
by Jesmin Akther | Jan 14, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
long double func_tion (long double n)
{
long double i,r = 1;
for ( i = 2; i <= n; i++)
{
r *= i;
}
return r;
}
int main ()
{
long double M, N,r,n,m;
while (cin>>N>>M)
{
if( N==0 and M==0 ) break;
n=(func_tion(N));
m=(func_tion(N-M)*func_tion(M));
r = n/m;
cout << N << " things taken " << M << " at a time is " << setprecision(0) << r << " exactly." << endl;
}
return 0;
}
by Jesmin Akther | Jan 14, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int tc;
char s[2000],l;
cin>>tc;
while (tc--)
{
scanf("%s", s);
l = strlen(s);
if (strcmp(s, "1") == 0 || strcmp(s, "4") == 0 || strcmp(s, "78") == 0)
printf("+\n");
else if ( s[l - 1] == '5' && s[l - 2] == '3')
printf("-\n");
else if (s[0] == '9' && s[l - 1] == '4')
printf("*\n");
else if (s[0] == '1' && s[1] == '9' && s[2] == '0')
printf("?\n");
else
printf("+\n");
}
return 0;
}
by Jesmin Akther | Jan 14, 2019 | Problem Solving, UVa
#include<bits/stdc++.h>
using namespace std;
int main()
{
double n;
int cases;
int cont=0;
while(cin>>n){
cont=0;
for(cases=1;;)
{
if((cases%2)==1)
{
n/=9;
cont++;
}
else
{
n/=2;
cont++;
}
if(n<=1)
{
break;
}
cases++;
}
if(cont%2==1)
printf("Stan wins.\n");
else
printf("Ollie wins.\n");
}
return 0;
}
by Jesmin Akther | Jan 14, 2019 | Problem Solving, UVa
#include<stdio.h>
#include<string.h>
int main()
{
int l,i,j,count=0;
char s[100000];
while(gets(s))
{
l=strlen(s);
for(i=0;i<l;i++)
{
switch(s[i])
{
case 'b':
{
for(j=0;j<count;j++)
printf(" ");
count=0; break;
}
case '1':
count=count+1; break;
case '2':
count=count+2; break;
case '3':
count=count+3; break;
case '4':
count=count+4; break;
case '5':
count=count+5; break;
case '6':
count=count+6; break;
case '7':
count=count+7; break;
case '8':
count=count+8; break;
case '9':
count=count+9; break;
case '!':
printf("\n");
default:
{
for(j=0;j<count;j++)
printf("%c",s[i]);
count=0; break;
}
}
}
printf("\n");
}
return 0;
}