zoj 3706 Break Standard Weight
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5009
题目大意:秤都玩过吧,没玩过也应该见过。放在枢轴上的秤杆子(equal length arms, called the beam)、托盘(weighing pan, also called scale)、砝码(standard weights)。每个样例给出两个砝码(质量均为整数),要把其中一个砸成两块(choose a standard weight to break it into 2 parts),当然这两块还是整数,问用这三个砝码组成的种类数最多可能是多少。
题目分析:读懂题之后剩下的就是模拟水了,要注意把所有可能的情况全枚举进来。
code:
#include<stdio.h>
#include<string.h>
int vis[2000];
int judge(int n)
{
if(n>0&&n<2000&&!vis[n])
{
//printf("%d\n",n);
vis[n]=1;
return 1;
}
return 0;
}
int cnt(int a,int b,int c)
{
int ans=0;
ans+=judge(a)+judge(b)+judge(c)+judge(a+b+c);
ans+=judge(a+b)+judge(a-b)+judge(b+c);
ans+=judge(b-c)+judge(a+c)+judge(a-c);
ans+=judge(b-a)+judge(c-b)+judge(c-a);
ans+=judge(a+b-c)+judge(b+c-a)+judge(a-b-c);
ans+=judge(a+c-b)+judge(b-c-a)+judge(c-a-b);
return ans;
}
int main()
{
int i,j,a,b,c,m,n,t,max;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&m,&n);
for(max=0,i=1;i<=(m+1)/2;i++)
{
memset(vis,0,sizeof(vis));
a=i,b=m-i,c=n;
j=cnt(a,b,c);
max=max>j?max:j;
}
for(i=1;i<=(n+1)/2;i++)
{
memset(vis,0,sizeof(vis));
a=i,b=n-i,c=m;
j=cnt(a,b,c);
max=max>j?max:j;
}
printf("%d\n",max);
}
return 0;
}
PS:居然 2 Wrong!?这不科学……