zoukankan      html  css  js  c++  java
  • C

    原题地址:http://abc077.contest.atcoder.jp/tasks/arc084_a;

    Time limit : 2sec / Memory limit : 256MB

    Score : 300 points

    Problem Statement

    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 is Ai, the size of the i-th middle part is Bi, and the size of the i-th lower part is Ci.

    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

    • 1≤N≤105
    • 1≤Ai≤109(1≤iN)
    • 1≤Bi≤109(1≤iN)
    • 1≤Ci≤109(1≤iN)
    • 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

    Copy
    2
    1 5
    2 4
    3 6
    

    Sample Output 1

    Copy
    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

    Copy
    3
    1 1 1
    2 2 2
    3 3 3
    

    Sample Output 2

    Copy
    27
    

    Sample Input 3

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

    Sample Output 3

    Copy
    87
    题目意思:给三层数据,求从小到大的可能顺序的可能情况;
    解题思路:没有太多难点,但是容易出错;

    代码:
    #include<iostream>
    #include<string>
    #include<algorithm>
    #include <string.h>
    #include <stdio.h>
    #include <math.h>
    #include <set>
    #include <queue>
    #include <stack>
    #include <map>
     
    using namespace std;
    typedef long long LL;
    const int INF = int(1e9);
    const int MAX = 1000020;
    LL N;
    LL a[MAX],b[MAX],c[MAX];
     
    void Cin(LL a[])
    {
        for(int i = 1;i<=N;i++)
            scanf("%lld",&a[i]);
    }
     
    int main()
    {
        cin>>N;
        Cin(a),Cin(b),Cin(c);
        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++;
           // cout<<ai<<" "<<ci<<endl;
            sum += ai*(N-ci);  //因为相乘可能会溢出,所以要为LL;
        }
     
        cout<<sum<<endl;
     
        return 0;
    }
     
  • 相关阅读:
    《c++ templates》学习笔记(8)——第十一章 模板实参演绎
    关于Decorator模式
    《c++ templates》学习笔记(11)——第十章 实例化
    《c++ templates》学习笔记(5)——第六章 模板实战
    《c++ templates》学习笔记(9)——第十二章 特化与重载
    关于windows Power Shell (1)
    VC版的IniFile
    《c++ templates》学习笔记(6)——第七章 模板术语
    《c++ templates》学习笔记(4)——第五章,技巧性基础知识
    boost::test
  • 原文地址:https://www.cnblogs.com/a2985812043/p/7788929.html
Copyright © 2011-2022 走看看