A:
解题思路:
只有一行一列的时候输出1,多列就输出2
有多行多列的时候,输出4
下面是c++代码:
#include<iostream>
using namespace std;
int main()
{
long long n,m,t;
cin >> t;
while(t != 0){
cin >> n >> m;
if(n > m){
n = n ^ m;
m = n ^ m;
n = n ^ m;
}
if(n < 2){
if(m < 2){
cout << 1 << endl;
}else{
cout << 2 << endl;
}
}else{
cout << 4 << endl;
}
t--;
}
return 0;
}
B:
解题思路:
找规律可得,偶数输出n - 1,奇数输出n - 2
下面是c++代码:
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
if(n % 2 == 0){
cout << n - 1;
}else{
cout << n - 2;
}
return 0;
}
C:
解题思路:
这题只要相邻两个数最大公约数不为1,那么你怎么操作都不能把两数最大公约数变为1,所以直接输出-1,循环结束相邻两数公约数都为1的话,输出0;
下面是c++代码:
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,arr[100000];
cin >> n;
for(int i = 0;i < n;i++){
cin >> arr[i];
}
for(int i = 1;i < n;i++){
if(gcd(arr[i - 1],arr[i]) != 1){
cout << -1 ;
return 0;
}
}
cout << 0;
return 0;
}
D:
解题思路:
在n比x小之前都除2,直到小于等于x时,结束循环,输出sum+1,因为还要进行一次减的操作
下面是c++代码:
#include<iostream>
using namespace std;
int main()
{
int n,x,sum = 0;
cin >> n >> x;
while(1){
if(n <= x){
break;
}
n /= 2;
sum++;
}
cout << sum + 1;
return 0;
}
E:
解题思路:
将给定的字符串放在一个数组中,判断输入的字符串是否在数组中就行
下面是c++代码:
#include<iostream>
using namespace std;
int main()
{
int t,index = 0;
string s;
string arr[35] = {
"algorithm", "bitset", "cctype", "cerrno", "clocale", "cmath", "complex",
"cstdio", "cstdlib", "cstring", "ctime", "deque", "exception", "fstream",
"functional", "limits", "list", "map", "iomanip", "ios", "iosfwd", "iostream",
"istream", "ostream", "queue", "set", "sstream", "stack", "stdexcept", "streambuf",
"string", "utility", "vector", "cwchar", "cwctype"};
cin >> t;
while(t != 0){
index = 0;
cin >> s;
for(int i = 0;i < 35;i++){
if(s == arr[i]){
index = 1;
break;
}
}
if(index == 1){
cout << "Qian" << endl;
}else{
cout << "Kun" << endl;
}
t--;
}
return 0;
}