• uvalive 6303 Smartphone Manufacturing


    思路:类似背包,直接搞

    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    #include<cstring>
    #include<map>
    #include<cmath>
    #include<queue>
    #include<cstring>
    #include<set>
    #include<stack>
    #include<string>
    #include<ctime>
    #define LL long long
    #define u64 unsigned long long
    #define maxn 100010
    #define INF 0x3f3f3f3f
    #define eps 1e-6
    using namespace std;
    
    int a[1010];
    bool vi[500010] ;
    vector<int>q;
    set<int>ss;
    void solve(int n)
    {
        memset(vi,0,sizeof(vi)) ;
        vi[0]=true;
        int v,Max=0;
        for( int i = 1 ; i <= n ;i++){
            for(int j = Max ; j >= 0 ;j--)if(vi[j])
            {
                vi[j+a[i]]=true;
            }
            Max+=a[i];
        }
    }
    int main()
    {
        int L,n,m,ans1,ans2,sum,a1,a2 ;
        int i,j,k,T ;
        cin >> T ;
        while(T--)
        {
             scanf("%d",&n) ;
             sum=0;
             for( i = 1 ; i <= n ;i++ ){
                scanf("%d",&a[i]) ;
                sum += a[i] ;
             }
             solve(n) ;
             m = sum/2;
             for( i = m ; i >= 0 ;i--)if(vi[i])
                break ;
             ans1=i ;
             ans2=sum-i;
             k=0;
    
             sum=0;
             scanf("%d",&n) ;
             for( i = 1 ; i <= n ;i++ ){
                scanf("%d",&a[i]) ;
                sum += a[i] ;
             }
             solve(n) ;
             m = sum/2;
             for( i = m ; i >= 0 ;i--)if(vi[i])
                break ;
             a1=i ;
             a2=sum-i;
    
             if(a2-a1 < ans2-ans1 || (a2-a1==ans2-ans1&&a1+a2 >ans2+ans1) )
             {
                    ans1=a1;
                    ans2=a2;
                    k = 1;
             }
    
             sum=0;
             scanf("%d",&n) ;
             for( i = 1 ; i <= n ;i++ ){
                scanf("%d",&a[i]) ;
                sum += a[i] ;
             }
             solve(n) ;
             m = sum/2;
             for( i = m ; i >= 0 ;i--)if(vi[i])
                break ;
             a1=i ;
             a2=sum-i;
    
             if(a2-a1 < ans2-ans1 || (a2-a1==ans2-ans1&&a1+a2 >ans2+ans1) )
             {
                    ans1=a1;
                    ans2=a2;
                    k = 2;
             }
             printf("%c %d %d
    ",'A'+k,ans1,ans2) ;
        }
        return 0 ;
    }
    View Code
  • 相关阅读:
    wifi详解(四)
    wifi详解(三)
    wifi详解(二)
    wifi详解(一)
    Linux下GPIO驱动
    wpa_cli调试工具的使用
    WAPI
    java spring使用Jackson过滤
    JPA 一对多双向映射 结果对象相互迭代 造成堆栈溢出问题方法
    Javassist指引(二)--ClassPool
  • 原文地址:https://www.cnblogs.com/20120125llcai/p/4354965.html
Copyright © 2020-2023  润新知