zoj 3706 Break Standard Weight

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!?这不科学……








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值