【CUGBACM15级BC第17场 B】hdu 5101 Select
2017-08-12 12:05
441 查看
Select
[align=center]Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2112 Accepted Submission(s): 594
[/align]
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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
), v[i]( 0≤v[i
]<231
)
[align=left]Output[/align]
For each test case, output a single integer.
[align=left]Sample Input[/align]
1
3 1
1 2
1 2
2 1 1
[align=left]Sample Output[/align]
5
题意是说从n个小组里的某两个小组中各选一个人,要求所选的两个人的IQ和必须大于k。问符合的情况有多少种。
答案=从所有数中选择的两个加和大于k的数的方案数-在同一个集合中选择的两个加和大于k的数的方案数 而对于同一个集合中选择的两个加和大于k的方案数是可以直接排序然后利用单调性快速统计出来的。
————出题者
PS:注意答案可以超int,所以必须longlong...
#include <bits/stdc++.h> #define bbf5 _ ios_base::sync_with_stdio(0);cin.tie(0); using namespace std; typedef long long LL; vector<LL> b; int t, n; LL a[1010][110]; int m[1010]; int main() { _ LL flag; while (~scanf("%d", &t)) { while (t--) { scanf("%d%I64d", &n, &flag); b.clear(); int sum_num = 0; for (int i = 0; i < n; i++) { scanf("%d", &m[i]); sum_num += m[i]; for (int j = 0; j < m[i]; j++) { scanf("%I64d", &a[i][j]); b.push_back(a[i][j]); } sort(a[i], a[i] + m[i]); } sort(b.begin(), b.end()); LL ans = 0, x, y; for (int i = 0; i < n; i++) { for (int j = 0; j < m[i]; j++) { LL temp = a[i][j]; int tmp1 = lower_bound(b.begin(), b.end(), flag - temp + 1) - b.begin(); x = (int)b.size() - tmp1; if (temp * 2 > flag) { x--; } int tmp2 = lower_bound(a[i], a[i] + m[i], flag - temp + 1) - a[i]; y = m[i] - tmp2; if (temp * 2 > flag) { y--; } ans += (x - y); } } printf("%I64d\n", ans / 2); } } return 0; }
相关文章推荐
- 【CUGBACM15级BC第17场 A】hdu 5100 Chessboard
- 【CUGBACM15级BC第六场 A】hdu 4981 Goffi and Median
- 【CUGBACM15级BC第29场 A】hdu 5170 GTY's math problem
- 【CUGBACM15级BC第三场 B】hdu 4908 BestCoder Sequence
- 【CUGBACM15级BC第12场 A】【STL】hdu 5058 So easy
- 【CUGBACM15级BC第28场 B】hdu 5167 Fibonacci
- 【CUGBACM15级BC第六场 B】hdu 4982 Goffi and Squary Partition
- 【CUGBACM15级BC第18场 A】hdu 5104 Primes Problem
- 【CUGBACM15级BC第9场 B】hdu 4994 Revenge of Nim
- 【CUGBACM15级BC第26场 A】hdu 5158 Have meal
- 【CUGBACM15级BC第12场 B】hdu 5059 Help him
- 【CUGBACM15级BC第31场 A】hdu 5178 pairs
- 【CUGBACM15级BC第20场 A】hdu 5123 who is the best?
- 【CUGBACM15级BC第二场 A】hdu 4883 TIANKENG’s restaurant
- 【CUGBACM15级BC第25场 A】hdu 5154 Harry and Magical Computer
- 【CUGBACM15级BC第26场 B】hdu 5159 Card
- 【CUGBACM15级BC第27场 B】hdu 5163 Taking Bus
- 【CUGBACM15级BC第五场 A】hdu 4956 Poor Hanamichi
- 【CUGBACM15级BC第33场 B】hdu 5187 zhx's contest
- 【CUGBACM15级BC第37场 A】hdu 5202 Rikka with string