SelectTime
limit:4000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1422 Accepted Submission (s): 395
Problem Descriptionone Day, Dudu, the most clever boy, heard of ACM/ICPC, which is a very interesting game. He wants the game. But as we all know, you can ' t get good result without teammates.
So, he needs to select the classmates as his teammates.
In this game, the IQ is very important and if you have a low IQ you'll wantuo. Dudu ' s IQ is a given number k. We use a integer v[i] to represent the IQ of the ith classmate.
The sum of new teammates ' IQ must more than Dudu ' s IQ.
For some reason, Dudu don ' t want the "teammates comes from the same class."
Now, give you the status of classes, can-tell-dudu How many ways there is.
Inputthere is a number T shows there is t test cases below. ( T≤ )
For each test case, the first line contains integers, n and K, which means the number of class and the IQ of Dudu. N ( 0≤n≤ ), K ( 0≤k<2 ).
Then, there is n classes below, for each class, the first line contains an integer m, which means the number of the class Mates in this class, and for next m lines, each line contains an integer v[i], which means there are a person whose IQ is V [i] in the This class. M 0≤m≤ ), V[i] ( 0 ≤ v [ i " 2 31 )
Outputfor each test case, output a single integer.
Sample Input
13 11 21 22 1 1
Sample Output
5
Sourcebestcoder Round #17
The main topic: give n sets, each set has m number, different sets, m of the value is not necessarily the same, ask from different sets of two number, so that the two number and greater than k of how many kinds.
Problem Solving Ideas:
For a group with m number, if you want to take two number A and B, so that the two number and greater than k, then you can set the number from small to large sort, and then enumerate a, find the number of B that satisfies the condition, when looking at the number of B, you can use the Lower_bound function (binary search). For example: We find the first B that satisfies a+b>k is the number of I, then section i+1,i+2, ... The number is satisfied. The process of enumerating a is counted and added, and the result is twice times the number of the (A, b) pair that satisfies the condition.
The topic requires a different set, which can take advantage of the number pairs that satisfy the condition in the total set-the same set that satisfies the set number pair.
(Note: The maximum number of individual collections is 100, and the number of collections is up to 1000, the maximum number of total collections is 100000)
The code is as follows:
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostream> #include <algorithm> #include <string> #include <vector> #include <deque > #include <list> #include <set> #include <map> #include <stack> #include <queue># Include <numeric> #include <iomanip> #include <bitset> #include <sstream> #include <fstream > #include <limits.h> #define DEBUG "Output for debug\n" #define PI (ACOs ( -1.0)) #define EPS (1e-6) #define INF (1< ; <28) #define SQR (x) (x) * (x) #define MoD 1000000007using namespace std;typedef long long ll;typedef unsigned long long Ull;struct iq{ll M; ll v[100005];} A[1005];int Main () {ll i,j,l,m,n,v,k,t; scanf ("%i64d", &t); while (t--) {scanf ("%i64d%i64d", &n,&k); a[0].m=0; for (i=1,l=0;i<=n;i++) {scanf ("%i64d", &m); A[i].m=m; a[0].m+=M for (j=0;j<m;j++) {scanf ("%i64d", &v); A[i].v[j]=v; A[0].v[l++]=v; } sort (a[i].v,a[i].v+m); } sort (A[0].V,A[0].V+A[0].M); ll Ans=0; for (i=1;i<=n;i++) {for (j=0;j<a[i].m;j++) {v=a[i].v[j]; ll X=lower_bound (a[0].v,a[0].v+a[0].m,k-v+1)-a[0].v; ll N1=a[0].m-x; printf ("I=%i64d j=%i64d x=%i64d n1=%i64d", i,j,x,n1); ll Y=lower_bound (a[i].v,a[i].v+a[i].m,k-v+1)-a[i].v; ll N2=a[i].m-y; printf ("I=%i64d j=%i64d y=%i64d n2=%i64d\n", i,j,y,n2); ANS+=N1-N2; }} printf ("%i64d\n", ANS/2); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 5101 Select (two number of scenarios with different sets greater than K)