[Artificial intelligence] Lab Course assignments 1. Artificial Intelligence
Job1
Multiple choice questions:
1. C
Programming questions:
1.
Code:
# Include <iostream>
# Include <cstdio>
# Include <cmath>
# Include <algorithm>
# Include <climits>
Using namespace std;
Int isPrime (int n ){
Int I, j;
If (n = 2 ){
Return true;
}
Else if (n <2 | n % 2 = 0 ){
Return false;
}
Else {
J = (int) sqrt (n + 1 );
For (I = 3; I <= j; I = I + 2)
If (n % I = 0)
Return false;
}
Return true;
}
Int main (){
Int count = 0;
For (int I = 101; I <200; I ++ ){
If (isPrime (I )){
Cout <I <"";
Count + = 1;
}
}
Cout <endl;
Cout <count <endl;
Return 0;
// 24747380@qq.com
}
Running result:
2.
Jack and Rose are lovers. They play a digital game every day. The rules are as follows:
[1] Jack randomly selects a number x from the range [a, B ].
[2] Rose randomly selects a number x from the range [c, d ].
[3] If (x + y) mod p = m, they will go out to the movies.
[4] Otherwise, study in the library
Given integers a, B, c, d, p, m, they want to know the probability of going out to a movie.
Code:
# Include <iostream>
# Include <cstdio>
# Include <cmath>
# Include <algorithm>
# Include <climits>
Using namespace std;
Int main (){
Int t;
Cin> t;
While (t --){
Int a, B, c, d, p, m;
Int count = 0;
Int res;
Cin> a> B> c> d> p> m;
For (int x = a; x <= B; x ++ ){
For (int y = c; y <= d; y ++ ){
If (x + y) % p = m ){
Count ++;
}
}
}
Res = (B-a + 1) * (d-c + 1 ));
If (count = 0 ){
Cout <0 <"/" <1 <endl;
}
Else {
For (int I = 2; I <= count; I ++)
If (count % I = 0 & res % I = 0 ){
Count/= I;
Res/= I;
I --;
}
Cout <count <"/" <res <endl;
}
}
Return 0;
}
Running result: