第一题
代码:
#include<iostream>
using namespace std;
int a[20][5];
int sum = 0;
int main()
{
for(int i=0;i<20;i++)
for (int j = 0; j < 5; j++)
{
cin >> a[i][j];
}
for(int i1=0;i1<20;i1++)
for(int i2=0;i2<20;i2++)
for (int i3 = 0; i3 < 20; i3++)
for (int i4 = 0; i4 < 20; i4++)
for (int i5 = 0; i5 < 20; i5++)
{
if (i1 != i2 && i1 != i3 && i1 != i4 && i1 != i5 && i2 != i3 && i2 != i4 && i2 != i5 &&
i3 != i4 && i3 != i5 && i4 != i5)
{
if (a[i1][0] + a[i2][1] + a[i3][2] + a[i4][3] + a[i5][4] > sum)
sum = a[i1][0] + a[i2][1] + a[i3][2] + a[i4][3] + a[i5][4];
}
}
cout << sum << endl;
system("pause");
return 0;
}
数据:
97 90 0 0 0
92 85 96 0 0
0 0 0 0 93
0 0 0 80 86
89 83 97 0 0
82 86 0 0 0
0 0 0 87 90
0 97 96 0 0
0 0 89 0 0
95 99 0 0 0
0 0 96 97 0
0 0 0 93 98
94 91 0 0 0
0 83 87 0 0
0 0 98 97 98
0 0 0 93 86
98 83 99 98 81
93 87 92 96 98
0 0 0 89 92
0 99 96 95 81
第二题
#include<iostream>
using namespace std;
int main()
{
int chu = 2019;
while (chu!=0)
{
cout << chu / 26 <<" "<<chu % 26 <<endl;
chu = chu / 26;
}
system("pause");
return 0;
}
输出为
17
25
2
则2019转化为二十六进制为 2 25 17 题中对应 BYQ
第三题
#include<iostream>
using namespace std;
long long int a[20190326];
int main()
{
a[0] = 1; a[1] = 1; a[2] = 1;
for (int i = 3; i < 20190324; i++)
{
a[i] = a[i - 1] + a[i - 2] + a[i - 3];
a[i] = a[i] % 10000;
}
cout << a[20190323] << endl;
system("pause");
return 0;
}
结果
4659
第四题
#include<iostream>
using namespace std;
bool bo(int num)
{
int a, b, c, d;
a = num % 10; num /= 10;
b = num % 10; num /= 10;
c = num % 10; num /= 10;
d = num % 10; num /= 10;
if (a == 2 || a == 4 || b == 2 || b == 4 || c == 2 || c == 4 || d == 2 || d == 4)
return false;
return true;
}
int main()
{
int cou = 0;
for(int i=1;i<2019;i++)
for(int j=1;j<2019;j++)
for (int k = 1; k < 2019; k++)
{
if (i + j + k == 2019&&i!=j&&i!=k&&j!=k&&bo(i)&&bo(j)&&bo(k))
{
cou++;
}
}
cout << cou / 6 << endl;
system("pause");
return 0;
}
结果
40785
第五题
/*
01010101001011001001010110010110100100001000101010
00001000100000101010010000100000001001100110100101
01111011010010001000001101001011100011000000010000
01000000001010100011010000101000001010101011001011
00011111000000101000010010100010100000101100000000
11001000110101000010101100011010011010101011110111
00011011010101001001001010000001000101001110000000
10100000101000100110101010111110011000010000111010
00111000001010100001100010000001000101001100001001
11000110100001110010001001010101010101010001101000
00010000100100000101001010101110100010101010000101
11100100101001001000010000010101010100100100010100
00000010000000101011001111010001100000101010100011
10101010011100001000011000010110011110110100001000
10101010100001101010100101000010100000111011101001
10000000101100010000101100101101001011100000000100
10101001000000010100100001000100000100011110101001
00101001010101101001010100011010101101110000110101
11001010000100001100000010100101000001000111000010
00001000110000110101101000000100101001001000011101
10100101000101000000001110110010110101101010100001
00101000010000110101010000100010001001000100010101
10100001000110010001000010101001010101011111010010
00000100101000000110010100101001000001000000000010
11010000001001110111001001000011101001011011101000
00000110100010001000100000001000011101000000110011
10101000101000100010001111100010101001010000001000
10000010100101001010110000000100101010001011101000
00111100001000010000000110111000000001000000001011
10000001100111010111010001000110111010101101111000
*/
#include<iostream>
#include<queue>
using namespace std;
int d[4][2] = { 1,0,0,-1,0,1,-1,0 };//定义四个方向
char d1[4] = { 'D','L','R','U' };//四个方向对应的字符
int sum = 0xfffffff;//初始化路径最大化
struct node
{
char tf;
int x; int y;
int dir;
int cou;
int x1; int y1;
int visi;
};
node map[33][55];
queue<node> way;
bool bo(int x,int y)
{
if (x<0||y<0||x>=30||x>=50||map[x][y].tf=='1'||map[x][y].visi==1)
return false;
return true;
}
void bfs()
{
map[0][0].cou = 0;
map[0][0].dir = -1;
map[0][0].visi = 1;
way.push(map[0][0]);
while (!way.empty())
{
bool boo = false;
for (int i = 0; i < 4; i++)
{
int x = way.front().x+d[i][0]; int y = way.front().y+d[i][1];
if (bo(x,y))
{
//改数据
map[x][y].dir = i;
map[x][y].x1 = way.front().x;
map[x][y].y1 = way.front().y;
map[x][y].visi = 1;
map[x][y].cou = way.front().cou + 1;
way.push(map[x][y]);
}
else
continue;
if (x == 29 && y == 49&&map[x][y].cou<sum)
{
boo = true;
char v[500];
int i = 0;
int X=map[x][y].x; int Y=map[x][y].y;
while (map[X][Y].dir != -1)
{
v[i++]=d1[map[X][Y].dir];
int M = map[X][Y].x1;
int N = map[X][Y].y1;
X = M; Y = N;
}
for (int j = i-1; j >=0; j--)
{
cout << v[j];
}
break;
}
}
if (boo)
break;
way.pop();
}
}
int main()
{
for (int i = 0; i < 30; i++)
for (int j = 0; j < 50; j++)
{
map[i][j].x = i;
map[i][j].y = j;
cin >> map[i][j].tf;
}
bfs();
system("pause");
return 0;
}
这道题要用广度优先搜索 数据太大 深度优先时间太长
结果
DDDDRRURRRRRRDRRRRDDDLDDRDDDDDDDDDDDDRDDRRRURRUURRDDDDRDRRRRRRDRRURRDDDRRRRUURUUUUUUULULLUUUURRRRUULLLUUUULLUUULUURRURRURURRRDDRRRRRDDRRDDLLLDDRRDDRDDLDDDLLDDLLLDLDDDLDDRRRRRRRRRDDDDDDRR
第六题
#include<iostream>
using namespace std;
int n;
int sum;
bool bo(int n)
{
while (n != 0)
{
int yu = n % 10;
n =n/ 10;
if (yu == 2 || yu == 0 || yu == 1 || yu == 9)
return true;
}
return false;
}
int main()
{
cin >> n;
int cou = 0;
while (n)
{
if (bo(n))
{
cout << n << endl;
sum += n;
cou++;
}
n--;
}
cout << sum <<' '<<cou<< endl;
system("pause");
return 0;
}
水题
第七题
#include<iostream>
#include<queue>
using namespace std;
struct node
{
int data;
int xb;
};
node a[100005];
queue<node> no;
int n;
int deep;
int mx;
int ncm(int k)
{
int sum = 1;
for (int i = 0; i < k-1; i++)
{
sum*= 2;
}
return sum;
}
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i].data;
a[i].xb = i + 1;
no.push(a[i]);
}
int k = 1;
while (1)
{
int j = ncm(k);
cout << j << endl;
int sum = 0;
if (j <= n)
{
for (int i = 0; i <j; i++)
{
sum += no.front().data;
no.pop();
}
if (sum >mx)
{
deep = k;
mx = sum;
}
}
else
{
while (!no.empty())
{
sum += no.front().data;
no.pop();
}
if (sum > mx)
deep = k;
break;
}
k++;
}
cout << deep << endl;
system("pause");
return 0;
}
哎 看着简单 还挺麻烦
第八题
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int a[1000];
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
//排序
sort(a, a + n);
//找出最大公差
int mi=0xfffffff;
for (int i = 0; i < n - 1; i++)
{
if (a[i + 1] - a[i] < mi)
mi = a[i + 1] - a[i];
}
cout << (a[n - 1] - a[0]) / mi + 1 << endl;
system("pause");
return 0;
}
先排序 找出最大公差数 然后(最大数—最小数)/最大公差+1
第九题