Vijos 1106 & noip2003 improve group detective Reasoning

Source: Internet
Author: User

[Original question]

P1106 detective reasoning accepted Tag: [display tag] Description

James recently fell in love with the detective cartoon Conan and became addicted to the reasoning game. So he summoned a group of students to play the reasoning game. The content of the game is like this. Obviously, the students first discuss how one of them acts as a criminal (without knowing it). The task is to find the criminal. Then, you may ask each student one by one, and the respondent may say:

Other words in the testimony are not included in logical reasoning.

Clearly, n of his students have always said false things, while others have always said true.

Now, we need your help to tell him who is the real murderer from his classmates. Remember, there is only one murderer!

Format input format

The input consists of several rows. The first row has two integers: m (1 ≤ m ≤ 20) and N (1 ≤ n ≤ m) and P (1 ≤ p ≤ 100); m is the number of students who participate in the game, n is the number of people who always lie, and P is the total number of testimonies. In the next m row, each row is the name of a clearly-known student (consisting of English letters, without a primary grid, all in uppercase ). There are P rows in the future. Each row starts with the name of a classmate, followed by a colon and a space, followed by a statement, which conforms to the format listed in the previous table. Each line of evidence cannot exceed 250 characters.

There are no consecutive two spaces in the input, and there are no spaces at the beginning and end of each line.

Output Format

If your program can determine who is a criminal, it will output his name; if the program determines that more than one person may be a criminal, it will output cannot determine; if the program determines that someone may be a criminal, then output impossible.

Example 1 input 1 [copy]
3 1 5 mikecharleskatemike: I am guilty. MIKE: Today is Sunday. CHARLES: Mike is guilty. KATE: I am guilty. KATE: How are you ??
Sample output 1 [copy]
Mike
Restrictions

1 s for each test point

Prompt

Is there no space at the end of a sentence ?..

Source

Noip2003 Question 2

[Analysis] It's strange to have too many questions. If there are no questions to adjust, it is really uncomfortable !. Then we rolled the rough to the VJ and got a code farming question. I feel that the idea is concise. After the initial contraction (this is more beautiful), there are only 69 lines. Map can be used for personal names.

Let's talk about the ideas. At the beginning, I am very stupid. I think that C (20, 10) is used to enumerate whether everyone is telling a lie. This time efficiency... Later, we found that, by enumerating criminals and today's day of the week, it is easy to judge whether each person speaks a lie and then check whether the number of people is a given number.

Pay attention to reading. At first, I got stuck in the sample. I thought there was no space behind the colon and it was super troublesome: if I cut out every word in each sentence, the first word would have to be divided into colons ~~ When Wa is handed in, spaces are found in the input format... Isn't it water?

Then, when judging five sentences, I combined two sentences 1, 2, and 3, 4, and 3 to make judgments, saving both code and thinking.

Another thing worth noting is that some people may not tell the truth or tell lies (that is, the irrelevant words). We can count as truth or lie, it is mainly to be closer to the answer.

By the way, the name string must be larger. I remember that the name of the last vertex had a long string, and then I broke it.

[Code]

#include<cstdio>#include<cstring>#include<map>#include<string>using namespace std;map<string,int>Map;char s[105][25][525],name[105][525],ans[105][525],a[25][525];int num[105],f[25],n,m,i,j,k,P,Today,flag,now,lie,Len,cnt,T;char day[8][25]={"","Monday.","Tuesday.","Wednesday.","Thursday.","Friday.","Saturday.","Sunday."};inline int equal(char *s1,char *s2){  int l1=strlen(s1),l2=strlen(s2);if (l1!=l2) return 0;  for (int i=0;i<l1;i++) if (s1[i]!=s2[i]) return 0;return 1;}inline int check_1(int k){  if (!equal(s[k][num[k]],"guilty.")||num[k]<3||num[k]>4) return 2;  if (s[k][1][0]!='I'||s[k][1][1]!='\0'||!equal(s[k][2],"am")) return 2;  if (num[k]==4) if (!equal(s[k][3],"not")) return 2;  if (Map[name[k]]==now) {if (num[k]==3) return 0;return 1;}  if (num[k]==3) return 1;return 0;}inline int check_2(int k){  if (!equal(s[k][num[k]],"guilty.")||num[k]<3||num[k]>4) return 2;  if (!equal(s[k][2],"is")) return 2;  if (num[k]==4) if (!equal(s[k][3],"not")) return 2;  if (Map[s[k][1]]==now) {if (num[k]==3) return 0;return 1;}  if (num[k]==3) return 1;return 0;}inline int check_3(int k){  if (num[k]!=3||!equal(s[k][1],"Today")||!equal(s[k][2],"is")) return 2;  return equal(day[Today],s[k][3])^1;}inline int work(){  now=Map[a[P]];int res=0,another=0;memset(f,0,sizeof(f));  for (int i=1;i<=m;i++)  {    int T1=check_1(i),T2=check_2(i),T3=check_3(i),pre=Map[name[i]];    if (!T1||!T2||!T3) {if (f[pre]==2) return 0;f[pre]=1;}    if (T1&1||T2&1||T3&1) {if (f[pre]==1) return 0;f[pre]=2;}  }  for (int i=1;i<=n;i++)    if (f[i]==2) res++;else if (!f[i]) another++;  return (res<=lie&&res+another>=lie);}inline int OK(char ch){return (ch>='A'&&ch<='Z'||ch>='a'&&ch<='z');}int main(){  scanf("%d%d%d",&n,&lie,&m);  for (i=1;i<=n;i++) scanf("%s",a[i]),Map[a[i]]=i;  for (i=1;i<=m;i++)   {    scanf("%s",name[i]);name[i][strlen(name[i])-1]='\0';    scanf("%s",s[i][num[i]=1]);    while (OK(s[i][num[i]][strlen(s[i][num[i]])-1])) scanf("%s",s[i][++num[i]]);  }  for (P=1;P<=n;P++)  {    flag=0;for (Today=1;Today<=7&&!flag;Today++) flag=work();    if (flag) memcpy(ans[++cnt],a[P],sizeof(a[P]));  }  if (!cnt) printf("Impossible");  else if (cnt==1) printf("%s",ans[cnt]);  else printf("Cannot Determine");  return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.