Bzoj2044: 3D Missile interception

Source: Internet
Author: User
2044: 3D Missile interception time limit: 10 sec memory limit: 259 MB
Submit: 175 solved: 76
[Submit] [Status] Description a war is in full swing between country A and country B. With its powerful economic strength, Country B has developed countless remote attack missiles. The leaders of country B hope to directly destroy the headquarters of country A through these missiles, so as to win the battle! Of course, the people of country A will not allow such incidents, so there are still interceptions of missiles in this world. Now, you are a Senior Assistant in charge of Missile interception in Country. The missiles of country B have effectively formed three-dimensional strikes. We can abstract the positions of these missiles to the points in the middle of the Three Dimensions (ignored). For the sake of simplicity, we only consider an instantaneous state, that is, their static state. Missile interceptions are well designed to precisely trigger missiles of the other party without their own losses. However, a technical problem facing Country A is that these missiles only know how to go up. Specifically, the linear rise here refers to the monotonic increase of the three-dimensional coordinates of XYZ. For all missiles in country B, the numbers are 1 to n. The objects that an intercept missile can strike can be expressed in a strictly monotonous ascending XYZ sequence. For example: missile position of country B: (0, 0, 0) (1, 1, 0) (1, 1, 1), (2, 2, 2) a legal strike sequence is: {1, 3, 4} an invalid strike sequence is {1, 2, 4}. The leaders of country A handed you a list of missile positions, I also asked you two simplest questions (pretend to be the easiest): 1. how many missiles in country B can be destroyed by an intercepted missile? 2. How many intercepted missiles can be used at least to destroy all missiles in country B? Whether it's for personal honor or for national convenience, but more for rice bowl, you should solve this problem well! The number of missiles in country B is given by an integer N in the first line of input. In the next n rows, each line contains three non-negative integers Xi, Yi, and Zi, which give a missile position. You can assume that any two missiles will not appear in the same position. The first line of output outputs an integer p, indicating the number of missiles that can be destroyed as many as a missile is intercepted. The second line outputs an integer Q, indicating at least the number of intercepted missiles. Sample input4
0 0 0
1 1 0
1 1 1
2 2 2

Sample output3
2
Hint

All coordinates are integers of [0, 10 ^ 6 ].
N <31 for 30% of data
N <50%
N <100%

Source

The first noier national competition by ghy

Question:

If the array is too small, you can blow wa to me... Oh...

First, I thought about N ^ 2 at the beginning. If I can play J after I, then even the edge (I, j)

This figure is obviously a dag. You can find the longest chain.

Then I thought about how to find out n ^ 2 DP after sorting by one dimension?

It seems like this, because the question requires every dimension to be strictly monotonous, so the same sequence of one dimension does not affect. If not, it is the longest chain...

The reason why DP is not allowed in the original order is that there is no recursive order, so we sort by one dimension. (What can I do with memory ?)

In the second question, we can find a minimum path overwrite on the Dag above. The Hungarian algorithm is OK.

Code:

  1 #include<cstdio>  2   3 #include<cstdlib>  4   5 #include<cmath>  6   7 #include<cstring>  8   9 #include<algorithm> 10  11 #include<iostream> 12  13 #include<vector> 14  15 #include<map> 16  17 #include<set> 18  19 #include<queue> 20  21 #include<string> 22  23 #define inf 1000000000 24  25 #define maxn 1005 26  27 #define maxm 500+100 28  29 #define eps 1e-10 30  31 #define ll long long 32  33 #define pa pair<int,int> 34  35 #define for0(i,n) for(int i=0;i<=(n);i++) 36  37 #define for1(i,n) for(int i=1;i<=(n);i++) 38  39 #define for2(i,x,y) for(int i=(x);i<=(y);i++) 40  41 #define for3(i,x,y) for(int i=(x);i>=(y);i--) 42  43 #define mod 1000000007 44  45 using namespace std; 46  47 inline int read() 48  49 { 50  51     int x=0,f=1;char ch=getchar(); 52  53     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} 54  55     while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();} 56  57     return x*f; 58  59 } 60 struct rec{int x,y,z;}a[maxn]; 61 struct edge{int go,next;}e[maxn*maxn]; 62 int p[2*maxn],n,m,tot,head[2*maxn],f[2*maxn]; 63 bool v[2*maxn]; 64 inline void insert(int x,int y) 65 { 66     e[++tot].go=y;e[tot].next=head[x];head[x]=tot; 67 } 68 inline bool find(int x) 69 { 70     for(int i=head[x],y;i;i=e[i].next) 71     { 72         if(v[y=e[i].go])continue; 73         v[y]=1; 74         if(p[y]==0||find(p[y])) 75         { 76             p[y]=x; 77             return 1; 78         } 79     } 80     return 0; 81 } 82 inline bool cmp(rec a,rec b) 83 { 84     return a.x<b.x; 85 } 86  87 int main() 88  89 { 90  91     freopen("input.txt","r",stdin); 92  93     freopen("output.txt","w",stdout); 94  95     n=read(); 96     for1(i,n)a[i].x=read(),a[i].y=read(),a[i].z=read(); 97     sort(a+1,a+n+1,cmp); 98     for1(i,n)f[i]=1; 99     for2(i,2,n)100      for1(j,i-1)101       if(a[j].x<a[i].x&&a[j].y<a[i].y&&a[j].z<a[i].z)102       {103           insert(j,i+n);104           f[i]=max(f[i],f[j]+1);105       }106     int ans=0;107     for1(i,n)if(f[i]>ans)ans=f[i];108     printf("%d\n",ans);109     ans=0;110     for1(i,n)111     {112         memset(v,0,sizeof(v));113         if(find(i))ans++;114     }115     printf("%d\n",n-ans);116 117     return 0;118 119 }
View code

 

Bzoj2044: 3D Missile interception

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.