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;
    }



  • 相关阅读:
    SQLServer 使用ADSI执行分布式查询ActiveDorectory对象
    GridView的DataFormatString
    我的第一篇博客
    delphi for php 帮助文档的笔记(二)
    用delphiforphp来编写算法注册机第一节
    delphiforphp的中文环境的搭建
    初步拟定的delphiforphp的学习计划
    取當前日期各种數据庫的寫法(转存,备查)
    php两页间传变量(转发,备查)
    关于delphiforphp我想说的。
  • 原文地址:https://www.cnblogs.com/csushl/p/9386608.html
Copyright © 2011-2022 走看看