记录编号 108513 评测结果 AAAAAAAAAAA
题目名称 [USACO Feb08] 晚餐队列安排 最终得分 100
用户昵称 GravatarJSX 是否通过 通过
代码语言 C++ 运行时间 0.010 s
提交时间 2014-07-04 20:51:19 内存使用 0.52 MiB
显示代码纯文本
  1. #include<cstdio>
  2. #include<cstring>
  3. using namespace std;
  4.  
  5. int nHigh[30001]={0};
  6. int nDate[30001]={0};
  7. int N=0;
  8.  
  9. int main()
  10. {
  11. freopen("diningb.in","r",stdin);
  12. freopen("diningb.out","w",stdout);
  13. scanf("%d",&N);
  14. for(int i=1;i<=N;++i)
  15. {
  16. scanf("%d",&nHigh[i]);
  17. }
  18. //printf("%d\n",nHigh[11]);
  19. int head=0,tail=0,mid=0,nLen=0;
  20. /*for(int i=1;i<=N;++i)
  21. {
  22. head=1;
  23. tail=nLen;
  24. while(head<=tail)
  25. {
  26. mid=(head+tail)/2;
  27. if(nHigh[i]<=nDate[mid])
  28. {
  29. head=mid+1;
  30. }
  31. else
  32. {
  33. tail=mid-1;
  34. }
  35. }
  36. if(head>nLen)
  37. {
  38. nLen=head;
  39. printf("i=%d\n",i);
  40. }
  41. nDate[head]=nHigh[i];
  42. }
  43. printf("%d\n",nDate[12]);*/
  44. int s1,s2;
  45. s1=1000000000;
  46. nLen=0;
  47. memset(nDate,0,sizeof(nDate));
  48. for(int i=1;i<=N;++i)
  49. {
  50. head=1;
  51. tail=nLen;
  52. while(head<=tail)
  53. {
  54. mid=(head+tail)/2;
  55. if(nHigh[i]>=nDate[mid])
  56. {
  57. head=mid+1;
  58. }
  59. else
  60. {
  61. tail=mid-1;
  62. }
  63. }
  64. if(head>nLen)
  65. {
  66. nLen=head;
  67. }
  68. nDate[head]=nHigh[i];
  69. }
  70. // printf("%d\n",nLen);
  71. s2=N-nLen;
  72. if(s1>s2) printf("%d",s2);
  73. else printf("%d",s1);
  74. return 0;
  75. }