HDU 5100 Select 排序相加
来源:互联网 发布:mac防蹭网软件 编辑:程序博客网 时间:2024/05/17 23:57
Select
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 565 Accepted Submission(s): 167
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.
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 ), v[i]( 0≤v[i]<231 )
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 (
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(
Output
For each test case, output a single integer.
Sample Input
13 11 21 22 1 1
Sample Output
5
/*HDU 5101 看时间长 刚开始暴力解决的 被人hack了。。。 int可以表示2^31啊 为什么这里非要用LL才能过?谁看了跟我说下 对每组进行排序,然后可以在O(n)时间求出同组相加大于k的数量。然后对整体排序,用O(N)求出所有的两两相加大于k的数量,然后相减。 */#include<iostream>#include<algorithm>#include<string>#include<stdio.h>#include<stack>#include<vector>typedef __int64 LL;using namespace std;LL v[1010][111];LL sum[1005*105];int cnt[1005];bool cmp(int a,int b) { return a<b; } int main(){ int t,i,j,tot,n,ii,jj;LL k,del,ans; //freopen("test.txt","r",stdin); scanf("%d",&t); while(t--) { scanf("%d%I64d",&n,&k); tot=0; del=0; ans=0; for(i=0;i<n;i++) { scanf("%d",&cnt[i]); for(j=0;j<cnt[i];j++) { scanf("%I64d",&v[i][j]); sum[tot++]=v[i][j]; } sort(v[i],v[i]+cnt[i],cmp); LL *vv=v[i]; for(ii=0,jj=cnt[i]-1;ii<jj;)//每个 { if(vv[ii]+vv[jj]>k) { del+=(jj-ii);//说明j与i后面每个都可以大于jj--; } else ii++; } } sort(sum,sum+tot,cmp); for(i=0,j=tot-1;i<j;)//总的 { if(sum[i]+sum[j]>k) { ans+=(j-i);j--; } else i++; }ans-=del;printf("%I64d\n",ans); } return 0;}
0 0
- HDU 5100 Select 排序相加
- hdu 1002 大数相加
- hdu 1715 大树相加
- HDU 1002(大数相加)
- HDU 1250(大数相加)
- hdu 倒转相加
- hdu 1002大数相加
- HDU 1047 大数相加
- HDU 2844 大数相加
- HDU 1047 大数相加
- HDU-1002-大数相加
- hdu 1002 大数相加
- hdu 1002 大数相加
- hdu 2100 大数相加
- HDU 1215 因子相加
- select 排序
- hdu 1753 高精度小数相加
- hdu 1002 java 大数相加
- android一个小网络图片查看器
- javascript数组
- PHP文件操作(一)获取文件信息,读取文件
- POJ2253Floyd
- 刚在在win8.1下装了ubuntu12.04
- HDU 5100 Select 排序相加
- 深度搜索,石油采集,
- hdu 3555 bomb 数位dp
- servlet与tomcat
- python threading(转)
- T-SQL的学习总结一
- 敕勒哥
- Mac OS X Yosemite 10.10 配置 Apache+PHP 教程注意事项
- 抓住商业先机,银行保险太给力