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

Source: Internet
Author: 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, 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 your n positive integers and an integer k. Need to calculate how many different solutions the equation x + y = k have. X and y must be among the given n integers. Solutions is 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 the 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 to remove duplicate elements and elements greater than k, because elements greater than k are definitely not equal to K Equation, can not determine whether there is 0 in the data, so the element is equal to K is retained, each one of the number of hash, and then a for loop, see hash[K-a[i]] is 1, is the words cnt++;
1#include <queue>2#include <math.h>3#include <stdio.h>4#include <string.h>5#include <iostream>6#include <algorithm>7 using namespacestd;8 #defineN 1234569 #defineM 1234Ten  One intn,k; A intA[n]; - intMain () - { the     intT;cin>>T; -      while(t--) -     { -scanf"%d%d",&n,&k); +         intha[n]={0}; -         intj=0, C; +          for(intI=0; i<n;i++) A         { atscanf"%d",&c); -             if(C>k | | ha[c])Continue; -a[j++]=C; -ha[c]=1; -         } -         intCnt=0; in          for(intI=0; i<j;i++) -             if(ha[KA[i]]) tocnt++; +  -cout<<cnt<<Endl; the     } *     return 0; $}

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.