【模拟】Vijos P1062 迎春舞会之交谊舞

题目链接:

  https://vijos.org/p/1062

题目大意

  一群男女站成一排,一男一女配对,女的只找左边第一个空闲的男生,给定前n个女生左边的额男生个数,问前n个女生到男伴之间共有几个男生。(n<=1500 女生左侧男生231内)

题目思路:

  【模拟】

  每个女生只找左边的最靠近的闲置男生,所以每当女生左边的男生数变化的时候就说明队伍里加入了新的男生,而这些男生只会影响右侧的女生。

  所以我一开始想到,把男生分成好多群,加入一个女生完把最靠近她的男生群最右的男生配对给这个女生,然后该男生群的数量减少1。

  用数组b记下男生群的位置和数量。之后只要从该女生往左找就行了。

 

 1 //
 2 //by coolxxx
 3 //
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<string>
 7 #include<iomanip>
 8 #include<memory.h>
 9 #include<time.h>
10 #include<stdio.h>
11 #include<stdlib.h>
12 #include<string.h>
13 #include<stdbool.h>
14 #include<math.h>
15 #define min(a,b) ((a)<(b)?(a):(b))
16 #define max(a,b) ((a)>(b)?(a):(b))
17 #define abs(a) ((a)>0?(a):(-(a)))
18 #define lowbit(a) (a&(-a))
19 #define sqr(a) ((a)*(a))
20 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
21 #define eps 1e-8
22 #define J 10000
23 #define MAX 0x7f7f7f7f
24 #define PI 3.1415926535897
25 #define N 1504
26 using namespace std;
27 int n,m,lll,ans,cas;
28 int a[N],b[N],c[N];
29 int main()
30 {
31     #ifndef ONLINE_JUDGE
32 //    freopen("1.txt","r",stdin);
33 //    freopen("2.txt","w",stdout);
34     #endif
35     int i,j,k;
36 //    while(~scanf("%s%d",s,&n))
37     while(~scanf("%d",&n) && n)
38     {
39         for(i=1;i<=n;i++)
40         {
41             scanf("%d",&a[i]);
42             b[i]=a[i]-a[i-1];
43         }
44         for(i=1;i<=n;i++)
45         {
46             for(j=i;j;j--)
47             {
48                 if(b[j])
49                 {
50                     printf("%d ",a[i]-a[j-1]-b[j]+1);
51                     b[j]--;
52                     break;
53                 }
54             }
55         }
56     }
57     return 0;
58 }
59 
60 
61 /*
62 //
63 
64 //
65 */
View Code

 

posted @ 2016-04-06 17:46  Cool639zhu  阅读(497)  评论(0编辑  收藏  举报