A. Emoogle Balance:
这道题目看起来比较长,但是主要的就是那个公式:Emoogle Balance = number of times Emoogle is supposed to give a treat
according to the book - number of times he has actually given the treat. 这样的话,我们就只是求和再相减就可以了,因为非0代表前一项,0代表后一项:
according to the book - number of times he has actually given the treat. 这样的话,我们就只是求和再相减就可以了,因为非0代表前一项,0代表后一项:
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <map>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
using namespace std;
int main()
{
int n;
int cnt = 0;
while(scanf("%d", &n))
{
if(!n)
break;
cnt++;
int a;
int num0 = 0;
int num = 0;
for(int i = 0; i < n; ++i)
{
scanf("%d", &a);
if(a)
num++;
else num0++;
}
printf("Case %d: %d\n",cnt, num-num0 );
}
return 0;
}
B. A Digital Satire of Digital Age
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <map>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
using namespace std;
char sp[8][18];
int weight(int n)
{
int sum0 = 0;
int sum1 = 0;
while(n > 0)
{
int tp = n%2;
if(tp)
sum1++;
else
sum0++;
n = n/2;
}
return sum1*500+250*sum0;
}
void tiaozhen2()
{
for(int i = 0; i <= 4; ++i)
{
for(int j = 0; j <= 7; ++j)
{
sp[i][j] = sp[i+2][j];
}
}
for(int i = 0; i <=7; ++i)
{
sp[5][i] = '.';
sp[6][i] = '.';
}
for(int i =6; i >=2 ; --i)
{
for(int j = 10; j < 18; ++j)
{
sp[i][j] = sp[i-2][j];
}
}
for(int i = 10; i < 18; ++i)
{
sp[0][i] = '.';
sp[1][i] = '.';
}
}
void tiaozhen1()
{
for(int i = 1; i <= 5; ++i)
{
for(int j = 0; j <= 7; ++j)
{
sp[i][j] = sp[i+1][j];
}
}
for(int i = 0; i <= 7; ++i)
{
sp[6][i] = '.';
}
for(int i = 5; i >= 1; --i)
{
for(int j = 10; j < 18; ++j)
{
sp[i][j] = sp[i-1][j];
}
}
for(int i = 10; i < 18; ++i)
{
sp[0][i] = '.';
}
}
void tiaozhen4()
{
for(int i = 0; i <= 4; ++i)
{
for(int j = 0; j <= 7; ++j)
{
sp[i][j] = sp[i+1][j];
}
}
for(int i = 0; i <= 7; ++i)
{
sp[5][i] = '.';
}
for(int i = 6; i >=2; --i)
{
for(int j = 10; j < 18; ++j)
{
sp[i][j] = sp[i-1][j];
}
}
for(int i = 10; i < 18; ++i)
{
sp[1][i] = '.';
}
}
void tiaozhen3()
{
for(int i = 6; i >=2; --i)
{
for(int j = 0; j <= 7; ++j)
{
sp[i][j] = sp[i-1][j];
}
}
for(int i = 0; i <= 7; ++i)
{
sp[1][i] = '.';
}
for(int i = 0; i <= 4; ++i)
{
for(int j = 10; j < 18; ++j)
{
sp[i][j] = sp[i+1][j];
}
}
for(int i = 10; i < 18; ++i)
{
sp[5][i] = '.';
}
}
void tiaozhen5()
{
for(int i = 5; i >= 1; --i)
{
for(int j = 0; j <= 7; ++j)
{
sp[i][j] = sp[i-1][j];
}
}
for(int i = 0; i <= 7; ++i)
{
sp[0][i] = '.';
}
for(int i = 1; i <= 5; ++i)
{
for(int j = 10; j < 18; ++j)
{
sp[i][j] = sp[i+1][j];
}
}
for(int i = 10; i < 18; ++i)
{
sp[6][i] = '.';
}
}
void tiaozhen6()
{
for(int i = 6; i >=2; --i)
{
for(int j = 0; j <= 7; ++j)
{
sp[i][j] = sp[i-2][j];
}
}
for(int i = 0; i <= 7; ++i)
{
sp[0][i] = '.';
sp[1][i] = '.';
}
for(int i = 0; i <= 4; ++i)
{
for(int j = 10; j < 18; ++j)
{
sp[i][j] = sp[i+2][j];
}
}
for(int i = 10; i < 18; ++i)
{
sp[6][i] = '.';
sp[5][i] = '.';
}
}
int main()
{
int t;
scanf("%d", &t);
int cnt = 0;
while(t--)
{
memset(sp, 0, sizeof(sp));
cnt++;
int flag = 0;
for(int i = 0; i < 8; ++i)
{
for(int j = 0; j < 18; ++j)
cin >> sp[i][j];
}
printf("Case %d:\n", cnt);
int sumz = 0;
int sumy = 0;
for(int i = 0; i < 7; ++i)
{
for(int j = 0; j <= 7; ++j)
{
if(sp[i][j]>='A'&&sp[i][j]<='Z')
{
sumz = sumz + weight(sp[i][j]);
// cout << sp[i][j]<<endl;
}
}
}
//cout << "*************"<<endl;
for(int i = 0; i < 7; ++i)
{
for(int j = 10; j < 18; ++j)
{
if(sp[i][j]>='A'&&sp[i][j]<='Z')
{
sumy = sumy + weight(sp[i][j]);
//cout << sp[i][j]<<endl;
}
}
}
//cout << sumz << ' ' << sumy << endl;
int tz, ty;
for(int i = 0; i < 7; ++i)
{
for(int j = 0; j <= 7; ++j)
{
if(sp[i][j]=='/')
{
tz = i;
break;
}
}
}
for(int i = 0; i < 7; ++i)
{
for(int j = 10; j < 18; ++j)
{
if(sp[i][j]=='/')
{
ty = i;
break;
}
}
}
if(tz > ty)
{
if(sumz > sumy)
{
printf("The figure is correct.\n");
flag = 1;
}
else
{
if(sumz == sumy)
{
tiaozhen1();
}
else
{
tiaozhen2();
}
}
}
else if(tz == ty)
{
if(sumz == sumy)
{
printf("The figure is correct.\n");
flag = 1;
}
else if(sumz > sumy)
{
tiaozhen3();
}
else
{
tiaozhen4();
}
}
else
{
if(sumz < sumy)
{
printf("The figure is correct.\n");
flag = 1;
}
else if(sumz == sumy)
{
tiaozhen5();
}
else
{
tiaozhen6();
}
}
if(flag == 0)
{
for(int i = 0; i < 7; ++i)
{
for(int j = 0; j < 18; ++j)
cout << sp[i][j];
printf("\n");
}
}
}
return 0;
}
C. Hyper Box
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <map>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
using namespace std;
long long sp[51];
void init()
{
sp[0] = 1;
sp[1] = 2;
for(int i = 2; i <= 50; ++i)
sp[i] = sp[i-2]+sp[i-1];
}
int main()
{
int t, n;
long long len;
init();
scanf("%d", &t);
for(int i = 1; i <= t; ++i)
{
scanf("%d", &n);
long long tot = 1;
for(int j = 0; j < n; ++j)
{
scanf("%lld", &len);
long long sum = 0;
for(int k = 50; k >= 0; k--)
{
while(len >= sp[k])
{
sum++;
len -= sp[k];
}
}
tot *= sum;
}
printf("Case %d: %lld\n", i,tot);
}
return 0;
}
E. Halloween Costumes
这道题目DP转移,(/ □ \)。表示推不出转移方程。看到一发爆搞的,囧:
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <map>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
using namespace std;
using namespace std;
int dp[105][105];
int a[105];
int main()
{
int t;
int counter=0;
int n,m,i,j,k;
scanf("%d",&t);
while(t--)
{
counter++;
scanf("%d%d",&n,&m);
for(i=0; i<n; i++)
scanf("%d",&a[i]);
for(i=0; i<n; i++)
dp[i][i]=1;
for(i=1; i<n; i++)
{
for(j=0; j+i<n; j++)
{
dp[j][j+i]=dp[j+1][j+i]+1;
for(k=j+1; k<=j+i; k++)
if(a[j]==a[k])
{
if(dp[j][j+i]>dp[j][k-1]+dp[k][j+i]-1)
dp[j][j+i]=dp[j][k-1]+dp[k][j+i]-1;
}
}
}
printf("Case %d: %d\n",counter,dp[0][n-1]);
}
return 0;
}
H. Optimal Store
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <map>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
using namespace std;
#define N 34445532.0
#define ee 1e-9
double x1,x2,x3,z,y2,y3;
double d(double a1,double b1,double a2,double b2)
{
return sqrt((a1-a2)*(a1-a2)+(b1-b2)*(b1-b2));
}
double g(int i,double a,double b)
{
double l1,l2,l3;
l1=d(a,b,x1,z);
l2=d(a,b,x2,y2);
l3=d(a,b,x3,y3);
if(i==0)
return (l1+l2+l3)*2.0-l1;
else if(i==1)
return (l1+l2+l3)*2.0-l2;
else
return (l1+l2+l3)*2.0-l3;
}
int main()
{
int cas=0,i,f;
double ans,xm,ym,xn,yn;
double len,xx,yy;
double now,fur;
double xd,yd,sum;
while(cin>>x1>>z>>x2>>y2>>x3>>y3)
{
if(x1<0&&z<0&&x2<0&&y2<0&&x3<0&&y3)
{
break;
}
cas++;
xm=max(x1,max(x2,x3));
ym=max(z,max(y2,y3));
xn=min(x1,min(x2,x3));
yn=min(z,min(y2,y3));
i=3;
sum=N;
while(i--)
{
xx=(x1+x2+x3)/3.0;
yy=(z+y2+y3)/3.0;
len=max(xm-xn,ym-yn);
now=g(i,xx,yy);
while(len>ee)
{
f=1;
while(f==1)
{
f=0;
now=g(i,xx,yy);
xd=xx+len;
yd=yy;
fur=g(i,xd,yd);
if(fur<now)
{
now=fur;
xx=xd;
f=1;
}
if(f==0)
{
now=g(i,xx,yy);
xd=xx-len;
yd=yy;
fur=g(i,xd,yd);
if(fur<now)
{
now=fur;
xx=xd;
f=1;
}
}
if(f==0)
{
now=g(i,xx,yy);
xd=xx;
yd=yy+len;
fur=g(i,xd,yd);
if(fur<now)
{
now=fur;
yy=yd;
f=1;
}
}
if(f==0)
{
now=g(i,xx,yy);
xd=xx;
yd=yy-len;
fur=g(i,xd,yd);
if(fur<now)
{
now=fur;
yy=yd;
f=1;
}
}
}
len=len*0.33;
}
sum=min(sum,now);
}
printf("Case %d: %.8f\n",cas,sum);
}
return 0;
}