HDU 2578 Dating with girls(1) [補7-26]

來源:互聯網
上載者:User

標籤:

Dating with girls(1)

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3869    Accepted Submission(s): 1196


Problem DescriptionEveryone in the HDU knows that the number of boys is larger than the number of girls. But now, every boy wants to date with pretty girls. The girls like to date with the boys with higher IQ. In order to test the boys ‘ IQ, The girls make a problem, and the boys who can solve the problem
correctly and cost less time can date with them.
The problem is that : give you n positive integers and an integer k. You need to calculate how many different solutions the equation x + y = k has . x and y must be among the given n integers. Two solutions are different if x0 != x1 or y0 != y1.
Now smart Acmers, solving the problem as soon as possible. So you can dating with pretty girls. How wonderful!
 

 

InputThe first line contain an integer T. Then T cases followed. Each case begins with two integers n(2 <= n <= 100000) , k(0 <= k < 2^31). And then the next line contain n integers. 

 

OutputFor each cases,output the numbers of solutions to the equation. 

 

Sample Input25 41 2 3 4 58 81 4 5 7 8 9 2 6 

 

Sample Output35 

 

Source HDU 2009-5 Programming Contest  

 

Recommendlcy   |   We have carefully selected several similar problems for you:  2575 2579 2573 2576 2574  要去除重複的元素和大於k的元素,因為大於k的元素是肯定組不成等於k的方程的,不能確定資料裡是否有0,所以等於k的元素也保留著,每存一個數都hash一下,然後一遍for迴圈,看 hash[ k-a[i] ]是否為1,是的話cnt++;
 1 #include<queue> 2 #include<math.h> 3 #include<stdio.h> 4 #include<string.h> 5 #include<iostream> 6 #include<algorithm> 7 using namespace std; 8 #define N 123456 9 #define M 123410 11 int n,k;12 int a[N];13 int main()14 {15     int t;cin>>t;16     while(t--)17     {18         scanf("%d%d",&n,&k);19         int ha[N]={0};20         int j=0,c;21         for(int i=0;i<n;i++)22         {23             scanf("%d",&c);24             if(c>k || ha[c])continue;25             a[j++]=c;26             ha[c]=1;27         }28         int cnt=0;29         for(int i=0;i<j;i++)30             if(ha[ k-a[i] ])31                 cnt++;32 33         cout<<cnt<<endl;34     }35     return 0;36 }

 

HDU 2578 Dating with girls(1) [補7-26]

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.