在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
C. Shockers
time limit per test
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputValentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for each incorrect guess he receives an electric shock too. The show ends when Valentin guesses the selected letter correctly. Valentin can't keep in mind everything, so he could guess the selected letter much later than it can be uniquely determined and get excessive electric shocks. Excessive electric shocks are those which Valentin got after the moment the selected letter can be uniquely determined. You should find out the number of excessive electric shocks. Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of actions Valentin did. The next n lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
All words consist only of lowercase English letters. The total length of all words does not exceed 105. It is guaranteed that last action is a guess about the selected letter. Also, it is guaranteed that Valentin didn't make correct guesses about the selected letter before the last action. Moreover, it's guaranteed that if Valentin got an electric shock after pronouncing some word, then it contains the selected letter; and also if Valentin didn't get an electric shock after pronouncing some word, then it does not contain the selected letter. Output
Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined. Examples
input
5 output
1 input
8 output
2 input
7 output
0 Note
In the first test case after the first action it becomes clear that the selected letter is one of the following: a, b, c. After the second action we can note that the selected letter is not a. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter isc, but Valentin pronounces the word cd and gets an excessive electric shock. In the second test case after the first two electric shocks we understand that the selected letter is e or o. Valentin tries some words consisting of these letters and after the second word it's clear that the selected letter is e, but Valentin makes 3 more actions before he makes a correct hypothesis. In the third example the selected letter can be uniquely determined only when Valentin guesses it, so he didn't get excessive electric shocks. 【题意】: 给出一个n 多余的电击是犯人在敏感词可以唯一确定之后得到的电击。 1.每次他发表一个包含所选字母的单词时,他都会受到电击+1 (!) 【Code】: #include<bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n; char op[10]; char s[N]; bool safe[N],temp[N];//a为安全词集合,b为待定敏感词集合 int main() { int ans = 0; bool konw = false; //判断敏感词确定否 scanf("%d",&n); while(n--){ scanf("%s%s",op,s); if(op[0] == '.'){ //不包含敏感词,排除 for(int i=0;s[i];i++) safe[s[i]]= true; //不包含敏感词,那么这段话每个字符都是是安全词 } if(op[0] == '!'){ //待定敏感词,要看是否在确定后知道,是则电击 memset(temp,false,sizeof(temp)); //先置位为非敏感词,即安全词 for(int i=0; s[i]; i++) temp[s[i]] = true; //!发言出现的字符都标记为敏感待定词 for(int i='a'; i<='z'; i++) if( !temp[i] ) safe[i] = true; //非敏感词,在safe数组标记为安全词 if(konw) ans++;//知道了后则多余被电次数++ } if(op[0] == '?'){ //猜测,若在确定后猜为安全词则电击 if(konw && safe[s[0]]) ans++; else safe[s[0]] = true; //否则为安全词 } int cnt = 0; for(int i='a'; i<='z'; i++) if(!safe[i]) cnt++; //最后确定的敏感词 if(cnt == 1) konw = true; } printf("%d\n", ans); }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论