记录编号 |
97953 |
评测结果 |
AAAAAAAAAA |
题目名称 |
导弹拦截 |
最终得分 |
100 |
用户昵称 |
cstdio |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.062 s |
提交时间 |
2014-04-21 11:46:50 |
内存使用 |
0.36 MiB |
显示代码纯文本
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- #include<cstring>
- #include<cmath>
- #include<vector>
- using namespace std;
- const int SIZEN=1010;
- class POINT{
- public:
- int x,y,z;
- };
- bool inc(POINT a,POINT b){
- return a.x<b.x&&a.y<b.y&&a.z<b.z;
- }
- bool noninc(POINT a,POINT b){
- return a.x>=b.x&&a.y>=b.y&&a.z>=b.z;
- }
- bool comp(POINT a,POINT b){
- if(a.x<b.x) return true;
- if(a.x>b.x) return false;
- if(a.y<b.y) return true;
- if(a.y>b.y) return false;
- return a.z<b.z;
- }
- int N;
- POINT P[SIZEN];
- int LISlen(bool (*cmp)(POINT,POINT)){
- //cmp(前,后)一直true的最长序列
- int f[SIZEN]={0};
- int ans=0;
- for(int i=1;i<=N;i++){
- f[i]=0;
- for(int j=1;j<i;j++){
- if(cmp(P[j],P[i])){
- //cout<<j<<" "<<i<<endl;
- f[i]=max(f[i],f[j]);
- }
- }
- f[i]++;
- //cout<<i<<" "<<f[i]<<endl;
- ans=max(ans,f[i]);
- }
- return ans;
- }
- int match[SIZEN*2]={0};
- bool visit[SIZEN*2]={0};
- vector<int> c[SIZEN*2];
- bool findpath(int x){
- for(int i=0;i<c[x].size();i++){
- int u=c[x][i];
- if(!visit[u]){
- visit[u]=true;
- if(match[u]==-1||findpath(match[u])){
- match[u]=x;
- match[x]=u;
- return true;
- }
- }
- }
- return false;
- }
- int COVnum(void){
- int ans=0;
- memset(match,-1,sizeof(match));
- for(int i=1;i<=N;i++){
- memset(visit,0,sizeof(visit));
- if(findpath(i)) ans++;
- }
- return N-ans;
- }
- void makegraph(void){
- for(int i=1;i<=N;i++){
- for(int j=1;j<=N;j++){
- if(inc(P[i],P[j])){
- c[i].push_back(j+N);
- c[j+N].push_back(i);
- }
- }
- }
- }
- void work(void){
- sort(P+1,P+1+N,comp);
- printf("%d\n",LISlen(inc));
- makegraph();
- printf("%d\n",COVnum());
- }
- void read(void){
- scanf("%d",&N);
- for(int i=1;i<=N;i++){
- scanf("%d%d%d",&P[i].x,&P[i].y,&P[i].z);
- //cout<<P[i].x<<" "<<P[i].y<<" "<<P[i].z<<endl;
- }
- }
- int main(){
- freopen("bomba.in","r",stdin);
- freopen("bomba.out","w",stdout);
- read();
- work();
- return 0;
- }
-