JZOJ 1381. deleted

Time Limits: 1000 ms  Memory Limits: 65536 KB  Detailed Limits 

Description

  Alice on chemical class and distracted, he first drew a line 3 of Form N columns, then the first row of numbers 1 to N fill in the form, to ensure that each number appears only once, while he also filled two rows numbers 1 to N, but not limit the number of occurrence of each number.
  Alice now want to delete several columns so that each row after row of identical sequence finished, the program requires a minimum of computing how many columns to delete.

Input

  The first row contains an integer N (1 <= N <= 100000), the number of columns of the table.
  The next three lines each line contains N integers, each a number between 1 to N, the number of the first row and different from each other.

Output

  Output requires a minimum number of columns deleted.

Sample Input

Input 1: 
. 7 
. 5. 4. 3 2 1. 6. 7 
. 5. 5 1 1. 3. 4. 7 
. 3. 7 1. 4. 5. 6 2 

Input 2: 
. 9 
1. 3. 5. 9. 8. 6 2. 4. 7 
2 1. 5. 6. 4. 9. 3. 4. 7 
. 3. 5 1 986287

Sample Output

Output 1: 
4 

Output 2: 
2

Data Constraint

Hint

[Explain] Sample
  Example 1, Alice needs to delete four of 2,4,6,7, and each row is drained sequence 1,3,5.
[Data] range
  of 40% of the data N <= 100
  70% of the data N <= 10000
 1 #include <stdio.h>
 2 #include <cmath>
 3 #include<iostream>
 4 #define fo() for(register int i=0;i<n;i++)
 5 using namespace std;
 6 int n,row1[100010],row2[100010],row3[100010],count2[100010],count3[100010],ans=0;
 7 int main()
 8 {
 9     cin>>n;
10     fo(){
11         cin>>row1[i];
12     }
13     fo(){
14         cin>>row2[i];
15         count2[row2[i]]++;
16     }
17     fo(){
18         cin>>row3[i];
19         count3[row3[i]]++;
20     }
21     register int flag=0;
22     while(!flag){
23         flag=1;
24         fo()
25         {
26             if (row1[i]&&!(count2[row1[i]]&&count3[row1[i]])){
27                 flag=0;
28                 ans++;
29                 row1[i]=0;
30                 count2[row2[i]]--;
31                 count3[row3[i]]--;
32             } 
33         }
34     }
35     cout<<ans;
36     return 0;
37 }

Guess you like

Origin www.cnblogs.com/anbujingying/p/11297610.html