zoukankan      html  css  js  c++  java
  • hdu-5680 zxa and set(水题)

    题目链接:

    zxa and set

    Time Limit: 2000/1000 MS (Java/Others)   

     Memory Limit: 65536/65536 K (Java/Others)


    Problem Description
     
    zxa has a set A={a1,a2,,an}, which has n elements and obviously (2n1) non-empty subsets.

    For each subset B={b1,b2,,bm}(1mn) of A, which has m elements, zxa defined its value as min(b1,b2,,bm).

    zxa is interested to know, assuming that Sodd represents the sum of the values of the non-empty sets, in which each set B is a subset of A and the number of elements in B is odd, and Seven represents the sum of the values of the non-empty sets, in which each set B is a subset of A and the number of elements in B is even, then what is the value of |SoddSeven|, can you help him?
     

     

    Input
     
    The first line contains an positive integer T, represents there are T test cases.

    For each test case:

    The first line contains an positive integer n, represents the number of the set A is n.

    The second line contains n distinct positive integers, repersent the elements a1,a2,,an.

    There is a blank between each integer with no other extra space in one line.

    1T100,1n30,1ai10^9
     

     

    Output
     
    For each test case, output in one line a non-negative integer, repersent the value of |SoddSeven|.
     

     

    Sample Input
    3
    1
    10
    3
    1 2 3
    4
    1 2 3 4
     

     

    Sample Output
    10
    3
    4
     
    题意:
     
    给定集合有奇数个元素组成的子集和偶数子集组成的得价值差值的绝对值是多少;
     
    思路:
     
    发现就是这个集合里最大的元素;
     
    AC代码
    //#include <bits/stdc++.h>
    #include <iostream>
    #include <queue>
    #include <cmath>
    #include <map>
    #include <cstring>
    #include <algorithm>
    #include <cstdio>
    using namespace std;
    #define Riep(n) for(int i=1;i<=n;i++)
    #define Riop(n) for(int i=0;i<n;i++)
    #define Rjep(n) for(int j=1;j<=n;j++)
    #define Rjop(n) for(int j=0;j<n;j++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
    typedef long long LL;
    const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const int inf=0x3f3f3f3f;
    const int N=1e5+25;
    int n,a[40];
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            Riep(n)scanf("%d",&a[i]);
            sort(a+1,a+n+1);
            printf("%d
    ",a[n]);
        }
    
    
        return 0;
    }
     
     
  • 相关阅读:
    es6 学习笔记
    正则表达式 学习笔记
    knockout 学习笔记
    错误笔记
    zepto 学习笔记
    Dialog提示框
    setContentView( )方法
    SVG图形之几何图形——学习笔记2
    SVG图形之SVG文件如何嵌入HTML文档——学习笔记1
    getchar()的用法
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5494666.html
Copyright © 2011-2022 走看看