#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;
}
Subscribe to:
Posts (Atom)