# UVa 136 – Ugly Numbers

0
```
/*
User ID: turing_13
*/

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

int main()
{
double a,b,c,k,ara[2000];
int count=0;
for(a=0; a<31; a++)
for(b=0; b<31; b++)
for(c=0; c<31; c++)
{
k=pow(2,c)*pow(3,b)*pow(5,a);
if(k>1000000000)
{
k=0;
break;
}
else
{
ara[count]=k;
count++;
}
}
sort(ara,ara+count);
printf("The 1500'th ugly number is %.lf.\n",ara[1499]);
return 0;
}

```

# UVa 113 – Power of Cryptography

0
```
/*
User ID: turing_13
*/

#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
double n,p;
while(scanf("%lf %lf", &n,&p)==2)
{
printf("%.lf\n", pow(p,1/n));
}
return 0;
}

```

# UVa 111 – History Grading

0
```
/*
User ID: turing_13
*/

#include<bits/stdc++.h>

#define pii pair <int,int>
#define sc scanf
#define pf printf
#define Pi 2*acos(0.0)
#define ms(a,b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define oo 1<<29
#define dd double
#define ll long long
#define EPS 10E-10
#define ff first
#define ss second
#define MAX 10000
#define SZ(a) (int)a.size()
#define getint(a) scanf("%d",&a)
#define loop(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define intlim 2147483648
#define inf 1000000
#define rtintlim 46340
#define llim 9223372036854775808
#define rtllim 3037000499
#define ull unsigned long long

using namespace std;

int data[30];
int input[30];
int n;
int dp[30];

int func(int u)
{
int &rfr=dp[u];
if(rfr!=-1) return rfr;
rfr=1;
for(int i=u+1;i<=n;i++)
{
if(data[input[u]]<data[input[i]])
rfr=max(rfr,func(i)+1);
}
return rfr;
}

int main()
{
///freopen("in.txt","r",stdin);
///freopen("out.txt","w",stdout);

cin>>n;
for(int i=1;i<=n;i++)
{
int inp;
cin>>inp;
data[i]=inp;
}
int tmp;
while(cin>>tmp)
{
input[tmp]=1;
for(int i=2;i<=n;i++)
{
cin>>tmp;
input[tmp]=i;
}
ms(dp,-1);
int ans=0;

for(int i=1;i<=n;i++)
ans=max(ans,func(i));
cout<<ans<<endl;
}
return 0;
}

```

# UVa 102 – Ecological Bin Packing

0
```
/*
User ID: turing_13
*/

#include <bits/stdc++.h>

#define ll long long
#define sc scanf
#define pf printf
#define Pi 2*acos(0.0)

using namespace std;

int main()
{
///freopen("input.txt","r",stdin);
///freopen("output.txt","w",stdout);
long long a1,a2,a3,b1,b2,b3,c1,c2,c3,ans,i,j,k,l;
while(cin>>a1>>b1>>c1>>a2>>b2>>c2>>a3>>b3>>c3)
{
j=(a2+a3+c1+c3+b1+b2);
k=j;
l=1;
j=(a2+a3+b1+b3+c1+c2);
if(j<k)
{
k=j;
l=2;
}
j=(c2+c3+a1+a3+b1+b2);
if(j<k)
{
k=j;
l=3;
}
j=(c2+c3+b1+b3+a1+a2);
if(j<k)
{
k=j;
l=4;
}
j=(b2+b3+a1+a3+c1+c2);
if(j<k)
{
k=j;
l=5;
}
j=(b2+b3+c1+c3+a1+a2);
if(j<k)
{
k=j;
l=6;
}
if(l==1)
cout<<"BCG "<<k<<endl;
else if(l==2)
cout<<"BGC "<<k<<endl;
else if(l==3)
cout<<"CBG "<<k<<endl;
else if(l==4)
cout<<"CGB "<<k<<endl;
else if(l==5)
cout<<"GBC "<<k<<endl;
else if(l==6)
cout<<"GCB "<<k<<endl;
}
return 0;
}

```

# UVA 100 – The 3n + 1 problem

0
```
/*
User ID: turing_13
*/

#include<stdio.h>

main()
{
unsigned long int a,b,c,d,e,f,n,max;
while(scanf(" %lu %lu", &a, &b) !=EOF)
{
if(a<b)
{
c=a;
d=b;
}
else
{
c=b;
d=a;
}
for(max=0; c<=d; c++)
{
n=c;
e=1;
while(n!=1)
{
if(n%2 !=0)
n=3*n+1;
else
n/=2;
e++;
}
if(e>max)
max=e;
}
printf("%lu %lu %lu\n", a,b,max);
}
return 0;
}

```

# UVa 591 – Box of Bricks

0
```
/*
User ID: turing_13
*/

#include <iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<cstdlib>

using namespace std;

int main()
{
int n,ara[55]= {0},i,avg,ans,b=0;
while(scanf("%d",&n)==1 & n!=0)
{
b++;
avg=ans=0;
for(i=0; i<n; i++)
{
scanf("%d",&ara[i]);
avg+=ara[i];
}
avg/=n;
for(i=0; i<n; i++)
{
if(ara[i]>avg)
ans+=(ara[i]-avg);
}
printf("Set #%d\n",b);
printf("The minimum number of moves is %d.\n\n",ans);
}
return 0;
}

```

# Light OJ 1249 – Chocolate Thief

0
```
/*
*/

#include <bits/stdc++.h>

#define pii pair <int,int>
#define sc scanf
#define pf printf
#define Pi 2*acos(0.0)
#define ms(a,b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define oo 1<<29
#define dd double
#define ll long long
#define EPS 10E-10
#define ff first
#define ss second
#define MAX 10000
#define SZ(a) (int)a.size()
#define getint(a) scanf("%d",&a)
#define loop(i,n) for(int i=0;i<n;i++)
#define TEST_CASE(t) for(int z=1;z<=t;z++)
#define PRINT_CASE printf("Case %d: ",z)
#define all(a) a.begin(),a.end()
#define intlim 2147483648
#define inf 1000000
#define rtintlim 46340
#define llim 9223372036854775808
#define rtllim 3037000499
#define ull unsigned long long
#define I int

using namespace std;

/* Bits operation */
int Set(int n,int pos)  { return n = n | 1<<pos;}
bool check(int n,int pos) { return n & 1<<pos;}
int Reset(int n, int pos) { return n=n & ~(1<<pos);}

struct data
{
string name;
int cube=0;
};

bool test(data a, data b)
{
return a.cube < b.cube;
}
int main()
{
///freopen("in.txt","r",stdin);
///freopen("out.txt","w",stdout);
vector<data>v;
int t,n;
getint(t);
TEST_CASE(t)
{
data temp;
int a,b,c;
getint(n);
loop(i,n)
{
cin>>temp.name;
getint(a);
getint(b);
getint(c);
temp.cube=a*b*c;
v.pb(temp);
}
sort(all(v),test);
PRINT_CASE;
if(v[0].cube==v[n-1].cube)
pf("no thief\n");
else
{
cout<<v[n-1].name<<" ";
pf("took chocolate from ");
cout<<v[0].name<<endl;
}
v.clear();
}
return 0;
}

```

# Light OJ 1241 – Pinocchio

0
```
/*
*/

#include <bits/stdc++.h>

#define pii pair <int,int>
#define sc scanf
#define pf printf
#define Pi 2*acos(0.0)
#define ms(a,b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define oo 1<<29
#define dd double
#define ll long long
#define EPS 10E-10
#define ff first
#define ss second
#define MAX 10000
#define SZ(a) (int)a.size()
#define getint(a) scanf("%d",&a)
#define loop(i,n) for(int i=0;i<n;i++)
#define TEST_CASE(t) for(int z=1;z<=t;z++)
#define PRINT_CASE printf("Case %d: ",z)
#define all(a) a.begin(),a.end()
#define intlim 2147483648
#define inf 1000000
#define rtintlim 46340
#define llim 9223372036854775808
#define rtllim 3037000499
#define ull unsigned long long
#define I int

using namespace std;

int main()
{
///freopen("in.txt","r",stdin);
///freopen("out.txt","w",stdout);
int t,n;
int ara[100];
getint(t);
TEST_CASE(t)
{
int temp=2;
int ans=0;
getint(n);
loop(i,n)
{
getint(ara[i]);
if(ara[i]>temp)
{
int a=ara[i]-temp;
ans+=a/5;
if(a%5)
ans++;
temp=ara[i];
}
}
PRINT_CASE;
cout<<ans<<endl;
}
return 0;
}

```

# Light OJ 1083 – Histogram

0
```
/*
*/

#include <bits/stdc++.h>

#define pii pair <int,int>
#define sc scanf
#define pf printf
#define Pi 2*acos(0.0)
#define ms(a,b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define oo 1<<29
#define dd double
#define ll long long
#define EPS 10E-10
#define ff first
#define ss second
#define MAX 10000
#define SZ(a) (int)a.size()
#define getint(a) scanf("%d",&a)
#define loop(i,n) for(int i=0;i<n;i++)
#define TEST_CASE(t) for(int z=1;z<=t;z++)
#define PRINT_CASE printf("Case %d: ",z)
#define all(a) a.begin(),a.end()
#define intlim 2147483648
#define inf 1000000
#define rtintlim 46340
#define llim 9223372036854775808
#define rtllim 3037000499
#define ull unsigned long long
#define I int

using namespace std;
int ara[30050];
int n;
ll histogram()
{
stack<int>st;
ll ans=0;
int i=0;
while(i<n)
{
if(st.empty() || ara[st.top()]<=ara[i])
st.push(i++);
else
{
int top=st.top();
st.pop();
ll top_area=ara[top]*(st.empty()?i:i-st.top()-1);
ans=max(ans,top_area);
}
}
while(!st.empty())
{
int top=st.top();
st.pop();
ll top_area=ara[top]*(st.empty()?i:i-st.top()-1);
ans=max(ans,top_area);
}
return ans;
}

int main()
{
///freopen("in.txt","r",stdin);
///freopen("out.txt","w",stdout);
int t;
getint(t);
TEST_CASE(t)
{

getint(n);
loop(i,n)
sc("%d",&ara[i]);
PRINT_CASE;
pf("%lld\n",histogram());
}
return 0;
}

```

# Light OJ 1216 – Juice in the Glass

0

Tutorial for the problem : http://light-online-judge.blogspot.com/search?q=1216

```
/*
*/

#include <bits/stdc++.h>

#define pii pair <int,int>
#define sc scanf
#define pf printf
#define Pi 2*acos(0.0)
#define ms(a,b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define oo 1<<29
#define dd double
#define ll long long
#define EPS 10E-10
#define ff first
#define ss second
#define MAX 10000
#define SZ(a) (int)a.size()
#define getint(a) scanf("%d",&a)
#define loop(i,n) for(int i=0;i<n;i++)
#define TEST_CASE(t) for(int z=1;z<=t;z++)
#define PRINT_CASE printf("Case %d: ",z)
#define all(a) a.begin(),a.end()
#define intlim 2147483648
#define inf 1000000
#define rtintlim 46340
#define llim 9223372036854775808
#define rtllim 3037000499
#define ull unsigned long long
#define I int

using namespace std;

int main()
{
///freopen("in.txt","r",stdin);
///freopen("out.txt","w",stdout);

int t;
cin>>t;
TEST_CASE(t)
{
int r1,r2,h,p;
cin>>r1>>r2>>h>>p;
double p_r = r2+(r1-r2)*(double)p/h*1.0;
double ans = 1.0/3*Pi*p*(p_r*p_r+r2*r2*1.0+p_r*r2);
PRINT_CASE;
pf("%lf\n",ans);
}
return 0;
}

```