পৃষ্ঠাসমূহ

শুক্রবার, ২৯ জানুয়ারী, ২০১৬

Jan’s LightOJ :: 1354 - IP Checking Solution



#include <stdio.h>
int DecBin(int n)
{
int multiplier = 1,result = 0;
while(n>0)
{

result+=n%2*multiplier;
multiplier*=10;
n/=2;

}
return result;


}
int main()
{
int T,da,db,dc,dd,ba,bb,bc,bd;
scanf("%d",&T);
int i;
for(i =0; i<T;i++)
{
scanf("%d.%d.%d.%d",&da,&db,&dc,&dd);
scanf("%d.%d.%d.%d",&ba,&bb,&bc,&bd);

if(DecBin(da)==ba&&DecBin(db)==bb&&DecBin(dc)==bc&&DecBin(dd)==bd)
printf("Case %d: Yes\n",i+1);
else
printf("Case %d: No\n",i+1);

}
return 0;


}

Jan’s LightOJ :: 1042 - Secret Origins Solution



#include <stdio.h>
int oneCount(int n)
{
int count = 0;
long long t = 1;
for(t = 1; t<=n; t*=2) {
if((n&(t))!=0) {
count++;
}

}
return count;


}
long long int next(long long int num)
{
long long res,t;
for(t = 1; t<=num; t*=2) {
if((num&(t))!=0) {
res = num+t;
break;

}

}
int diff = oneCount(num)-oneCount(res);
int i;
for(i = 0; i<diff; i++) {
res+=(1<<i);

}
return res;



}
int main()
{
int T,i,N,j;
scanf("%d",&T);
for(i =0; i<T; i++) {
scanf("%d",&N);
printf("Case %d: %lld\n",i+1,next(N));

}
return 0;



}

Jan’s LightOJ :: 1006 - Hex-a-bonacci Solution



#include <cstdio>
#include <bits/stdc++.h>

using namespace std;
long long data[100005];
long long a, b, c, d, e, f;
long long fn( long long n )
{
if( n == 0 ) return a;
else
if( n == 1 ) return b;
else
if( n == 2 ) return c;
else
if( n == 3 ) return d;
else
if( n == 4 ) return e;
else
if( n == 5 ) return f;
else
if(data[n]!=-1) return data[n];
else
{

data[n] = ( fn(n-1) + fn(n-2) + fn(n-3) + fn(n-4) + fn(n-5) + fn(n-6) )%10000007;

return data[n];
}
}
int main()
{
long long n, caseno = 0, cases;
scanf("%lld", &cases);
while( cases-- )
{
memset(data,-1,sizeof(data));
scanf("%lld %lld %lld %lld %lld %lld %lld", &a, &b, &c, &d, &e, &f, &n);
printf("Case %lld: %lld\n", ++caseno, fn(n) % 10000007);
}
return 0;
}



Jan’s LightOJ :: 1000 - Greetings from LightOJ Solution



#include <stdio.h>

int main()
{
int n,i, a, b, sum;

scanf("%d",&n);
for (i = 0; i< n; i++)
{
scanf("%d %d",&a,&b);
sum = a + b;
printf("Case %d: %d\n",i+1,sum);

}



return 0;
}

Jan’s LightOJ :: 1069 - Lift Solution



#include <stdio.h>

int main()
{
int T;
scanf("%d",&T);

int i;
int a,b;
for(i =0; i<T;i++)
{
scanf("%d%d",&a,&b);
if(b==a)
printf("Case %d: %d\n",i+1,(19+b*4));
else if(a<b)
printf("Case %d: %d\n",i+1,(19+b*4));
else if(a>b)

printf("Case %d: %d\n",i+1,(19+a*4+(a-b)*4));



}

return 0;
}



Jan’s LightOJ :: 1107 - How Cow Solution



#include <stdio.h>

int main()
{
int T,M;
scanf("%d",&T);
int i,j;
for(i =0; i<T; i++)
{
int x1,x2,y1,y2,a,b;

printf("Case %d:\n",i+1);
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
scanf("%d",&M);
for(j=0; j<M; j++)
{
scanf("%d%d",&a,&b);

if((a>=x1&&a<=x2)&&(b>=y1&&b<=y2))
{
printf("Yes\n");
}
else
printf("No\n");


}
}
return 0;

}

Jan’s LightOJ :: 1297 - Largest Box Solution



#include <stdio.h>
#include <math.h>

int main()
{
int T,i;
double L,W,x;
scanf("%d",&T);
for(i =0; i<T; i++)
{
scanf("%lf%lf",&L,&W);
x = (W+L-sqrt(W*W+L*L-W*L))/6;
printf("Case %d: %lf\n",i+1,(W-2*x)*(L-2*x)*x);


}
return 0;


}

Jan’s LightOJ :: 1053 - Higher Math Solution



#include <stdio.h>
#include <math.h>
int main(){
int input,i=1;

unsigned a,o,h;
scanf("%d",&input);

while(input-->0)
{
scanf("%d%d%d",&a,&o,&h);
if(sqrt(a*a+o*o)==h)
{
printf("Case %d: yes\n",i++);
}
else if(sqrt(h*h+o*o)==a)
{
printf("Case %d: yes\n",i++);
}
else if(sqrt(a*a+h*h)==o)
{
printf("Case %d: yes\n",i++);
}
else
printf("Case %d: no\n",i++);



}

return 0;
}

Jan’s LightOJ :: 1116 - Ekka Dokka Solution



#include <stdio.h>
#include <math.h>

int main()
{
int T,x,i,j,m;
long int w;
scanf("%d",&T);
for(x =0; x<T; x++) {

scanf("%ld",&w);
if(w%2!=0)
printf("Case %d: Impossible\n",x+1);
else {
m = 1;
while(w%2==0) {
m*=2;
w/=2;

}
printf("Case %d: %ld %d\n",x+1,w,m);



}





}
return 0;
}

Jan’s LightOJ :: 1001 - Opposite Task Solution



#include <stdio.h>
int oneCount(int n)
{
int count = 0;
long long t = 1;
for(t = 1; t<=n; t*=2) {
if((n&(t))!=0) {
count++;
}

}
return count;


}
long long int next(long long int num)
{
long long res,t;
for(t = 1; t<=num; t*=2) {
if((num&(t))!=0) {
res = num+t;
break;

}

}
int diff = oneCount(num)-oneCount(res);
int i;
for(i = 0; i<diff; i++) {
res+=(1<<i);

}
return res;



}
int main()
{
int T,i,N,j;
scanf("%d",&T);
for(i =0; i<T; i++) {
scanf("%d",&N);
printf("Case %d: %lld\n",i+1,next(N));

}
return 0;



}

Jan’s LightOJ :: 1216 - Juice in the Glass Solution



#include <stdio.h>
#include <math.h>
#define PI acos(-1)
int main()
{
int T,i,r1,r2,h,p;
double R,R2,V;
scanf("%d",&T);

for(i =0; i<T; i++) {
scanf("%d%d%d%d",&r1,&r2,&h,&p);
R = r2+ (r1-r2)*((double)(p)/h);
V = ((PI*p)*(R*R+R*r2+r2*r2))/3.0;
printf("Case %d: %lf\n",i+1,V);


}
return 0;


}




Jan’s LightOJ :: 1305 - Area of a Parallelogram Solution



#include <stdio.h>
#include <math.h>
int main()
{
int i,T,Dx,Dy,Ax,Ay,Bx,By,Cx,Cy,height,base;
int area;

scanf("%d",&T);
for(i =0 ;i<T; i++)
{
scanf("%d%d%d%d%d%d",&Ax,&Ay,&Bx,&By,&Cx,&Cy);
Dx = Ax+Cx-Bx;
Dy = Ay-By+Cy;
height = Cy-By;
base = Bx-Ax;
area = ((Ax*By)+(Bx*Cy)+(Cx*Dy)+(Dx*Ay))-((Ay*Bx)+(By*Cx)+(Cy*Dx)+(Dy*Ax));


printf("Case %d: %d %d %d\n",i+1,Dx,Dy,abs(area/2));


}

return 0;


}

Jan’s LightOJ :: 1385 - Kingdom Division Solution



#include <stdio.h>
#include <math.h>
int main()
{
int T,i;
double a,b,c,result,div;
scanf("%d",&T);
for(i = 0; i<T; i++) {
scanf("%lf%lf%lf",&a,&b,&c);
div = ((b * b)-(a * c))/b;
if((b*b-a*c)/b<=0)
printf("Case %d: -1\n",i+1);
else {
result = (a*c)*(b+c+a+b)/div;
printf("Case %d: %.8lf\n",i+1,result/b);
}

}


return 0;
}




Jan’s LightOJ :: 1225 - Palindromic Numbers (II) Solution


#include

int main()
{
int T;
scanf("%d",&T);
int n;
int reverse=0;
int in;
int i;
for(i =0; i {
scanf("%d",&n);
in = n;
while(n!=0)
{
reverse = reverse*10;
reverse = reverse + n%10;

n = n/10;
}
if(in==0)
printf("Case %d: Yes\n",i+1);
else

if(in==reverse)
printf("Case %d: Yes\n",i+1);
else
printf("Case %d: No\n",i+1);

reverse = 0;


}
return 0;
}



Jan’s LightOJ :: 1433 - Minimum Arc Distance Solution



#include <stdio.h>
#include <math.h>
int main()
{
int i,T, Ox,Oy,Ax,Ay,Bx,By;
double angle,s,AB,OB,OA;
scanf("%d",&T);

for(i =0; i<T;i++)
{
scanf("%d%d%d%d%d%d",&Ox,&Oy,&Ax,&Ay,&Bx,&By);
AB = sqrt(pow(Ax-Bx,2)+pow(Ay-By,2));
OB = sqrt(pow(Ox-Bx,2)+pow(Oy-By,2));
OA= OB;
angle = acos((OB*OB + OA*OA-AB*AB)/(2*OB*OA));
s = OB*angle;
printf("Case %d: %f\n",i+1,s);



}
return 0;




}


Jan’s LightOJ :: 1294 - Positive Negative Sign Solution



#include <stdio.h>

int main()
{
int T,i;
long long n,m;
scanf("%d",&T);
for(i =0; i<T;i++)
{
scanf("%ld%ld",&n,&m);
printf("Case %d: %lld\n",i+1,(m*(n/2)));

}
return 0;

}

Jan’s LightOJ :: 1022 - Circle in Square Solution



#include <stdio.h>
#include <math.h>
int main()
{
int T,i;
double r;
scanf("%d",&T);
for(i =0; i<T; i++) {
scanf("%lf",&r);
printf("Case %d: %.2f\n",i+1,((2*r)*(2*r)-((2*acos(0.0))*r*r))+1e-9);
}
return 0;
}



Jan’s LightOJ :: 1331 - Agent J Solution



#include <stdio.h>
#include <math.h>
const double EPS = 1e-9;
int main()
{
int i,T;
scanf("%d",&T);
double r1,r2,r3,a,b,c,s,area,A,B,C,result;
for(i =0; i<T; i++) {
scanf("%lf%lf%lf",&r1,&r2,&r3);
a = r1+r2;
b = r2+r3;
c = r3 + r1;
s = (a+b+c)*0.5;
area = sqrt(s*(s-a)*(s-b)*(s-c));
A = acos((a*a+c*c-b*b)/(2.0*a*c));
B = acos((a*a+b*b-c*c)/(2.0*a*b));
C = acos((b*b+c*c-a*a)/(2.0*b*c));
result = area-A*r1*r1*0.5-B*r2*r2*0.5-C*r3*r3*0.5;
printf("Case %d: %.8lf\n",i+1,result+EPS);
}
return 0;

}


Jan’s LightOJ :: 1275 - Internet Service Providers Solution



#include <stdio.h>

int main()
{
long long N,C;
int T,i,ans;
scanf("%d",&T);
for(i =0; i<T; i++
) {
scanf("%lld%lld",&N,&C);
if(N==0)
ans = 0;
else
ans = C/(2*N);

int res1 = ans*C-ans*ans*N,res2=(ans+1)*C-(ans+1)*(ans+1)*N;
res1>=res2?1:(ans+=1);
if(N==0) ans = 0;
printf("Case %d: %d\n",i+1,ans);
}


return 0;
}



Jan’s LightOJ :: 1387 - Setu Solution



#include <stdio.h>

int main()
{
int i,j,y,input,sum=0,donation;
scanf("%d",&input);
char step[6];

for(i = 0; i<input; i++) {
scanf("%d",&j);

printf("Case %d:\n",i+1);
for(y = 0; y<j; y++) {
scanf("%s",step);
if(step[0]=='d') {
scanf("%d",&donation);
sum+=donation;

}
if(step[0]=='r')
printf("%d\n",sum);



}
sum = 0;

}
return 0;

}

Jan’s LightOJ :: 1020 - A Childhood Game Solution



#include <stdio.h>
int main()
{
int T,i,n;
char name[5];
scanf("%d",&T);

for(i =0; i<T; i++) {
scanf("%d%s",&n,name);
if(name[0]=='A') {
if(n%3==1)
printf("Case %d: Bob\n",i+1);
else
printf("Case %d: Alice\n",i+1);
}
else if(name[0]=='B') {
if(n%3==0)
printf("Case %d: Alice\n",i+1);
else
printf("Case %d: Bob\n",i+1);



}

}

return 0;
}




Jan’s LightOJ :: 1178 - Trapezium Solution


#include <stdio.h>
#include <math.h>
int main()
{
int T,i;
double a,b,c,d,s,h,w,area,result;
scanf("%d",&T);

for(i =0; i<T; i++) {
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
s = (d+b+a-c)/2;
area = sqrt(s*(s-d)*(s-b)*(s-a+c));
h = (2*area)/(fabs(a-c));
result = ((a+c)*h)/2;
printf("Case %d: %lf\n",i+1,result);



}

return 0;


}

Jan’s LightOJ :: 1043 - Triangle Partitioning Solution



#include <stdio.h>
#include <math.h>
int main()
{
int T;
scanf("%d",&T);
float AB,AC,BC,ratio;
int i;
for(i =0; i<T; i++)
{
scanf("%f%f%f%f",&AB,&AC,&BC,&ratio);
printf("Case %d: %f\n",i+1,(sqrt(ratio)/sqrt(ratio+1))*AB);



}

return 0;

}




Jan’s LightOJ :: 1015 – Brush(I) Solution

Solution:

#include <stdio.h>

int main()
{
int T,N;
scanf("%d\n",&T);

int i,j,dust;
unsigned long long int sum = 0;
for(i =0; i<T;i++)
{
scanf("%d",&N);
for(j=0;j<N;j++)
{
scanf("\n%d",&dust);
if(dust>0)
sum+=dust;


}
printf("Case %d: %lld\n",i+1,sum);
sum =0;



}

return 0;
}





Jan’s LightOJ :: 1182 – Parity Solution


#include <stdio.h>
int oneCount(int n)
{
int count = 0;
while(n>0)
{

if(n%2==1) count++;
n/=2;
}
return count;

}

int main()
{
int T;
unsigned long long int n;
scanf("%d",&T);
int i;
for(i =0; i<T;i++)
{
scanf("%lld",&n);
if(oneCount(n)%2==0)
printf("Case %d: even\n",i+1);
else
printf("Case %d: odd\n",i+1);

}
return 0;


}