Rearrangement (thinking)

 

Links: https://ac.nowcoder.com/acm/contest/3007/D
Source: Cattle-off network

Title Description

Rearrangement means a sequence of elements in this sequence several times (including zero) new sequence obtained after exchange operations
In this problem, possible duplication of numbers in the sequence, they are treated as different elements
For example, the sequence rearrangement 11 there are two
There are two length N sequences of non-negative integers A and B, there is asked how many A permutation satisfies all for 1≤i≤N, there are A I ≦ B I
Since the answer may be large, you only need to output the results to answer 1e9 + 7 modulo
 

Enter a description:

Input of the first line, contains a positive integer N
Next row, N represents a sequence of non-negative integers A
The next row, N represents a sequence of non-negative integers B
1≤N≤100,000,0≤A i,B i≤10 9

Output Description:

Line An integer that represents the answer

Entry

4
1 1 2 3
1 2 3 4

Export

8

 

Official Solution:

Easy to know the ascending sort A and B do not affect the results.
According to numbers from small to large to consider what each position A number of fill.
Example: A (1,2,3)
  B(1,3,4)
When you consider the first position, you can only fill 1.
Considering a second position, 2 or 3 can be filled.
However, because 2 and 3 here are completely equivalent, that is to say we do not care who filled out.
Then we only need to record every step of the number of how many may fill enough, the answer has nothing to do with the previous fill solution.

 

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 #include <string>
 5 #include <math.h>
 6 #include <algorithm>
 7 #include <vector>
 8 #include <stack>
 9 #include <queue>
10 #include <set>
11 #include <map>
12 #include <sstream>
13 const int INF=0x3f3f3f3f;
14 typedef long long LL;
15 const double eps =1e-8;
16 const int mod=1e9+7;
17 const int maxn=1e6+10;
18 using namespace std;
19 
20 int a[100005];
21 int b[100005];
22 
23 int main()
24 {
25     #ifdef DEBUG
26     freopen("sample.txt","r",stdin);
27     #endif
28     
29     int n;
30     scanf("%d",&n);
31     for(int i=1;i<=n;i++)
32         scanf("%d",&a[i]);
33     for(int i=1;i<=n;i++)
34         scanf("%d",&b[i]);
35     sort(a+1,a+1+n);
36     Sort (B + . 1 , B + . 1 + n-);
 37 [      LL ANS = . 1 ;
 38 is      for ( int I = . 1 ; I <= n-; I ++ )
 39      {
 40          int POS = upper_bound, (A + . 1 , A + . 1 + n-, B [ i]) - (a + . 1 ) + . 1 - . 1 ; // looking for a position of the first is greater than b [i] of 
41 is          int NUM = i +-POS . 1 ; // from the beginning or less i b [i] of The number 
42 is          ANS ANS * =% NUM MOD;
 43 is      }
 44 is     printf("%lld\n",ans);
45     
46     return 0;
47 }

 

Is an official to scan double-pointer, because sort, it seems a little better, posted Come

1  Author: Heng May
 2 links: HTTPS: // ac.nowcoder.com/discuss/367149?type=101&order=0&pos=6&page=0 
3  Source: cattle off net
 4  
5 #include <iostream>
 6 #include <cstdio>
 . 7 #include <CString>
 . 8 #include <algorithm>
 . 9 #include <the cmath>
 10   
. 11  the using  namespace STD;
 12 is typedef Long  Long LL;
 13 is  const  int N = 100050, China ;
 14  const LL MOD = 1,000,000,007 ;
 15   
16 int a[N], b[N], ans = 1, n; 
17 int main()
18 {
19      
20     int i, j, k;
21     cin >> n;
22     for(i = 1; i <= n; i ++)
23         scanf("%d", &a[i]);
24     for(i = 1; i <= n; i ++)
25         scanf("%d", &b[i]);
26     sort(a + 1, a + n + 1);
27     sort(b + 1, b + n + 1);
28     for(i = 1, j = 0; i <= n; i ++){
29         while(j < n && a[j + 1] <= b[i])
30             j ++;
31         ans = (LL)ans * max(0ll, j - i + 1ll) % mod;
32     }
33     printf("%d", (ans + mod) % mod);
34      
35     return 0;
36 }

 

 

 

-

Guess you like

Origin www.cnblogs.com/jiamian/p/12319314.html