zoukankan      html  css  js  c++  java
  • hdu4277 暴力

    hdu4277   暴力

    USACO ORZ

    Time Limit : 5000/1500ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 4   Accepted Submission(s) : 2
    Problem Description
    Like everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The old rectangular shapes are out of favor; new geometries are the favorite.
    I. M. Hei, the lead cow pasture architect, is in charge of creating a triangular pasture surrounded by nice white fence rails. She is supplied with N fence segments and must arrange them into a triangular pasture. Ms. Hei must use all the rails to create three sides of non-zero length. Calculating the number of different kinds of pastures, she can build that enclosed with all fence segments. 
    Two pastures look different if at least one side of both pastures has different lengths, and each pasture should not be degeneration.
     
    Input
    The first line is an integer T(T<=15) indicating the number of test cases. The first line of each test case contains an integer N. (1 <= N <= 15) The next line contains N integers li indicating the length of each fence segment. (1 <= li <= 10000)
     
    Output
    For each test case, output one integer indicating the number of different pastures.
     
    Sample Input
    1
    3
    2 3 4
     
    Sample Output
    1
     
    Source
    2012 ACM/ICPC Asia Regional Changchun Online
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #include<set>
    
    using namespace std;
    
    const int maxn=1000100;
    
    typedef long long ll;
    int T;
    int a,b,c;
    int l[maxn],n;
    set<ll> s;
    
    void dfs(int i)
    {
        if(i==n+1){
            if(a&&a<=b&&b<=c&&a+b>c){
                if(s.find((a<<16)|b)==s.end()) s.insert((a<<16)|b);
            }
            return;
        }
        a+=l[i];dfs(i+1);a-=l[i];
        b+=l[i];dfs(i+1);b-=l[i];
        c+=l[i];dfs(i+1);c-=l[i];
    }
    
    int main()
    {
        cin>>T;
        while(T--){
            cin>>n;
            for(int i=1;i<=n;i++) scanf("%d",&l[i]);
            s.clear();
            a=b=c=0;
            dfs(1);
            cout<<(int)s.size()<<endl;
        }
        return 0;
    }
    View Code
    没有AC不了的题,只有不努力的ACMER!
  • 相关阅读:
    去除空格
    常见的Js
    无法访问 ASP 兼容性模式
    asp.net mvc 笔记一
    PowerDesigner如何将设计的表更新到数据库中
    微信小程序基于第三方websocket的服务器端部署
    C# Linq GroupBy 分组过滤求和
    一步一步教你用c# entity framework6 连接 sqlite 实现增删改查
    执行指定iframe页面的脚本
    vs2017 x64 ibatis.net 平台调用 Oracle.DataAccess, Version=2.112.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342 x64
  • 原文地址:https://www.cnblogs.com/--560/p/4782233.html
Copyright © 2011-2022 走看看