https://vjudge.net/problem/LightOJ-1030
#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
int main()
{
int t;
cin>>t;
int a[110];
double dp[110];
for(int i=1;i<=t;i++)
{
memset(a,0,sizeof(a));
memset(dp,0,sizeof(dp));
dp[1]=1;
int n,h;
double ans=0;
cin>>n;
for(int j=1;j<=n;j++)
cin>>a[j];
for(int j=1;j<=n;j++){
if(n-j<6)
h=n-j;
else
h=6;
for(int k=1;k<=h;k++)
{
dp[j+k]+=dp[j]*1.0*1/h;
}
ans+=1.0*a[j]*dp[j];
}
printf("Case %d: %lf
",i,ans);
}
return 0;
}
https://vjudge.net/problem/LightOJ-1027
#include<iostream>
using namespace std;
int gcd(int a,int b)
{
return b>0?gcd(b,a%b):a;
}
int main()
{
int t;
int a[110];
cin>>t;
for(int i=1;i<=t;i++)
{
int n,sum1=0,sum2=0,door1=0,door2=0;
cin>>n;
for(int j=0;j<n;j++)
{
cin>>a[j];
if(a[j]>0)
{
sum1+=a[j];
door1++;
}
else
{
sum2+=-a[j];
door2++;
}
}
int q=gcd(sum1+sum2,n-door2);
cout<<"Case "<<i<<':'<<' ';
if(door2==n)
cout<<"inf"<<endl;
else
cout<<(sum1+sum2)/q<<'/'<<(n-door2)/q<<endl;
}
return 0;
}
https://vjudge.net/problem/LightOJ-1038
#include<stdio.h>
#include<iostream>
#include<cstring>
using namespace std;
int main(){
double dp[100010];
memset(dp,0,sizeof(dp));
for(int i=2;i<=100000;i++){
int num=2;
double sum=0;
for(int j=2;j*j<=i;j++){
if(i%j==0){
num++;
sum+=dp[j];
if(j*j!=i){
num++;
sum+=dp[i/j];
}
}
}
dp[i]=(1.0*sum+num)/(num-1);
}
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++){
int n;
cin>>n;
printf("Case %d: %lf
",i,dp[n]);
}
return 0;
}