我是靠谱客的博主 淡淡小懒虫,最近开发中收集的这篇文章主要介绍hdu5101——SelectSelect,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Select

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


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
BestCoder Round #17
 

Recommend
heyang   |   We have carefully selected several similar problems for you:   5103  5102  5100  5099  5098 
 

Statistic | Submit | Discuss | Note


先计算总的,然后排出在同一个班级的就行复杂度是n*m


#include <map>  
#include <set>  
#include <list>  
#include <stack>  
#include <queue>  
#include <vector>  
#include <cmath>  
#include <cstdio>  
#include <cstring>  
#include <iostream>  
#include <algorithm>  
  
using namespace std;

const int N = 1010;

vector <__int64> ma[N];
__int64 all[N * 100];

int main()
{
    __int64 t;
    scanf("%I64d", &t);
    while (t--)
    {
        __int64 n, k, v, res, m;
        scanf("%I64d%I64d", &n, &k);
        res = 0;
        for (int i = 1; i <= n; ++i)
        {
            scanf("%I64d", &m);
            ma[i].clear();
            for (int j = 1; j <= m; ++j)
            {
                scanf("%I64d", &v);
                ma[i].push_back(v);
                all[res++] = v;
            }
            sort(ma[i].begin(), ma[i].end());
        }
        sort(all, all + res);
        __int64 ans = 0, tmp = 0;
        int i = 0, j = res - 1;
        while (i < j)
        {
            while(i < j && all[i] + all[j] > k)
            {
                j--;
            }
            tmp += j - i;
            i++;
        }
        ans = (__int64)(res * (res - 1) / 2) - tmp;
        for (int i = 1; i <= n; ++i)
        {
            int j = 0, l = ma[i].size() - 1;
            tmp = 0;
            int cnt = ma[i].size();
            while(j < l)
            {
                while(j < l && ma[i][j] + ma[i][l] > k)
                {
                    l--;
                }
                tmp += l - j;
                j++;
            }
            ans -= (__int64)(cnt * (cnt - 1) / 2) - tmp;
        }
        printf("%I64dn", ans);
    }
    return 0;
}




最后

以上就是淡淡小懒虫为你收集整理的hdu5101——SelectSelect的全部内容,希望文章能够帮你解决hdu5101——SelectSelect所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部