BestCoder Round #17

http://acm.hdu.edu.cn/showproblem.php?pid=5101

Select

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

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. (T≤20)
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 ( 0≤n≤1000 ), k( 0≤k<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( 0≤m≤100 ), vi

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

```
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
vector<int >vi[1000+5],v;
typedef long long ll;
int T,n,m,k,x;
int main() {
    //freopen("D://imput.txt","r",stdin);
    scanf("%d",&T);
    while(T--) {
        v.clear();
        scanf("%d%d",&n,&k);
        for(int i=0; i<n; i++) {
            scanf("%d",&m);
            vi[i].clear();
            for(int j=0; j<m; j++) {
                scanf("%d",&x);
                vi[i].push_back(x);
                v.push_back(x);
            }
            sort(vi[i].begin(),vi[i].end());
        }
        sort(v.begin(),v.end());
        ll ans=0,sum=0;
        for(int i=0; i<v.size(); i++)
            ans+=v.end()-lower_bound(v.begin(),v.end(),k-v[i]+1)-1;//chongguyici
        for(int i=0; i<n; i++) {
            for(int j=0; j<vi[i].size(); j++)
                sum=sum+vi[i].end()-lower_bound(vi[i].begin(),vi[i].end(),k-vi[i][j]+1)-1;
        }
        printf("%I64d\n",(ans-sum)/2);
    }
    return 0;
}

“`

你可能感兴趣的:(CF)