zoukankan      html  css  js  c++  java
  • Atoder-3620

    The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.

    He has N parts for each of the three categories. The size of the i-th upper part isAi, the size of the i-th middle part is Bi, and the size of the i-th lower part isCi.

    To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.

    How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.

    Constraints

    • 1N105
    • 1Ai109(1iN)
    • 1Bi109(1iN)
    • 1Ci109(1iN)
    • All input values are integers.
    Input

    Input is given from Standard Input in the following format:

    N
    A1  AN
    B1  BN
    C1  CN
    
    Output

    Print the number of different altars that Ringo can build.

    Sample Input 1

    2
    1 5
    2 4
    3 6
    
    Sample Output 1

    3
    

    The following three altars can be built:

    • Upper: 1-st part, Middle: 1-st part, Lower: 1-st part
    • Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part
    • Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part
    Sample Input 2

    3
    1 1 1
    2 2 2
    3 3 3
    
    Sample Output 2

    27
    
    Sample Input 3

    6
    3 14 159 2 6 53
    58 9 79 323 84 6
    2643 383 2 79 50 288
    
    Sample Output 3

    87


    题解:对上,中,下分别排序;然后对于每一个middle分别查找比他小的lower 与比他大的upper的数量

    两个数相乘既得到一个middle的数量,将每一个相加即可得到max_sum的值;

    AC代码为:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<vector>
    #include<cmath>
    #include<algorithm>
    using namespace std;


    typedef long long LL;
    const int MAX = 1e5 + 10;
    LL N;
    LL a[MAX], b[MAX], c[MAX];


    int main()
    {
    cin >> N;
    for (int i = 1; i <= N; i++)
    cin >> a[i];
    for (int i = 1; i <= N; i++)
    cin >> b[i];
    for (int i = 1; i <= N; i++)
    cin >> c[i];
    sort(a + 1, a + 1 + N), sort(b + 1, b + 1 + N), sort(c + 1, c + 1 + N);


    LL sum = 0;
    LL ai = 0, ci = 0;
    for (int i = 1; i <= N; i++)
    {
    while (a[ai + 1]<b[i] && ai + 1 <= N)
    ai++;
    while (c[ci + 1] <= b[i] && ci + 1 <= N)
    ci++;
    sum += ai * (N - ci);
    }


    cout << sum << endl;


    return 0;
    }



  • 相关阅读:
    [HAOI2015][bzoj 4033]树上染色(树dp+复杂度分析)
    20190716NOIP模拟赛T1 礼物(概率dp+状压)
    20190716NOIP模拟赛T2 通讯(tarjan缩点+贪心)
    延迟载入Dll(动态载入Dll)
    Dll重定向(尚存否?)
    delete和delete[] 区别
    06 序列号保护 学习分析(字符串)
    05 初识加壳脱壳
    04 复制删除行为IDA反汇编
    03 复制行为动态分析
  • 原文地址:https://www.cnblogs.com/csushl/p/9386608.html
Copyright © 2011-2022 走看看