比赛 20150423 评测结果 AAAAAAAAAAAAAA
题目名称 守卫标志物 最终得分 100
用户昵称 Asm.Def 运行时间 5.332 s
代码语言 C++ 内存使用 5.14 MiB
提交时间 2015-04-23 10:22:04
显示代码纯文本
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <cctype>
  6. #include <algorithm>
  7. #include <cmath>
  8. using namespace std;
  9. //#define USEFREAD
  10. #ifdef USEFREAD
  11. #define InputLen 5000000
  12. char *ptr=(char *)malloc(InputLen);
  13. #define getc() (*(ptr++))
  14. #else
  15. #define getc() (getchar())
  16. #endif
  17. #define SetFile(x) (freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout))
  18. template<class T>inline void getd(T &x){
  19. int ch = getc();bool neg = false;
  20. while(!isdigit(ch) && ch != '-')ch = getc();
  21. if(ch == '-')ch = getc(), neg = true;
  22. x = ch - '0';
  23. while(isdigit(ch = getc()))
  24. x = x * 10 - '0' + ch;
  25. if(neg)x = -x;
  26. }
  27. /***********************************************************************/
  28. typedef long long LL;
  29. struct Cow{
  30. int str, h, w;
  31. }C[22];
  32.  
  33. int N, H, Ans = -1, F[1100000], End;
  34. LL sumw, sumh;
  35. bool vis[1100000];
  36.  
  37. void dfs(int i, LL w, LL h){//状态到了i,当前堆放了w,h
  38. int j, t;
  39. vis[i] = true;
  40. for(j = 0, t = 1;j < N;++j, t <<= 1)if(i & t){
  41. if(!vis[i ^ t])dfs(i ^ t, w - C[j].w, h - C[j].h);
  42. if(F[i ^ t] >= C[j].w)F[i] = max(F[i], min(C[j].str, F[i ^ t] - C[j].w));
  43. }
  44. if(h >= H)Ans = max(Ans, F[i]);
  45. }
  46.  
  47. inline void init(){
  48. getd(N), getd(H);
  49. End = (1 << N) - 1;
  50. int i;
  51. Cow *it = C;
  52. for(i = 0;i < N;++i, ++it){
  53. getd(it->h), getd(it->w), getd(it->str);
  54. sumw += it->w, sumh += it->h;
  55. }
  56. memset(F, -1, sizeof(F));
  57. *F = 0x7fffffff;*vis = true;
  58. }
  59.  
  60. int main(){
  61. #ifdef DEBUG
  62. freopen("test.txt", "r", stdin);
  63. #else
  64. SetFile(guardc);
  65. #endif
  66. #ifdef USEFREAD
  67. fread(ptr,1,InputLen,stdin);
  68. #endif
  69. init();
  70. dfs(End, sumw, sumh);
  71. if(~Ans)printf("%d\n", Ans);
  72. else puts("Mark is too tall");
  73. #ifdef DEBUG
  74. printf("\n%.3lf sec \n", (double)clock() / CLOCKS_PER_SEC);
  75. #endif
  76. return 0;
  77. }