当前位置:网站首页>Digital informatization (enumerate assumptions first, and then see whether the conditions are met) (1089 werewolf kill - simple version)
Digital informatization (enumerate assumptions first, and then see whether the conditions are met) (1089 werewolf kill - simple version)
2022-07-25 19:44:00 【Madness makes freedom】
question 1 The police caught him a,b,c,d Four suspected thieves , Only one of them was a thief .
In Interrogation ,a say : I'm not a thief ;b say :c It's a thief ;c say : The thief must be d;d say :c Wronged people .
It is now known that 3 People tell the truth , One person lies , Ask who the thief is ;
* \ anaysis: Number the thief , Enumerate all people trying , Meet the conditions is a thief .
/** \ question 1 The police caught him a,b,c,d Four suspected thieves , Only one of them was a thief .
In Interrogation ,a say : I'm not a thief ;b say :c It's a thief ;c say : The thief must be d;d say :c Wronged people .
* It is now known that 3 People tell the truth , One person lies , Ask who the thief is ;
* \ anaysis: Number the thief , Enumerate all people trying , Meet the conditions is a thief .
* \param
* \return
*
*/
/**< */
/**
#include <iostream>
using namespace std;
int main()
{
int thief='a';
for(thief='a';thief<='d';++thief)
if(((thief!='a')+(thief=='c')+(thief=='d')+(thief!='d'))==3)
printf("%c is thief\n",thief);
return 0;
}
*//** \ question 2:3 A teacher predicted a math contest , Their predictions are as follows :
A said :a Won the first place ,b Got the third place ;
B said :c Won the first place ,d Got the fourth place ;
C said :d Got the second place ,a Got the third place .
The results of the competition show that , They are only half right , And there is no parallel ranking , Output the ranking of students
*
* \ anaysis : Yes abcd Go ahead separately 1234 enumeration , It can be realized by triple loop , final d use d=10-a-b-c;
/** \ question 2:3 A teacher predicted a math contest , Their predictions are as follows :
A said :a Won the first place ,b Got the third place ;
B said :c Won the first place ,d Got the fourth place ;
C said :d Got the second place ,a Got the third place .
The results of the competition show that , They are only half right , And there is no parallel ranking , Output the ranking of students
*
* \ anaysis : Yes abcd Go ahead separately 1234 enumeration , It can be realized by triple loop , final d use d=10-a-b-c;
* \
* \return
*
*/
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int a,b,c,d;
for(a=1;a<5;++a)
for(b=1;b<5;++b)
if(b!=a)
for(c=1;c<5;++c)
if(c!=a&&c!=b)
{
d=10-a-b-c;
if(((a==1)+(b==3)==1)&&((c==1)+(d==4)==1)&&((d==2)+(a==3)==1))
printf("a yes %dth\nb yes %dth\nc yes %dth\nd yes %dth\n",a,b,c,d);
}
return 0;
}
problem 3:
PAT( Class B )2022 Summer exam
7-4 What day of the week is today
fraction 20
author Chen Yue
Company Zhejiang University
Han Meimei and Li Lei are arguing. What day of week is it today , Their dialogue is as follows :
Han Meimei : Today is Friday .
Li lei : incorrect ! Today is Saturday .
Han Meimei : But yesterday was Wednesday .
Li lei : impossible ! Yesterday was Thursday .
Han Meimei : Tomorrow is Tuesday .
Li lei : Funny ? Tomorrow is Monday .
Their mother told you , Each bear child only said one word right , Please judge , What day of week is today ?
Input format :
The input contains 2 That's ok , Each line gives a statement of a bear child , The format is as follows :
yesterday today Tomorrow,
The date here is 0 To 6 The integer of , Corresponding to Sunday to Saturday .
Output format :
First, output the first line “ today ” What day is it , It is required to output its English name ( The comparison table is given after the example ). Input to ensure that each bear child is only right in one sentence ,“ today ” The answer exists and is unique .
And then 2 Print out the day on which each bear child answers correctly —— yes yesterday It outputs yesterday, Or is it today To export today, Or is it Tomorrow, To export tomorrow.
sample input :
3 5 2
4 6 1
sample output :
Friday
today
yesterday
Be careful : The English name of the date is as follows
Sunday :0 - Sunday
Monday :1 - Monday
Tuesday :2 - Tuesday
Wednesday :3 - Wednesday
Thursday :4 - Thursday
Friday :5 - Friday
Saturday :6 - Saturday
Code length limit
16 KB
The time limit
400 ms
Memory limit
64 MB
A total of three codes are written : The first code I don't want to write for a lifetime .
coding first: Judge the number of days the second bear child tells the truth , It's really hard to judge , It can be said to be exhausted , The second program is easy to write , This can be directly ignored , Belong to is to give the fight out .
/**
Judge the number of days the second bear child tells the truth , It's really hard to judge , It can be said to be exhausted ,
The second program is easy to write
*/
/**
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
int ch[2][3];
for(int i=0;i<2;++i)
for(int j=0;j<3;++j)
scanf("%d",&ch[i][j]);
int index=0;
for(int i=-1;i<2;++i)
{
int yes=ch[0][i+1];
if((((yes-ch[0][0])%7==i+1)+((yes-ch[0][1])%7==i)+((yes-ch[0][2])%7==i-1))==1
&&(((yes-ch[1][0])%7==i+1)+((yes-ch[1][1])%7==i)+((yes-ch[1][2])%7==i-1)==1))
index=i+1;
}
map<int,string> mp={
{0,"Sunday"},{1,"Monday"},{2,"Tuesday"},{3,"Wednesday"},
{4,"Thursday"},{5,"Friday"},{6,"Saturday"}};
int day=ch[0][index];
if(index==0)
cout << mp[(day+1)%7] << endl;
else if(index==1)
cout << mp[day] << endl;
else cout << mp[(day-1)%7] << endl;
map<int,string> str{
{0,"yesterday"},{1,"today"},{2,"tomorrow"}};
for(int i=0;i<3;++i)
if(i==index)
{
cout << str[i] << endl;
}
for(int i=0;i<3;++i)
{
if(index<=i) // According to the truth of the first bear child , Introduce the truth that the second bear child said
{
//if The statement can only be (5,0),(6,0)(6,1) To enter ;
// because (index-i)%7 It can only be equal to 5,6,0((day-ch[1][i])%7 It can't be equal to 0), therefore 0 Can be ruled out
if(day>ch[1][i] && (day-ch[1][i])%7==(index-i)%7)// If the first bear child told the truth yesterday and Friday
cout << str[i] << endl; // Or Saturday to judge the day when the second child is telling the truth
else if((day <= ch[1][i]) && day-ch[1][i]==index-i)
cout << str[i] << endl;
}
else if(index>i && ((day-ch[1][i])%7==index-i))
cout << str[i] << endl;
}
return 0;
}
*/coding second : Because the title said that each bear child only said one sentence , We can find the subscript of the truth spoken by the second bear child in the same way as the first bear child speaks the truth
/**
To write : Because the title said that each bear child only said one sentence , We can say by looking for the first bear child
The same way to find out the subscript of the truth that the second bear child said
*/
/**
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
int ch[2][3];
for(int i=0;i<2;++i)
for(int j=0;j<3;++j)
scanf("%d",&ch[i][j]);
int index=0;
for(int i=-1;i<2;++i)
{
int yes=ch[0][i+1];
if((((yes-ch[0][0])%7==i+1)+((yes-ch[0][1])%7==i)+((yes-ch[0][2])%7==i-1))==1
&&(((yes-ch[1][0])%7==i+1)+((yes-ch[1][1])%7==i)+((yes-ch[1][2])%7==i-1)==1))
index=i+1; // Because the title said that each bear child only said one sentence , You can find out the truth that the first bear child said
} // The subscript
map<int,string> mp={
{0,"Sunday"},{1,"Monday"},{2,"Tuesday"},{3,"Wednesday"},
{4,"Thursday"},{5,"Friday"},{6,"Saturday"}};
int day=ch[0][index];
if(index==0)
cout << mp[(day+1)%7] << endl;
else if(index==1)
cout << mp[day] << endl;
else cout << mp[(day-1)%7] << endl;
map<int,string> str{
{0,"yesterday"},{1,"today"},{2,"tomorrow"}};
for(int i=0;i<3;++i)
if(i==index)
{
cout << str[i] << endl;
}
for(int i=-1;i<2;++i)
{
int yes=ch[1][i+1];
if((((yes-ch[0][0])%7==i+1)+((yes-ch[0][1])%7==i)+((yes-ch[0][2])%7==i-1))==1
&&(((yes-ch[1][0])%7==i+1)+((yes-ch[1][1])%7==i)+((yes-ch[1][2])%7==i-1)==1))
index=i+1; // Because the title said that each bear child only said one sentence , We can say by looking for the first bear child
} // The same way to find out the subscript of the truth that the second bear child said
for(int i=0;i<3;++i)
if(i==index)
{
cout << str[i] << endl;
}
return 0;
}
*/
coding thirt: It suddenly occurred to me that there was another solution , Let's assume today's date is (0~6), Then use the words of two bear children to judge whether it is true ;
/**
It suddenly occurred to me that there was another solution , Let's assume today's date is (0~6), Then use the words of two bear children to judge whether it is true ;
*/
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
map<int,string> date={
{0,"Sunday"},{1,"Monday"},{2,"Tuesday"},{3,"Wednesday"},
{4,"Thursday"},{5,"Friday"},{6,"Saturday"}};
map<int,string> true_word{
{0,"yesterday"},{1,"today"},{2,"tomorrow"}};
int ch[2][3];
for(int i=0;i<2;++i)
for(int j=0;j<3;++j)
scanf("%d",&ch[i][j]);
int today=0;
for(today =0;today<7;++today)
{
if(((((today-ch[0][0])%7==1)+((today-ch[0][1])==0)+((today-ch[0][2])%7==6))==1)&&
(((today-ch[1][0])%7==1)+((today-ch[1][1])==0)+((today-ch[1][2])%7==6))==1)
break;
}
cout << date[today] << endl;
int index=0;
for(int k=0;k<2;++k)
{
for(int i=0;i<3;++i)
if(((today-ch[k][i])%7)==(1-i)%7)
index=i;
cout << true_word[index] << endl;
}
}prlblem 4:
1089 Werewolf killing - Simple version
fraction 20
author CHEN, Yue
Company Zhejiang University
The following text is taken from 《 brainwave · Fun math 》:“ Werewolf killing ” The game is divided into werewolves 、 The two camps of good people . In one game “ Werewolf killing ” In the game ,1 Player No. 1 said :“2 Number one is a werewolf ”,2 Player No. 1 said :“3 Number one is a good man ”,3 Player No. 1 said :“4 Number one is a werewolf ”,4 Player No. 1 said :“5 Number one is a good man ”,5 Player No. 1 said :“4 Number one is a good man ”. Known 5 Of the players 2 Man plays the role of werewolf , Yes 2 People are not telling the truth , There are werewolves lying, but not all werewolves are lying . Which two players play the role of werewolf ?
This question is an upgraded version of this problem : It is known that N Of the players 2 Man plays the role of werewolf , Yes 2 People are not telling the truth , There are werewolves lying, but not all werewolves are lying . Ask you to find out which players are playing the role of werewolves ?
Input format :
Input gives a positive integer in the first line N(5≤N≤100). And then N That's ok , The first i Line gives i What player No. 1 said (1≤i≤N), That is, a player number , Use a plus sign for good people , A minus sign means a werewolf .
Output format :
If there is any solution , Output in ascending order on a line 2 The number of a werewolf , Separated by spaces , There must be no extra space at the beginning and end of the line . If the solution is not unique , Then output the minimum sequence solution —— That is, for two sequences A=a[1],...,a[M] and B=b[1],...,b[M], If exist 0≤k<M bring a[i]=b[i] (i≤k), And a[k+1]<b[k+1], It's called sequence A Less than sequence B. If there is no solution, the output is No Solution.
sample input 1:
5
-2
+3
-4
+5
+4
sample output 1:
1 4
sample input 2:
6
+6
+3
+1
-5
-2
+4
sample output 2( The solution is not unique ):
1 5
sample input 3:
5
-2
-3
-4
-5
-1
sample output 3:
No Solution
Code length limit
16 KB
The time limit
400 ms
Memory limit
64 MB
coding : This code should be read by Liu Shen :
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> vec(n+1);
for(int i=1;i<=n;++i)
cin >> vec[i];
for(int i=1;i<n;++i) // The first two floors for Cycle through werewolf numbers
{
for(int j=i+1;j<=n;++j)
{
vector<int> goodman(n+1,1),lie; // lie Store the number of the liar
goodman[i]=goodman[j]=-1; // hypothesis i and j It's a werewolf
for(int k=0;k<=n;++k)
{
if(vec[k]*goodman[abs(vec[k])]<0) // If k What the number one said and what he said specify the true identity of the person
lie.push_back(k); // If not, the person told a lie
}
if(lie.size()==2&&goodman[lie[0]]+goodman[lie[1]]==0) // If there are just two liars
{
cout << i << ' ' << j << endl; // And a person is a werewolf , One is a good man , Then I found the answer
return 0;
}
}
}
cout << "No Solution\n" ; // If none of them are found , There is no solution
return 0;
}边栏推荐
- 高效生成接口文档好方法
- Solve the problem that the win10 account has no administrator rights
- 滑雪手机端H5小游戏源码下载
- 从瞳代到“瞳代”再到品牌,暴利的美瞳的变与未变
- Wxss template style and WXS scripting language for wechat applet development
- RepVGG网络中重参化网络结构解读【附代码】
- Bash does not add single quotes to your string
- Bash does not add single quotes to your string
- What is idealism
- 相机内参矩阵K和fov的相互转换
猜你喜欢

滑雪手机端H5小游戏源码下载

Internal network planning and design of Yingcheng hospital

sentinel简单限流和降级demo问题记录

微信小程序开发之网络数据请求

Sccm2012r2 network deployment reinstallation system

Concept of IP address

TFIDF examples and explanations

Add a subtitle of 3D effect to the container

Istio exposes applications to the Internet

Software designer afternoon real topic: 2009-2022
随机推荐
VMware 虚拟机下载、安装和使用教程
Research and application of servo driver in robot
网络数据包多层传输演示
Network data request for wechat applet development
Hongke shares | how to solve blackmail software security vulnerabilities
Skiing mobile H5 game source code download
打印数据库返回的查询数据是null,或者是默认值。与数据库返回的值不相符
ERROR: role “admin“ cannot be dropped because some objects depend on itDETAIL:
An idea of solving div adapting to screen
Gbase 8s UDR memory management_ 01_ mi_ alloc
Binarysearch basic binary search
How to be a self disciplined person?
On interface encryption
Univariate function integration_ Partial integral method
Bash does not add single quotes to your string
JS learning notes 17: DOM query exercise
Detailed explanation of three methods of selenium setting element waiting
Ml programming skills:
Wechat campus maintenance and repair applet graduation design finished product of applet completion work (4) opening report
Scala foundation [set 01]