HDU 2578 Dating with girls (1)

Source: Internet
Author: User

2 have done, put 1 to fill.

Test instructions gives N and K, and the number of N. is the n number to find the two number x, Y. Make x+y=k.

Calculate all the possibilities. When X0+y0=k. X1+y1=k. Must have unequal. X0!=x1 or Y0!=y1.

For example

4 4

2 2 2 2

The correct output should be 1.


I was sort of, went heavy, and then two points. It seems that many people are using the pointers.

Forget the STL's two-point return subscript function, the mood is not good, too lazy to check, hand hit two points.

#include <cstdio> #include <cstring> #include <string> #include <queue> #include <algorithm > #include <map> #include <stack> #include <iostream> #include <list> #include <set># include<bitset> #include <vector> #include <cmath> #define INF 0x7fffffff#define EPS 1e-8#define LL Long Long#define PI 3.141592654#define CLR (A, B) memset (A,b,sizeof (a)) #define for (I,A,B) for (int i=a;i<b;i++) #define For_ (I,A,B) for (int. i=a;i>=b;i--) #define SF scanf#define PF Printf#define All (v) (v). Begin (), (v). End () #define Acfun Std::ios::sync_with_stdio (False) #define SIZE (100000 +2) #define MOD 1000000007using namespace std;int binsearch (int *a,        int L,int R,int key) {while (l<=r) {int m= (L+R) >>1;        if (A[m]==key) return m;        else if (A[m]>key) r=m-1;    else l=m+1; } return-1;}    int main () {int t;    SF ("%d", &t);        while (t--) {int n,m; SF ("%d%d", &n,&AMP;M);        int a[size];        for (I,0,n) SF ("%d", &a[i]);        Sort (a,a+n);        int cnt =unique (a,a+n)-A;        int ans=0;        for (i,0,cnt) {if (A[i]<=m&&binsearch (a,0,cnt-1,m-a[i))!=-1) ans++;    } PF ("%d\n", ans); }}


HDU 2578 Dating with girls (1)

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.