记录编号 275586 评测结果 AAAAAAAAAAAAAAA
题目名称 逻辑岛 最终得分 100
用户昵称 Gravatarfmj 是否通过 通过
代码语言 C++ 运行时间 0.004 s
提交时间 2016-07-02 16:56:04 内存使用 0.31 MiB
显示代码纯文本
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. using namespace std;
  6. const int maxn = 50 + 10;
  7. class kanato{//Kanato-chan――.//
  8. public:
  9. int sp, re, st;//speaker, reference, status.
  10. bool fa;//false(is not ...).
  11. }sen[maxn];//sentence.
  12. bool night = false;
  13. int sta[maxn], is[maxn], n;
  14. inline int f(bool flag){//false==1貌似会不被判断为真...orz Update: 废话. 懒得重打就这么凑合着看吧.
  15. if(flag)return 1;
  16. return 0;
  17. }
  18. inline bool check(){
  19. bool flag = false;//这句话是否成立.
  20. for(int i=1;i<=n;i++){//逐个检验每句话关于时间与身份的信息.
  21. if(sen[i].re==-1){//关于时间.
  22. if(sen[i].st==f(night))flag = true;
  23. else flag = false;
  24. }
  25. else if(sen[i].st<3){//关于身份.
  26. if(sen[i].st==sta[sen[i].re])flag = true;
  27. else flag = false;
  28. }
  29. else if((sta[sen[i].re]==1)||(sta[sen[i].re]==2)&&night)flag = true;//魔鬼或者是晚上的人.
  30. else flag = false;
  31. //对于说这句话的家伙.
  32. if(sen[i].fa)flag = !flag;//"Is not ...".
  33. if((sta[sen[i].sp])==1||(sta[sen[i].sp]==2&&night))flag = !flag;
  34. if(flag==false)//如果这句话不成立.
  35. return false; //那就无解咯.
  36. }
  37. return true;//找到了一个可行解.
  38. }
  39. inline bool impos(bool a){
  40. for(int i=1;i<=5;i++)if(!is[i])return true;
  41. if(!a)return true;
  42. return false;
  43. }
  44.  
  45. #define is_cha(x) ((x <= 'z' and x >= 'a') or (x <= 'Z' and x >= 'A'))
  46. #define is_sym(x) ( x == '.' or x == ':' or x == ' ')
  47. #define is_ch(x) (is_sym(x) or is_cha(x))
  48.  
  49. string get_line() {
  50. char tmp = getchar();
  51. string ans;
  52. ans.clear();
  53. while(!is_ch(tmp)) tmp = getchar();
  54. while( is_ch(tmp)) {
  55. ans = ans + tmp;
  56. tmp = getchar();
  57. }
  58. return ans;
  59. }
  60.  
  61. int main(){
  62. freopen("logicisland.in", "r", stdin);
  63. freopen("logicisland.out", "w", stdout);
  64. int kase = 0;
  65. //while(cin>>n){getchar();if(n==0)break;kase++;cout<<"Conversation #"<<kase<<endl;
  66. memset(is, 0, sizeof(is));
  67. memset(sta, 0, sizeof(sta));
  68. memset(sen, 0, sizeof(sen));
  69. night = false;
  70. cin>>n;//getchar();//Read char '/n'.
  71. for(int i=1;i<=n;i++){
  72. string str;
  73. str = get_line();
  74. int name = str[0] - 'A' + 1, ref = -1;//Speaker, Mentioned.
  75. str = str.substr(3, str.length());
  76. if(str[0]=='I'&&str[2]=='a'){//I am.
  77. ref = name;
  78. str = str.substr(5, str.length());//go over.
  79. }
  80. else if(str[2]=='i'&&str[3]=='s'){//X is.
  81. ref = str[0] - 'A' + 1;
  82. str = str.substr(5, str.length());//go over.
  83. }
  84. else {//It is night/day.
  85. ref = -1;//算了用中文注释吧, 没有人被提到的情况ref设为-1.
  86. str = str.substr(6, str.length());//继续往后面找相关信息.
  87. }
  88. sen[i].sp = name;sen[i].re = ref;
  89. if(str[0]=='n'&&str[1]=='o'){sen[i].fa = true;str = str.substr(4, str.length());}//Is not.
  90. else sen[i].fa = false;
  91. //
  92. string tmp = "121213413";tmp = tmp.substr(1, tmp.length());
  93. if(str.compare("divine.")==0)sen[i].st = 0;
  94. else if(str.compare("evil.")==0)sen[i].st = 1;
  95. else if(str.compare("human.")==0)sen[i].st = 2;
  96. else if(str.compare("lying.")==0)sen[i].st = 3;
  97. else if(str.compare("day.")==0)sen[i].st = 0;
  98. else if(str.compare("night.")==0)sen[i].st = 1;
  99. else cout<<"Orz Cstdio"<<endl;//哎嘿.
  100. }
  101. //枚举, 搞大新闻.
  102. int tnight = 0, kount = 0;
  103. for(night=false;kount<=1;night=!night, kount++)
  104. for(sta[1]=0;sta[1]<=2;sta[1]++)
  105. for(sta[2]=0;sta[2]<=2;sta[2]++)
  106. for(sta[3]=0;sta[3]<=2;sta[3]++)
  107. for(sta[4]=0;sta[4]<=2;sta[4]++)
  108. for(sta[5]=0;sta[5]<=2;sta[5]++)
  109. if(check()){
  110. for(int j=1;j<=5;j++)is[j] |= (1<<sta[j]);//拆二进制存储状态. 1, 2, 4.
  111. tnight = tnight | (1<<f(night));
  112. }
  113. if(impos(tnight)){cout<<"This is impossible."<<endl<<endl;return 0;}//continue;}
  114. bool flag = false;//有没有找到的推论.
  115. for(int j=1;j<=5;j++){//先输出身份信息.
  116. string out;//cout<<is[j]<<endl;
  117. if(is[j]==(1<<0))out = "divine.";
  118. else if(is[j]==(1<<1))out = "evil.";
  119. else if(is[j]==(1<<2))out = "human.";
  120. else continue;
  121. flag = true;
  122. printf("%c is ", (char)(j+'A'-1));cout<<out<<endl;
  123. }
  124. if(tnight==(1<<0)){flag = true;cout<<"It is day."<<endl;}
  125. if(tnight==(1<<1)){flag = true;cout<<"It is night."<<endl;}
  126. if(flag==false)cout<<"No facts are deducible."<<endl;
  127. cout<<endl;
  128. return 0;
  129. }