Seniors out of the problem.

Source: Internet
Author: User

Because not on the intranet, your own hands to lay the problem. The meaning is like this: input an n, for n boys, below is the number of N, representing each boy's ability to dance. Enter a m for M girls, below is the number of M, representing each girl's ability to dance. Now to start pairing (must be paired with each other), the principle of pairing is that men and women cannot dance more than one value. Ask how many pairs there are. Case has been forgotten. I'm directly on the code. Have resolved
#include <stdio.h> #include <math.h> #include <string.h> #include <algorithm>using namespace Std;int Main () {int n,m,i,j,sum,k;double a[105];d ouble b[105];while (~scanf ("%d", &n))   //Enter n males {for (i=0;i< n;i++) scanf ("%lf", &a[i]);//input n male capacity value scanf ("%d", &m), for (i=0;i<m;i++) scanf ("%lf", &b[i]);//ditto sort (a,a+n);//Sort (b,b+m) the ability value,//the same as sum=0;//sum on the outside. Otherwise, the pairing is not allowed, for (i=0;i<n;i++) {for (j=0;j<m;j++) {if (Fabs (A[i]-b[j]) <=1.0)//  if paired {b[j]=-232;//  The ability value of the paired girl is assigned a negative number so that she will not be paired again. (Here is the key to solving the problem) sum++; Break;}}} printf ("%d", sum); Output}return 0;}


Seniors out of the problem.

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.