#include<stdio.h>
#include<math.h>
int main()
{
int test,ii,cnt1,cnt2,res,c;
char ara[100];
long long int n,result,i,j,h;
scanf("%d",&test);
for(ii=1;ii<=test;ii++)
{
scanf("%lld",&n);
result=0;
cnt1=0;
cnt2=0;
for(i=0;n>0;i++){
if(n%2==1){
ara[i]='1';
cnt1+=1;
}
else ara[i]='0';
n=n/2;
}
ara[i]='\0';
j=0;
for(j=0;;j++){
if(ara[j]=='1'){
while(ara[j]=='1'){
ara[j]='0';
j++;
}
ara[j]='1';
break;
}
}
if(i==j)ara[j+1]='\0';
else ara[i]='\0';
for(i=0;ara[i]!='\0';i++){
if(ara[i]=='1')cnt2++;
else
continue;
}
c=cnt1-cnt2;
for(h=0;h<c;h++){
ara[h]='1';
}
for(h=0;ara[h]!='\0';h++){
res = ara[h] - 48;
result = result + res * pow (2, h);
}
printf ("Case %d: %lld\n", ii, result);
}
return 0;
}
Sunday, 15 February 2015
Friday, 13 February 2015
light oj 1241
#include <stdio.h>
#include <math.h>
int main() {
int T,n,l,i,a[100],t=0,x;
int p;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
for(i=1; i<=n; i++) {
scanf("%d",&a[i]);
}
l=0;
p=2;
for(i=1;i<=n; i++) {
if(a[i]>p){
l+=ceil((a[i]-p)/5.0);
p=a[i];
}
}
printf("Case %d: %d\n",++t,l);
}
return 0;
}
#include <math.h>
int main() {
int T,n,l,i,a[100],t=0,x;
int p;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
for(i=1; i<=n; i++) {
scanf("%d",&a[i]);
}
l=0;
p=2;
for(i=1;i<=n; i++) {
if(a[i]>p){
l+=ceil((a[i]-p)/5.0);
p=a[i];
}
}
printf("Case %d: %d\n",++t,l);
}
return 0;
}
solution of light oj 1216
#include<stdio.h>
#include<math.h>
#define PI acos(-1)
int main()
{
int i,test;
int r1,r2,h,p;
double R,v;
scanf("%d",&test);
for(i=1;i<=test;i++)
{
scanf (" %d %d %d %d", &r1, &r2, &h, &p);
R= r2 +(r1-r2)*((double)p/h);
v = (1/3.0)*PI*( R*R+r2*r2+R*r2)*p;
printf("Case %d: %lf\n",i,v);
}
return 0;
}
#include<math.h>
#define PI acos(-1)
int main()
{
int i,test;
int r1,r2,h,p;
double R,v;
scanf("%d",&test);
for(i=1;i<=test;i++)
{
scanf (" %d %d %d %d", &r1, &r2, &h, &p);
R= r2 +(r1-r2)*((double)p/h);
v = (1/3.0)*PI*( R*R+r2*r2+R*r2)*p;
printf("Case %d: %lf\n",i,v);
}
return 0;
}
c solution for light oj problem no 1249
#include <stdio.h>
#include <string.h>
int main ()
{
int a, b, c, test, k, n,l, v, max, min, i;
char str[21], s1[21],s2[21];
scanf (" %d", &test);
for (k = 1; k <= test; k++) {
scanf("%d",&n);
scanf ("%s%d%d%d",str,&a,&b,&c);
max=min=a * b * c;
strcpy (s1,str);
strcpy (s2, str);
for (i = 1; i < n; i++) {
scanf ("%s%d%d%d",str,&a,&b,&c);
v = a * b * c;
if (v > max) {
strcpy (s1 , str);
max = v;
}
else if (v < min) {
strcpy (s2 , str);
min = v;
}
}
if (max == min) printf ("Case %d: no thief\n", k);
else printf ("Case %d: %s took chocolate from %s\n", k, s1, s2);
}
return 0;
}
#include <string.h>
int main ()
{
int a, b, c, test, k, n,l, v, max, min, i;
char str[21], s1[21],s2[21];
scanf (" %d", &test);
for (k = 1; k <= test; k++) {
scanf("%d",&n);
scanf ("%s%d%d%d",str,&a,&b,&c);
max=min=a * b * c;
strcpy (s1,str);
strcpy (s2, str);
for (i = 1; i < n; i++) {
scanf ("%s%d%d%d",str,&a,&b,&c);
v = a * b * c;
if (v > max) {
strcpy (s1 , str);
max = v;
}
else if (v < min) {
strcpy (s2 , str);
min = v;
}
}
if (max == min) printf ("Case %d: no thief\n", k);
else printf ("Case %d: %s took chocolate from %s\n", k, s1, s2);
}
return 0;
}
Wednesday, 11 February 2015
Solution Of Light oj 1331
#include <stdio.h>
#include <math.h>
int main() {
double r1,r2,r3,x,y,z,X,Y,Z,area,s,area1;
int test,i;
scanf("%d",&test);
for(i=1;i<=test;i++){
scanf("%lf%lf%lf",&r1,&r2,&r3);
x = r2 + r3;
y = r1 + r3;
z = r1 + r2;
X = acos((y*y+z*z-x*x)/(2*y*z));
Y = acos((z*z+x*x-y*y)/(2*x*z));
Z = acos((x*x+y*y-z*z)/(2*x*y));
s = (x+y+z)/2;
area = sqrt(s*(s-x)*(s-y)*(s-z));
area1 = area - (0.5)*(r1*r1*X+r2*r2*Y+r3*r3*Z);
printf("Case %d: %.08lf\n",i,area1);
}
return 0;
}
#include <math.h>
int main() {
double r1,r2,r3,x,y,z,X,Y,Z,area,s,area1;
int test,i;
scanf("%d",&test);
for(i=1;i<=test;i++){
scanf("%lf%lf%lf",&r1,&r2,&r3);
x = r2 + r3;
y = r1 + r3;
z = r1 + r2;
X = acos((y*y+z*z-x*x)/(2*y*z));
Y = acos((z*z+x*x-y*y)/(2*x*z));
Z = acos((x*x+y*y-z*z)/(2*x*y));
s = (x+y+z)/2;
area = sqrt(s*(s-x)*(s-y)*(s-z));
area1 = area - (0.5)*(r1*r1*X+r2*r2*Y+r3*r3*Z);
printf("Case %d: %.08lf\n",i,area1);
}
return 0;
}
Solution Of Light oj 1433
#include<stdio.h>
#include<math.h>
int main()
{
int test,i;
double Ox, Oy, Ax, Ay, Bx, By,A,B,C,c,arc;
scanf("%d",&test);
for(i=1;i<=test;i++){
scanf("%lf%lf%lf%lf%lf%lf",&Ox,&Oy, &Ax, &Ay, &Bx, &By);
A=sqrt(((Ox-Ax)*(Ox-Ax))+((Oy-Ay)*(Oy-Ay)));
C=sqrt(((Ax-Bx)*(Ax-Bx))+((Ay-By)*(Ay-By)));
c=acos((2*A*A-C*C)/(2*A*A));
arc=c*A;
printf("Case %d: %lf\n",i,arc);
}
}
#include<math.h>
int main()
{
int test,i;
double Ox, Oy, Ax, Ay, Bx, By,A,B,C,c,arc;
scanf("%d",&test);
for(i=1;i<=test;i++){
scanf("%lf%lf%lf%lf%lf%lf",&Ox,&Oy, &Ax, &Ay, &Bx, &By);
A=sqrt(((Ox-Ax)*(Ox-Ax))+((Oy-Ay)*(Oy-Ay)));
C=sqrt(((Ax-Bx)*(Ax-Bx))+((Ay-By)*(Ay-By)));
c=acos((2*A*A-C*C)/(2*A*A));
arc=c*A;
printf("Case %d: %lf\n",i,arc);
}
}
Solution Of Light oj 1387
#include<stdio.h>
int main()
{
int i,j,k,money,m,test,acc;
char ara[6]={0};
scanf("%d",&test);
for(m=1;m<=test;m++){
printf("Case %d:\n",m);
scanf("%d",&j);
k=0;
for(i=1;i<=j;i++){
scanf("%s",ara);
if(ara[0]=='d'){
scanf("%d",&acc);
k=k+acc;
}
else{
printf("%d\n",k);}
}
}
}
int main()
{
int i,j,k,money,m,test,acc;
char ara[6]={0};
scanf("%d",&test);
for(m=1;m<=test;m++){
printf("Case %d:\n",m);
scanf("%d",&j);
k=0;
for(i=1;i<=j;i++){
scanf("%s",ara);
if(ara[0]=='d'){
scanf("%d",&acc);
k=k+acc;
}
else{
printf("%d\n",k);}
}
}
}
Solution Of Light oj 1354
#include<stdio.h>
#include<math.h>
int binary(long bin)
{
int reminder,sum=0,h=0;
while(bin!=0){
reminder=bin%10;
bin/=10;
sum+=reminder*pow(2,h++);}
return sum;
}
int main()
{
int i,a[4],test,j,h,reminder,sum;
long b[4];
scanf("%d",&test);
for(i=1;i<=test;i++)
{
scanf("%d.%d.%d.%d",&a[0],&a[1],&a[2],&a[3]);
scanf("%ld.%ld.%ld.%ld",&b[0],&b[1],&b[2],&b[3]);
b[0]=binary(b[0]);
b[1]=binary(b[1]);
b[2]=binary(b[2]);
b[3]=binary(b[3]);
if(a[0]==b[0]&&a[1]==b[1]&&a[2]==b[2]&&a[3]==b[3]){
printf("Case %d: Yes\n",i);}
else{
printf("Case %d: No\n",i);}
}
return 0;
}
#include<math.h>
int binary(long bin)
{
int reminder,sum=0,h=0;
while(bin!=0){
reminder=bin%10;
bin/=10;
sum+=reminder*pow(2,h++);}
return sum;
}
int main()
{
int i,a[4],test,j,h,reminder,sum;
long b[4];
scanf("%d",&test);
for(i=1;i<=test;i++)
{
scanf("%d.%d.%d.%d",&a[0],&a[1],&a[2],&a[3]);
scanf("%ld.%ld.%ld.%ld",&b[0],&b[1],&b[2],&b[3]);
b[0]=binary(b[0]);
b[1]=binary(b[1]);
b[2]=binary(b[2]);
b[3]=binary(b[3]);
if(a[0]==b[0]&&a[1]==b[1]&&a[2]==b[2]&&a[3]==b[3]){
printf("Case %d: Yes\n",i);}
else{
printf("Case %d: No\n",i);}
}
return 0;
}
Solution Of Light oj 1338
#include <stdio.h>
#include <string.h>
int main()
{
int test,i,len1,len2,j,k,x,y,len3,len4;
char a1[10000],a2[10000],a3[10000],a4[10000],temp;
scanf("%d",&test);
getchar();
for(k=1;k<=test;k++){
gets(a1);
gets(a2);
len1=strlen(a1);
len2=strlen(a2);
x=0;y=0;
for(i=0;i<len1;i++){
if(a1[i]>='a'&&a1[i]<='z'){
a1[i]='A'+(a1[i]-'a');
}
}
for(i=0;i<len1;i++){
if(a1[i]!=' '){
a3[x]=a1[i];
x++;
}
}
a3[x]='\0';
for(i=0;i<len2;i++){
if(a2[i]>='a'&&a2[i]<='z'){
a2[i]='A'+(a2[i]-'a');
}
}
for(i=0;i<len2;i++){
if(a2[i]!=' '){
a4[y]=a2[i];
y++;
}
}
a4[y]='\0';
len3=strlen(a3);
len4=strlen(a4);
for(i=0;i<len3-1;i++){
for(j=0;j<len3-1;j++){
if(a3[j]>a3[j+1]){
temp=a3[j];
a3[j]=a3[j+1];
a3[j+1]=temp;
}
}
}
for(i=0;i<len4-1;i++){
for(j=0;j<len4-1;j++){
if(a4[j]>a4[j+1]){
temp=a4[j];
a4[j]=a4[j+1];
a4[j+1]=temp;
}
}
}
if(strcmp(a3,a4)==0)
printf("Case %d: Yes\n",k);
else
printf("Case %d: No\n",k);
}
return 0;
}
#include <string.h>
int main()
{
int test,i,len1,len2,j,k,x,y,len3,len4;
char a1[10000],a2[10000],a3[10000],a4[10000],temp;
scanf("%d",&test);
getchar();
for(k=1;k<=test;k++){
gets(a1);
gets(a2);
len1=strlen(a1);
len2=strlen(a2);
x=0;y=0;
for(i=0;i<len1;i++){
if(a1[i]>='a'&&a1[i]<='z'){
a1[i]='A'+(a1[i]-'a');
}
}
for(i=0;i<len1;i++){
if(a1[i]!=' '){
a3[x]=a1[i];
x++;
}
}
a3[x]='\0';
for(i=0;i<len2;i++){
if(a2[i]>='a'&&a2[i]<='z'){
a2[i]='A'+(a2[i]-'a');
}
}
for(i=0;i<len2;i++){
if(a2[i]!=' '){
a4[y]=a2[i];
y++;
}
}
a4[y]='\0';
len3=strlen(a3);
len4=strlen(a4);
for(i=0;i<len3-1;i++){
for(j=0;j<len3-1;j++){
if(a3[j]>a3[j+1]){
temp=a3[j];
a3[j]=a3[j+1];
a3[j+1]=temp;
}
}
}
for(i=0;i<len4-1;i++){
for(j=0;j<len4-1;j++){
if(a4[j]>a4[j+1]){
temp=a4[j];
a4[j]=a4[j+1];
a4[j+1]=temp;
}
}
}
if(strcmp(a3,a4)==0)
printf("Case %d: Yes\n",k);
else
printf("Case %d: No\n",k);
}
return 0;
}
Solution Of Light oj 1311
#include <stdio.h>
int main()
{
int test,i;
double time1,time2,d1,d2,t;
scanf("%d",&test);
for(i=1;i<=test;i++)
{
double v1,v2,v3,a1,a2;
scanf("%lf%lf%lf%lf%lf",&v1,&v2,&v3,&a1,&a2);
d1=v1*v1/2/a1+v2*v2/2/a2;
time1=v1/a1;
time2=v2/a2;
if(time1>time2)t=time1;
else{
t=time2;
}
d2=t*v3;
printf("Case %d: %lf %lf\n",i,d1,d2);
}
return 0;
}
int main()
{
int test,i;
double time1,time2,d1,d2,t;
scanf("%d",&test);
for(i=1;i<=test;i++)
{
double v1,v2,v3,a1,a2;
scanf("%lf%lf%lf%lf%lf",&v1,&v2,&v3,&a1,&a2);
d1=v1*v1/2/a1+v2*v2/2/a2;
time1=v1/a1;
time2=v2/a2;
if(time1>time2)t=time1;
else{
t=time2;
}
d2=t*v3;
printf("Case %d: %lf %lf\n",i,d1,d2);
}
return 0;
}
Solution Of Light oj 1305
#include<stdio.h>
#include<stdlib.h>
int main()
{
int Ax,Ay,Bx,By,Cx,Cy,Dx,Dy,j=0,TEST,area;
scanf("%d",&TEST);
while(TEST--){
scanf("%d%d%d%d%d%d",&Ax,&Ay,&Bx,&By,&Cx,&Cy);
Dx=(Ax+Cx)-Bx;
Dy=(Ay+Cy)-By;
area=((Ax*By)+(Bx*Cy)+(Cx*Dy)+(Dx*Ay))-((Ay*Bx)+(By*Cx)+(Cy*Dx)+(Dy*Ax));
area=0.5*area;
printf("Case %d: %d %d %d\n",++j,Dx,Dy,abs(area));
}
return 0;
}
#include<stdlib.h>
int main()
{
int Ax,Ay,Bx,By,Cx,Cy,Dx,Dy,j=0,TEST,area;
scanf("%d",&TEST);
while(TEST--){
scanf("%d%d%d%d%d%d",&Ax,&Ay,&Bx,&By,&Cx,&Cy);
Dx=(Ax+Cx)-Bx;
Dy=(Ay+Cy)-By;
area=((Ax*By)+(Bx*Cy)+(Cx*Dy)+(Dx*Ay))-((Ay*Bx)+(By*Cx)+(Cy*Dx)+(Dy*Ax));
area=0.5*area;
printf("Case %d: %d %d %d\n",++j,Dx,Dy,abs(area));
}
return 0;
}
Solution Of Light oj 1294
#include <stdio.h>
int main()
{
long long n,m;
int test,i;
scanf("%d",&test);
for(i=1;i<=test;i++)
{
scanf("%lld%lld",&n,&m);
printf("Case %d: ",i);
printf("%lld\n",n/2*m);
}
return 0;
}
int main()
{
long long n,m;
int test,i;
scanf("%d",&test);
for(i=1;i<=test;i++)
{
scanf("%lld%lld",&n,&m);
printf("Case %d: ",i);
printf("%lld\n",n/2*m);
}
return 0;
}
Solution Of Light oj 1227
#include<stdio.h>
int main()
{
int test,i,j,k,l,n,p,q,res,n1;
int ara[1000],num;
scanf("%d",&test);
for(i=1;i<=test;i++)
{
num=0;
scanf("%d%d%d",&n,&p,&q);
for(j=0;j<n;j++)
{
scanf("%d",&ara[j]);
}
for(l=0;l<n;l++)
{
num=num+ara[l];
if(l>=p||num>q)break;
}
printf("Case %d: %d\n",i,l);
}
}
int main()
{
int test,i,j,k,l,n,p,q,res,n1;
int ara[1000],num;
scanf("%d",&test);
for(i=1;i<=test;i++)
{
num=0;
scanf("%d%d%d",&n,&p,&q);
for(j=0;j<n;j++)
{
scanf("%d",&ara[j]);
}
for(l=0;l<n;l++)
{
num=num+ara[l];
if(l>=p||num>q)break;
}
printf("Case %d: %d\n",i,l);
}
}
Solution Of Light oj 1225
#include <stdio.h>
#include <string.h>
char s[20];
char str[20];
int main()
{
int t,j,k,i,temp;
scanf("%d",&t);
for(k=1;k<=t;k++)
{
scanf("%s",s);
printf("Case %d: ",k);
strcpy(str,s);
j=strlen(str);
for(i=0;i<j/2;i++){
temp = str[i];
str[i] = str[j-1-i];
str[j-1-i] = temp;}
if(strcmp(s,str)==0)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
#include <string.h>
char s[20];
char str[20];
int main()
{
int t,j,k,i,temp;
scanf("%d",&t);
for(k=1;k<=t;k++)
{
scanf("%s",s);
printf("Case %d: ",k);
strcpy(str,s);
j=strlen(str);
for(i=0;i<j/2;i++){
temp = str[i];
str[i] = str[j-1-i];
str[j-1-i] = temp;}
if(strcmp(s,str)==0)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
Solution Of Light oj 1214
#include<stdio.h>
#include<string.h>
int main()
{
long long int b, i, t, test, remin, n, len, x, start;
char str[200];
scanf("%d",&test);
getchar();
for(t=1; t<=test; t++)
{
memset(str,'\0',sizeof(str));
start=0;
scanf("%s",str);
scanf("%lld",&b);
if(b<0)
b=b*(-1);
if(str[0]=='-')
start=1;
len=strlen(str);
x=0;
n=0;
for(i=start; str[i]!='\0'; i++)
{
x=(str[i]-'0')+x;
remin=x%b;
x=remin*10;
if(remin==0&&i==(len-1))
{
n++;
printf("Case %lld: divisible\n",t);
}
}
if(n==0)
{
printf("Case %lld: not divisible\n",t);
}
}
return 0;
}
#include<string.h>
int main()
{
long long int b, i, t, test, remin, n, len, x, start;
char str[200];
scanf("%d",&test);
getchar();
for(t=1; t<=test; t++)
{
memset(str,'\0',sizeof(str));
start=0;
scanf("%s",str);
scanf("%lld",&b);
if(b<0)
b=b*(-1);
if(str[0]=='-')
start=1;
len=strlen(str);
x=0;
n=0;
for(i=start; str[i]!='\0'; i++)
{
x=(str[i]-'0')+x;
remin=x%b;
x=remin*10;
if(remin==0&&i==(len-1))
{
n++;
printf("Case %lld: divisible\n",t);
}
}
if(n==0)
{
printf("Case %lld: not divisible\n",t);
}
}
return 0;
}
Solution Of Light oj 1211
#include<stdio.h>
int main()
{
int i,j,x,test,a,n,s[7],res;
s[1]=s[2]=s[3]=1;
s[4]=s[5]=s[6]=1000;
scanf("%d",&test);
for(i=1;i<=test;i++)
{
scanf("%d",&a);
s[1]=s[2]=s[3]=1;
s[4]=s[5]=s[6]=1000;
for(x=1;x<=a;x++)
{
for(j=1;j<=3;j++)
{
scanf("%d",&n);
if(n>s[j]){
s[j]=n;}
}
for(j=4;j<=6;j++)
{
scanf("%d",&n);
if(n<s[j]){
s[j]=n;}
}
}
if(s[4]>s[1]&&s[5]>s[2]&&s[6]>s[3])
{
res=(s[4]-s[1])*(s[5]-s[2])*(s[6]-s[3]);
printf("Case %d: %d\n",i,res);}
else printf("Case %d: 0\n",i);
}
return 0;
}
Solution Of Light oj 1202
#include <stdio.h>
#include <math.h>
int main()
{
int test,i,x1,y1,x2,y2;
scanf("%d",&test);
for(i=1;i<=test;i++)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
printf("Case %d: ",i);
x1=abs(x1-x2);
y1=abs(y1-y2);
if(x1==y1)
printf("1\n");
else
{
if(x1%2==y1%2)
printf("2\n");
else
printf("impossible\n");
}
}
return 0;
}
#include <math.h>
int main()
{
int test,i,x1,y1,x2,y2;
scanf("%d",&test);
for(i=1;i<=test;i++)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
printf("Case %d: ",i);
x1=abs(x1-x2);
y1=abs(y1-y2);
if(x1==y1)
printf("1\n");
else
{
if(x1%2==y1%2)
printf("2\n");
else
printf("impossible\n");
}
}
return 0;
}
Solution Of Light Online Judge 1182
#include<stdio.h>
int main()
{
int t,i,s=0;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
int n;
scanf("%d",&n);
printf("Case %d: ",i);
s=0;
while(n>0){
if(n%2!=0){
s++;
n=n/2;
}
else{
n=n/2;
}
}
if(s%2!=0){
printf("odd\n");}
else{
printf("even\n");}
}
return 0;
}
int main()
{
int t,i,s=0;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
int n;
scanf("%d",&n);
printf("Case %d: ",i);
s=0;
while(n>0){
if(n%2!=0){
s++;
n=n/2;
}
else{
n=n/2;
}
}
if(s%2!=0){
printf("odd\n");}
else{
printf("even\n");}
}
return 0;
}
Solution Of Light Online Judge 1136
#include<stdio.h>
int main()
{
long long int a,b,i,temp,test,z,x,res;
scanf("%lld",&test);
for(i=1;i<=test;i++){
scanf("%lld %lld",&a,&b);
if(a>b){
temp=a;
a=b;
b=temp;
}
if(a%3==0)
z=(a/3)*2;
else{
z=((a/3)*2)+1;
}
b=b+1;
if(b%3==0)
x=(b/3)*2;
else{
x=((b/3)*2)+1;
}
res=x-z;
printf("Case %lld: %lld\n",i,res);
}
}
int main()
{
long long int a,b,i,temp,test,z,x,res;
scanf("%lld",&test);
for(i=1;i<=test;i++){
scanf("%lld %lld",&a,&b);
if(a>b){
temp=a;
a=b;
b=temp;
}
if(a%3==0)
z=(a/3)*2;
else{
z=((a/3)*2)+1;
}
b=b+1;
if(b%3==0)
x=(b/3)*2;
else{
x=((b/3)*2)+1;
}
res=x-z;
printf("Case %lld: %lld\n",i,res);
}
}
Tuesday, 10 February 2015
Solution Of Light Online Judge 1133
#include <stdio.h>
int main()
{
int test,a[110],n,m,j,add,x,temp,q,w,temp1,i,c;
char ch[0];
scanf(" %d",&test);
for(j=1;j<=test;j++)
{
scanf(" %d%d",&n,&m);
for(i=0;i<n;i++)
scanf(" %d",&a[i]);
for(c=0;c<m;c++)
{
scanf(" %c",&ch);
if(ch[0]=='S')
{
scanf(" %d",&add);
for(i=0;i<n;i++){
a[i]=add+a[i];}
}
else if(ch[0]=='M')
{
scanf(" %d",&add);
for(i=0;i<n;i++){
a[i]=add*a[i];}
}
else if(ch[0]=='P')
{
scanf(" %d%d",&q,&w);
temp1=a[q];
a[q]=a[w];
a[w]=temp1;
}
else if(ch[0]=='R')
{
for(i=0;i<=(n-1)/2;i++)
{
temp=a[i];
a[i]=a[n-i-1];
a[n-i-1]=temp;}
}
else
{
scanf(" %d",&add);
for(i=0;i<n;i++)
a[i]/=add;
}
}
printf("Case %d:\n",j);
for(i=0; i<n; i++)
printf("%d%c", a[i],i==n-1?'\n':' ');
}
return 0;
}
int main()
{
int test,a[110],n,m,j,add,x,temp,q,w,temp1,i,c;
char ch[0];
scanf(" %d",&test);
for(j=1;j<=test;j++)
{
scanf(" %d%d",&n,&m);
for(i=0;i<n;i++)
scanf(" %d",&a[i]);
for(c=0;c<m;c++)
{
scanf(" %c",&ch);
if(ch[0]=='S')
{
scanf(" %d",&add);
for(i=0;i<n;i++){
a[i]=add+a[i];}
}
else if(ch[0]=='M')
{
scanf(" %d",&add);
for(i=0;i<n;i++){
a[i]=add*a[i];}
}
else if(ch[0]=='P')
{
scanf(" %d%d",&q,&w);
temp1=a[q];
a[q]=a[w];
a[w]=temp1;
}
else if(ch[0]=='R')
{
for(i=0;i<=(n-1)/2;i++)
{
temp=a[i];
a[i]=a[n-i-1];
a[n-i-1]=temp;}
}
else
{
scanf(" %d",&add);
for(i=0;i<n;i++)
a[i]/=add;
}
}
printf("Case %d:\n",j);
for(i=0; i<n; i++)
printf("%d%c", a[i],i==n-1?'\n':' ');
}
return 0;
}
Solution Of Light Online Judge 1116
#include<stdio.h>
int main()
{
long long int a,i,test,even,odd;
scanf("%lld",&test);
for(i=1;i<=test;i++){
scanf("%lld",&a);
even=1;
while(a){
if(!(a&1)){
even=even<<1;
a=a>>1;
if(a&1){
printf("Case %lld: %lld %lld\n",i,a,even);
break;
}
}
else{
printf("Case %lld: Impossible\n",i);
break;
}
}
}
}
int main()
{
long long int a,i,test,even,odd;
scanf("%lld",&test);
for(i=1;i<=test;i++){
scanf("%lld",&a);
even=1;
while(a){
if(!(a&1)){
even=even<<1;
a=a>>1;
if(a&1){
printf("Case %lld: %lld %lld\n",i,a,even);
break;
}
}
else{
printf("Case %lld: Impossible\n",i);
break;
}
}
}
}
Solution Of Light Online Judge 1107
#include<stdio.h>
int main()
{
int x1,x2,y1,y2,x,y,c,i,n,m;
scanf("%d",&c);
for(i=0;i<c;i++){
printf("Case %d:\n",i+1);
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
scanf("%d",&n);
for(m=0;m<n;m++){
scanf("%d %d",&x,&y);
if(x==0||y==0){
printf("No\n");
}
else if((x1<x)&&(x<x2)&&(y1<y)&&(y<y2)){
printf("Yes\n");
}
else{
printf("No\n");}
}
}
}
int main()
{
int x1,x2,y1,y2,x,y,c,i,n,m;
scanf("%d",&c);
for(i=0;i<c;i++){
printf("Case %d:\n",i+1);
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
scanf("%d",&n);
for(m=0;m<n;m++){
scanf("%d %d",&x,&y);
if(x==0||y==0){
printf("No\n");
}
else if((x1<x)&&(x<x2)&&(y1<y)&&(y<y2)){
printf("Yes\n");
}
else{
printf("No\n");}
}
}
}
Solution Of Light Online Judge 1072
#include<stdio.h>
#include<math.h>
#define PI 3.14159265
int main()
{
double R,r,g;
int i,j,n;
scanf("%d",&j);
for(i=0;i<j;i++){
scanf("%lf",&R);
scanf("%d",&n);
r=((sin(PI/n)*R)/(sin(PI/n)+1));
printf("Case %d: %.10lf\n",i+1,r);
}
}
#include<math.h>
#define PI 3.14159265
int main()
{
double R,r,g;
int i,j,n;
scanf("%d",&j);
for(i=0;i<j;i++){
scanf("%lf",&R);
scanf("%d",&n);
r=((sin(PI/n)*R)/(sin(PI/n)+1));
printf("Case %d: %.10lf\n",i+1,r);
}
}
Solution Of Light Online Judge 1069
#include<stdio.h>
int main()
{
int me,lift,i,j,k,pos,u;
scanf("%d",&k);
for(i=1;i<=k;i++){
scanf("%d%d",&me,&lift);
if(me>lift){
u=((me-lift)*2)+lift;
pos=(u*4)+19;
}
else{
pos=(lift*4)+19;
}
printf("Case %d: %d\n",i,pos);
}
}
int main()
{
int me,lift,i,j,k,pos,u;
scanf("%d",&k);
for(i=1;i<=k;i++){
scanf("%d%d",&me,&lift);
if(me>lift){
u=((me-lift)*2)+lift;
pos=(u*4)+19;
}
else{
pos=(lift*4)+19;
}
printf("Case %d: %d\n",i,pos);
}
}
Solution Of Light Online Judge 1053
#include<stdio.h>
int main()
{
long a,b,c,i,j,sum,temp,t,v;
scanf("%d",&j);
for(i=1;i<=j;i++){
scanf("%ld%ld%ld",&a,&b,&c);
if(a>=b && a>=c){
temp=a;
a=c;
c=temp;}
else if(b>=a && b>=c){
temp=b;
b=c;
c=temp;}
else if(c>=a && c>=b){
temp=c;
c=temp;}
t=(a*a)+(b*b);
v=(c*c);
if(t==v){
printf("Case %d: yes\n",i);
}
else{
printf("Case %d: no\n",i);
}
}
}
int main()
{
long a,b,c,i,j,sum,temp,t,v;
scanf("%d",&j);
for(i=1;i<=j;i++){
scanf("%ld%ld%ld",&a,&b,&c);
if(a>=b && a>=c){
temp=a;
a=c;
c=temp;}
else if(b>=a && b>=c){
temp=b;
b=c;
c=temp;}
else if(c>=a && c>=b){
temp=c;
c=temp;}
t=(a*a)+(b*b);
v=(c*c);
if(t==v){
printf("Case %d: yes\n",i);
}
else{
printf("Case %d: no\n",i);
}
}
}
C Solution Of Light Online Judge 1045
#include <stdio.h>
#include <math.h>
double num[1000001];
int main() {
int test,i, n, b;
for(n = 1; n < 1000001; n++){
num[n] = log(n) + num[n-1];}
scanf("%d", &test);
for(i= 1; i <= test; i++) {
scanf("%d %d", &n, &b);
printf("Case %d: %.0lf\n",i, floor(num[n]/log(b)) + 1.0);
}
return 0;
}
#include <math.h>
double num[1000001];
int main() {
int test,i, n, b;
for(n = 1; n < 1000001; n++){
num[n] = log(n) + num[n-1];}
scanf("%d", &test);
for(i= 1; i <= test; i++) {
scanf("%d %d", &n, &b);
printf("Case %d: %.0lf\n",i, floor(num[n]/log(b)) + 1.0);
}
return 0;
}
C Solution Of Light Online Judge 1022
#include<stdio.h>
#include<math.h>
int main()
{
long i,j,power;
double pi=3.1415926535897932384626;
double r,n,h,k,l;
scanf("%d",&j);
for(i=0;i<j;i++){
scanf("%lf",&r);
n=2*r;
h=pow(n,2);
k=h-(pi*(r*r));
l=(k+10e-9);
printf("Case %d: %.2lf\n",i+1,l);
}
}
#include<math.h>
int main()
{
long i,j,power;
double pi=3.1415926535897932384626;
double r,n,h,k,l;
scanf("%d",&j);
for(i=0;i<j;i++){
scanf("%lf",&r);
n=2*r;
h=pow(n,2);
k=h-(pi*(r*r));
l=(k+10e-9);
printf("Case %d: %.2lf\n",i+1,l);
}
}
C Solution Of Light Online Judge 1015
#include<stdio.h>
int main()
{
int n,i,sum=0,h,d,k;
scanf("%d",&k);
for(d=0;d<k;d++){
scanf("%d",&n);
sum=0;
for(i=0;i<n;i++){
scanf("%d",&h);
if(h<0)
h=0;
sum=sum+h;
}
printf("Case %d: %d\n",d+1,sum);
}
}
int main()
{
int n,i,sum=0,h,d,k;
scanf("%d",&k);
for(d=0;d<k;d++){
scanf("%d",&n);
sum=0;
for(i=0;i<n;i++){
scanf("%d",&h);
if(h<0)
h=0;
sum=sum+h;
}
printf("Case %d: %d\n",d+1,sum);
}
}
C Solution Of Light Online Judge 1010
#include<stdio.h>
#define pi 3.1415926535897932
int main()
{
int m,n,c,x,p,q,s,z;
scanf("%d",&s);
for(q=1;q<=s;q++){
scanf("%d %d",&m,&n);
if(m>n){
p=m;
m=n;
n=p;
}
if(m==1 || n==1){
x=m*n;}
else if(m==2||n==2){
z=0;
if(m==n){
x=m*n;
}
else if(n%2==1){
x=n+1;
}
else if(n%2==0){
z=n/2;
if(z%2==0){
x=((m*n)/2);
}
else{
x=m+n;
}
}
}
else {
x=(((m*n)+1)/2);
}
printf("Case %d: %d\n",q, x);}
}
#define pi 3.1415926535897932
int main()
{
int m,n,c,x,p,q,s,z;
scanf("%d",&s);
for(q=1;q<=s;q++){
scanf("%d %d",&m,&n);
if(m>n){
p=m;
m=n;
n=p;
}
if(m==1 || n==1){
x=m*n;}
else if(m==2||n==2){
z=0;
if(m==n){
x=m*n;
}
else if(n%2==1){
x=n+1;
}
else if(n%2==0){
z=n/2;
if(z%2==0){
x=((m*n)/2);
}
else{
x=m+n;
}
}
}
else {
x=(((m*n)+1)/2);
}
printf("Case %d: %d\n",q, x);}
}
C Solution Of Light Online Judge 1008
#include<stdio.h>
#include<math.h>
int main()
{
int t,j,i,te;
long long n,s,x,y;
scanf("%d",&i);
for(j=1;j<=i;j++){
scanf("%lld",&s);
n=ceil(sqrt ((double)(s)));
if(n*n-s<n)x=n,y=n*n-s+1;
else x=-n*n+2*n+s-1,y=n;
if(n&1)
{
te=x;
x=y;
y=te;
}
printf("Case %d: %lld %lld\n",j,x,y);
}
return 0;
}
#include<math.h>
int main()
{
int t,j,i,te;
long long n,s,x,y;
scanf("%d",&i);
for(j=1;j<=i;j++){
scanf("%lld",&s);
n=ceil(sqrt ((double)(s)));
if(n*n-s<n)x=n,y=n*n-s+1;
else x=-n*n+2*n+s-1,y=n;
if(n&1)
{
te=x;
x=y;
y=te;
}
printf("Case %d: %lld %lld\n",j,x,y);
}
return 0;
}
Light OJ 1001 no problem c solution
#include<stdio.h>
#include<stdlib.h>
int main()
{
int b,i,a,j,u;
int ara[50]={0};
scanf("%d",&a);
for(i=0;i<a;i++){
scanf("%d",&b);
if(b==0)
{
printf("0 0\n");
}
else if(b==20){
printf("10 10\n");
}
else if(b<11){
printf("%d %d\n",ara[b],abs(b-ara[b]));
ara[b]++;
}
else{
u=10-ara[b];
printf("%d %d\n",u,abs(b-u));
ara[b]++;
}
}
}
#include<stdlib.h>
int main()
{
int b,i,a,j,u;
int ara[50]={0};
scanf("%d",&a);
for(i=0;i<a;i++){
scanf("%d",&b);
if(b==0)
{
printf("0 0\n");
}
else if(b==20){
printf("10 10\n");
}
else if(b<11){
printf("%d %d\n",ara[b],abs(b-ara[b]));
ara[b]++;
}
else{
u=10-ara[b];
printf("%d %d\n",u,abs(b-u));
ara[b]++;
}
}
}
Light OJ 1000 no problem c solution
#include<stdio.h>
int main()
{
int i,j,sum=0,a,k,l,h;
scanf("%d",&a);
for(i=1;i<=a;i++){
scanf("%d%d",&k,&l);
sum=k+l;
printf("Case %d: %d\n",i,sum);
}
return 0;
}
int main()
{
int i,j,sum=0,a,k,l,h;
scanf("%d",&a);
for(i=1;i<=a;i++){
scanf("%d%d",&k,&l);
sum=k+l;
printf("Case %d: %d\n",i,sum);
}
return 0;
}
Subscribe to:
Posts (Atom)