"Simulation" Vijos P1062 Ballroom Dance of the spring party

Source: Internet
Author: User

Topic Links:

https://vijos.org/p/1062

Main Topic :

A group of men and women stood in a row, a man and a woman paired, the female only find the left the first free boy, given the number of men on the left of the top n girls, ask the first n girls to male with a few boys. (n<=1500 girl left male 231 inside)

Topic Ideas:

  Simulation

  Each girl only find the closest to the left of the idle boys, so every time the number of boys on the left side of the change in the team to indicate the addition of new boys, and these boys will only affect the girls on the right.

So I began to think, the boys into a lot of groups, joined a girl to the most close to her boys to the right of the boys to match to this girl, and then the number of the boys group decreased by 1.

Use array b to make a note of the location and number of males. Then just go from the girl to the left.

1 //2 //by Coolxxx3 //4#include <iostream>5#include <algorithm>6#include <string>7#include <iomanip>8#include <memory.h>9#include <time.h>Ten#include <stdio.h> One#include <stdlib.h> A#include <string.h> -#include <stdbool.h> -#include <math.h> the #defineMin (a) < (b) ( A):(B)) - #defineMax (a) (a) > (b)? ( A):(B)) - #defineABS (a) ((a) >0? ( A):(-(a))) - #defineLowbit (a) (a& (a)) + #defineSqr (a) ((a) * (a)) - #defineSwap (a) (a) ^= (b), (b) ^= (a), (a) ^= (b)) + #defineEPS 1e-8 A #defineJ 10000 at #defineMAX 0x7f7f7f7f - #definePI 3.1415926535897 - #defineN 1504 - using namespacestd; - intN,m,lll,ans,cas; - intA[n],b[n],c[n]; in intMain () - { to #ifndef Online_judge + //freopen ("1.txt", "R", stdin); - //freopen ("2.txt", "w", stdout); the     #endif *     inti,j,k; $ //while (~scanf ("%s%d", S,&n))Panax Notoginseng      while(~SCANF ("%d", &n) &&N) -     { the          for(i=1; i<=n;i++) +         { Ascanf"%d",&a[i]); theb[i]=a[i]-a[i-1]; +         } -          for(i=1; i<=n;i++) $         { $              for(j=i;j;j--) -             { -                 if(B[j]) the                 { -printf"%d", a[i]-a[j-1]-b[j]+1);Wuyib[j]--; the                      Break; -                 } Wu             } -         } About     } $     return 0; - } -  -  A /* + // the  - // $ */
View Code

"Simulation" Vijos P1062 Ballroom Dance of the spring party

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.