zoukankan      html  css  js  c++  java
  • FZU2127_养鸡场

    题目的意思为要你求出满足三边范围条件且周长为n的三角形的数目。

    其实做法是直接枚举最短边,然后就可以知道第二条边的取值范围,同时根据给定的范围缩小范围。

    同时根据第二条边的范围推出第三条边的范围,再次缩小范围。此时范围里面的数就是此时最短边对应的可行数。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #define ll long long
    using namespace std;
    
    ll n,m,k,x[4],y[4],ans;
    
    
    ll Max(ll X,ll Y) { return X>Y?X:Y; }
    ll Min(ll X,ll Y) { return X<Y?X:Y; }
    
    int main()
    {
        while (scanf("%I64d",&n)!=EOF)
        {
            for (ll i=1; i<4; i++) scanf("%I64d%I64d",&x[i],&y[i]);
            ans=0;
            for (ll i=Max(x[1],1); i<=n/3; i++)
            {
                ll tepx=Max(i,(n-2*i)/2+1),tepy=(n-i)/2;
                tepx=Max(x[2],tepx),tepy=Min(y[2],tepy);
                if (tepx>tepy) continue;
                //cout<<i<<" : "<<tepx<<' '<<tepy<<endl;
                tepx=n-i-tepx,tepy=n-i-tepy;
                tepy=Max(x[3],tepy),tepx=Min(y[3],tepx);
                if (tepy>tepx) continue;
                ans+=tepx-tepy+1;
            }
            printf("%I64d
    ",ans);
        }
        return 0;
    }
    如有转载,请注明出处(http://www.cnblogs.com/lochan)
  • 相关阅读:
    Javascript 进阶
    transform顺序浅谈
    js对象克隆
    js动画最佳实现——requestAnimationFrame
    svg标签
    typeof和instanceof
    js变量浅谈
    X-UA-compatible浅谈
    封装$
    面向对象
  • 原文地址:https://www.cnblogs.com/lochan/p/3433949.html
Copyright © 2011-2022 走看看