记录编号 97953 评测结果 AAAAAAAAAA
题目名称 导弹拦截 最终得分 100
用户昵称 Gravatarcstdio 是否通过 通过
代码语言 C++ 运行时间 0.062 s
提交时间 2014-04-21 11:46:50 内存使用 0.36 MiB
显示代码纯文本
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. #include<vector>
  7. using namespace std;
  8. const int SIZEN=1010;
  9. class POINT{
  10. public:
  11. int x,y,z;
  12. };
  13. bool inc(POINT a,POINT b){
  14. return a.x<b.x&&a.y<b.y&&a.z<b.z;
  15. }
  16. bool noninc(POINT a,POINT b){
  17. return a.x>=b.x&&a.y>=b.y&&a.z>=b.z;
  18. }
  19. bool comp(POINT a,POINT b){
  20. if(a.x<b.x) return true;
  21. if(a.x>b.x) return false;
  22. if(a.y<b.y) return true;
  23. if(a.y>b.y) return false;
  24. return a.z<b.z;
  25. }
  26. int N;
  27. POINT P[SIZEN];
  28. int LISlen(bool (*cmp)(POINT,POINT)){
  29. //cmp(前,后)一直true的最长序列
  30. int f[SIZEN]={0};
  31. int ans=0;
  32. for(int i=1;i<=N;i++){
  33. f[i]=0;
  34. for(int j=1;j<i;j++){
  35. if(cmp(P[j],P[i])){
  36. //cout<<j<<" "<<i<<endl;
  37. f[i]=max(f[i],f[j]);
  38. }
  39. }
  40. f[i]++;
  41. //cout<<i<<" "<<f[i]<<endl;
  42. ans=max(ans,f[i]);
  43. }
  44. return ans;
  45. }
  46. int match[SIZEN*2]={0};
  47. bool visit[SIZEN*2]={0};
  48. vector<int> c[SIZEN*2];
  49. bool findpath(int x){
  50. for(int i=0;i<c[x].size();i++){
  51. int u=c[x][i];
  52. if(!visit[u]){
  53. visit[u]=true;
  54. if(match[u]==-1||findpath(match[u])){
  55. match[u]=x;
  56. match[x]=u;
  57. return true;
  58. }
  59. }
  60. }
  61. return false;
  62. }
  63. int COVnum(void){
  64. int ans=0;
  65. memset(match,-1,sizeof(match));
  66. for(int i=1;i<=N;i++){
  67. memset(visit,0,sizeof(visit));
  68. if(findpath(i)) ans++;
  69. }
  70. return N-ans;
  71. }
  72. void makegraph(void){
  73. for(int i=1;i<=N;i++){
  74. for(int j=1;j<=N;j++){
  75. if(inc(P[i],P[j])){
  76. c[i].push_back(j+N);
  77. c[j+N].push_back(i);
  78. }
  79. }
  80. }
  81. }
  82. void work(void){
  83. sort(P+1,P+1+N,comp);
  84. printf("%d\n",LISlen(inc));
  85. makegraph();
  86. printf("%d\n",COVnum());
  87. }
  88. void read(void){
  89. scanf("%d",&N);
  90. for(int i=1;i<=N;i++){
  91. scanf("%d%d%d",&P[i].x,&P[i].y,&P[i].z);
  92. //cout<<P[i].x<<" "<<P[i].y<<" "<<P[i].z<<endl;
  93. }
  94. }
  95. int main(){
  96. freopen("bomba.in","r",stdin);
  97. freopen("bomba.out","w",stdout);
  98. read();
  99. work();
  100. return 0;
  101. }
  102.