[zoj]第十九届浙大校赛

Thanks, TuSimple!

Description

As a manager of TuSimple, you are going to hold a dancing party for both the Development Department and the Marketing Department. There will be gentlemen and ladies in total and they are going to dance in pairs. After a careful investigation, we have already known that for each person, they like to dance with either a taller person or a person with smaller height. To simplify the problem, there are no two persons of the same height and people are only allowed to dance with a person of the opposite gender. In order to reserve a proper dancing field, you must calculate the maximum possible number of pairs of people dancing at the same time.

正确解法:

简单模拟然后居然没有写出来QAQ

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <set>
 7 #include <map>
 8 #include <vector>
 9 using namespace std;
10 typedef long long ll;
11 const int inf=0x7fffffff;
12 const int N=100000+100;
13 int T,n,m,x;
14 ll a[N],b[N],nv0[N],nv1[N],nan1[N],nan0[N];
15 int aa,bb,cc,dd;
16 int main()
17 {
18     scanf("%d",&T);
19     while(T--)
20     {
21         int ans=0;
22         memset(a,0,sizeof(a));
23         memset(b,0,sizeof(b));
24         aa=bb=cc=dd=0;
25         scanf("%d %d",&n,&m);
26         for(int i=1;i<=n;i++)
27             scanf("%lld",&a[i]);
28         for(int i=1;i<=m;i++)
29             scanf("%lld",&b[i]);
30         for(int i=1;i<=n;i++)
31         {
32             scanf("%d",&x);
33             if(x==1)    nan1[++bb]=a[i];
34             else    nan0[++aa]=a[i];
35         }
36         for(int i=1;i<=m;i++)
37         {
38             scanf("%d",&x);
39             if(x==1)    nv1[++dd]=b[i];
40             else    nv0[++cc]=b[i];
41         }
42         sort(nan0+1,nan0+aa+1);
43         sort(nan1+1,nan1+bb+1);
44         sort(nv0+1,nv0+cc+1);
45         sort(nv1+1,nv1+dd+1);
46         for(int i=1,j=1;i<=aa&&j<=dd;)
47         {
48             if(nan0[i]>nv1[j])
49             {
50                 ans++;  i++;    j++;
51             }
52             else    i++;
53         }
54         for(int i=1,j=1;i<=bb&&j<=cc;)
55         {
56             if(nan1[i]<nv0[j])
57             {
58                 ans++;  i++;    j++;
59             }
60             else    i++;
61         }
62         printf("%d\n",ans);
63     }
64 
65 
66     return 0;
67 }
View Code

 

posted @ 2019-04-17 21:19  kaike  阅读(150)  评论(0编辑  收藏  举报