记录编号 43385 评测结果 AAAAA
题目名称 木棍 最终得分 100
用户昵称 GravatarTruth.Cirno 是否通过 通过
代码语言 C++ 运行时间 0.380 s
提交时间 2012-10-10 08:57:52 内存使用 3.21 MiB
显示代码纯文本
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4.  
  5. int l[5010],w[5010],rec[5010];
  6. bool used[5010];
  7.  
  8. void swap(int& a,int& b)
  9. {
  10. int temp;
  11. temp=a;
  12. a=b;
  13. b=temp;
  14. }
  15.  
  16. int main(void)
  17. {
  18. freopen("wooden.in","r",stdin);
  19. freopen("wooden.out","w",stdout);
  20. int i,j,n,rest,c=0,from,temp,temp2;
  21. cin>>n;
  22. rest=n;
  23. for (i=1;i<=n;i++)
  24. {
  25. cin>>l[i]>>w[i];
  26. l[i]--;
  27. w[i]--;
  28. rec[i]=l[i]*10000+w[i];
  29. }
  30. for (i=1;i<n;i++)
  31. for (j=1;j<=n-i;j++)
  32. if (rec[j]>rec[j+1])
  33. {
  34. swap(l[j],l[j+1]);
  35. swap(w[j],w[j+1]);
  36. swap(rec[j],rec[j+1]);
  37. }
  38. while (rest)
  39. {
  40. c++;
  41. for (i=1;i<=n;i++)
  42. if (!used[i])
  43. {
  44. from=i;
  45. break;
  46. }
  47. used[from]=true;
  48. temp=l[from];
  49. temp2=w[from];
  50. rest--;
  51. for (i=from+1;i<=n;i++)
  52. {
  53. if (used[i])
  54. continue;
  55. if (temp<=l[i]&&temp2<=w[i])
  56. {
  57. used[i]=true;
  58. temp=l[i];
  59. temp2=w[i];
  60. rest--;
  61. }
  62. }
  63. }
  64. cout<<c<<endl;
  65. return(0);
  66. }