记录编号 342905 评测结果 AAAAAAAAAA
题目名称 嵌套矩形 最终得分 100
用户昵称 Gravatarsxysxy 是否通过 通过
代码语言 C++ 运行时间 0.063 s
提交时间 2016-11-08 20:15:36 内存使用 4.12 MiB
显示代码纯文本
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <list>
  4. #include <queue>
  5. #include <vector>
  6. #include <algorithm>
  7. using namespace std;
  8. struct rect
  9. {
  10. int w, h;
  11. bool canin(rect &ct)
  12. {
  13. return w<ct.w && h<ct.h;
  14. }
  15. }rs[1111];
  16. int G[1001][1001];
  17. int d[1001];
  18. int n;
  19. int ss, tt;
  20. int calc(int u)
  21. {
  22. if(d[u])return d[u];
  23. d[u] = 1;
  24. for(int i = 1; i <= n; i++)if(G[u][i])
  25. d[u] = max(d[u], calc(i)+1);
  26. return d[u];
  27. }
  28. void dfs(int u)
  29. {
  30. printf("%d ", u);
  31. for(int i = 1; i <= n; i++)
  32. if(G[u][i] && d[u] == d[i]+1)
  33. {
  34. dfs(i);
  35. break;
  36. }
  37. }
  38. int main()
  39. {
  40. freopen("qiantao.in", "r", stdin);
  41. freopen("qiantao.out", "w", stdout);
  42. scanf("%d", &n);
  43. for(int i = 1; i <= n; i++)
  44. {
  45. scanf("%d %d", &rs[i].w, &rs[i].h);
  46. if(rs[i].w > rs[i].h)swap(rs[i].w, rs[i].h);
  47. }
  48. for(int i = 1; i <= n; i++)for(int j = 1; j <= n; j++)if(rs[i].canin(rs[j]))
  49. G[i][j] = 1;
  50. int l = 0;
  51. int s;
  52. for(int i = 1; i <= n; i++)
  53. if(calc(i) > l)
  54. {
  55. l = d[i];
  56. s = i;
  57. }
  58. printf("%d\n", l);
  59. dfs(s);
  60. return 0;
  61. }