zoukankan      html  css  js  c++  java
  • hdu 5101

    Select

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 68    Accepted Submission(s): 18


    Problem Description
    One day, Dudu, the most clever boy, heard of ACM/ICPC, which is a very interesting game. He wants to take part in the game. But as we all know, you can't get good result without teammates.
    So, he needs to select two classmates as his teammates. 
    In this game, the IQ is very important, if you have low IQ you will WanTuo. Dudu's IQ is a given number k. We use an integer v[i] to represent the IQ of the ith classmate. 
    The sum of new two teammates' IQ must more than Dudu's IQ.
    For some reason, Dudu don't want the two teammates comes from the same class.
    Now, give you the status of classes, can you tell Dudu how many ways there are.
     
    Input
    There is a number T shows there are T test cases below. (T20)
    For each test case , the first line contains two integers, n and k, which means the number of class and the IQ of Dudu. n ( 0n1000 ), k( 0k<231 ).
    Then, there are n classes below, for each class, the first line contains an integer m, which means the number of the classmates in this class, and for next m lines, each line contains an integer v[i], which means there is a person whose iq is v[i] in this class. m( 0m100 ), v[i]( 0v[i]<231 )
     
    Output
    For each test case, output a single integer.
     
    Sample Input
    1 3 1 1 2 1 2 2 1 1
     
    Sample Output
    5
     
    Source
     
    思路:对于每一行,先询问,后插入树状数组。
    手残写错一个变量竟然过了初判,也是醉了
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #include<queue>
    #include<vector>
    #include<set>
    #include<stack>
    #include<map>
    #include<ctime>
    #include<bitset>
    #define LL long long
    #define ll long long
    #define INF 0x3f3f3f3f
    #define maxn 100010
    #define eps 1e-6
    using namespace std;
    
    int cnt[1010] ,len ;
    LL b[maxn] ;
    int mat[1010][110],xt[maxn] ;
    
    void add(int x)
    {
        while(x< maxn)
        {
            xt[x]++;
            x += (x&-x) ;
        }
    }
    int sum1(int x)
    {
        int ans=0;
        while(x>0)
        {
            ans += xt[x] ;
            x -= (x&-x) ;
        }
        return ans;
    }
    int main()
    {
        int n ,i ,j ,k ,m ;
        int T,sum;
        LL ans;
        cin >> T ;
        while(T--)
        {
            scanf("%d%d",&n,&sum) ;
            len=0;
            for( i = 1 ; i <= n ;i++)
            {
                scanf("%d",&cnt[i]) ;
                for( j = 1 ; j <= cnt[i];j++)
                {
                    scanf("%d",&mat[i][j]) ;
                    b[len++] =mat[i][j] ;
                }
            }
            b[len++]=7897878787888LL;
            sort(b,b+len) ;
            len=unique(b,b+len)-b;
            memset(xt,0,sizeof(xt)) ;
            int hehe=0;
            for( i = 1 ; i <= cnt[1];i++)
            {
                k = lower_bound(b,b+len,mat[1][i])-b;
                k++;
                hehe++;
                add(k) ;
            }
            ans=0;
            for( i = 2 ; i <= n;i++)
            {
                for( j = 1 ; j <= cnt[i];j++)
                {
                    m = sum-mat[i][j] ;
                    k = lower_bound(b,b+len,m)-b;
                    if(k==len-1) continue;
                    if(m!=b[k])k--;
                    k++;
                    //cout<<k<<" "<<sum1(k)<<endl;
                    if(k>0)
                      ans += hehe-sum1(k) ;
                    else ans += hehe;
                }
                for( j = 1 ; j <= cnt[i];j++)
                {
                    k = lower_bound(b,b+len,mat[i][j])-b;
                    k++;
                    hehe++;
                    add(k) ;
                }
            }
            cout<<ans<<endl;
        }
        return 0;
    }
    /*
    1
    3 3
    1 2
    1 2
    2 1 1
    */
    View Code
  • 相关阅读:
    hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
    HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)
    Codeforces 715B & 716D Complete The Graph 【最短路】 (Codeforces Round #372 (Div. 2))
    Codeforces 715A & 716C Plus and Square Root【数学规律】 (Codeforces Round #372 (Div. 2))
    Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))
    Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))
    HDU 5875 Function 【倍增】 (2016 ACM/ICPC Asia Regional Dalian Online)
    axios 简介与安装
    serializer 功能
    APIview 整理
  • 原文地址:https://www.cnblogs.com/20120125llcai/p/4084131.html
Copyright © 2011-2022 走看看