Article Directory
-
- Programming question link
- Test Question A: Sum of Squares (violence) (Answer: 2658417853, pay attention to open longlong)
- Question B: Evaluation of a sequence of numbers (violence) (Answer: 4659, pay attention to the data is too large in advance mod)
- Test question C: Maximum rainfall (structure) (thinking question, find the median of the median, Mongolian 25, answer 34, fuck)
- Test question D: Labyrinth (BFS) (direction vector priority, read the file `freopen("maze.txt","r",stdin)`), just record the predecessor node to find the path, remember to set the boundary! This search (You still have to write more questions)
- Test question E: RSA decryption (number theory) (decompose prime factors, expand Euclidean algorithm, fast exponentiation, fast addition, no)
Programming question link
Test Question A: Sum of Squares (violence) (Answer: 2658417853, pay attention to open longlong)
#include <iostream>
using namespace std;
bool check(int x)
{
while(x){
int t = x % 10;
if(t == 2 || t == 0 || t==1 || t == 9) return true;
x /= 10;
}
return false;
}
int main()
{
long long res = 0;
for(int i =1;i<=2019;i++)
{
if(check(i)) res += i * i;
}
cout << res << endl;
return 0;
}
Question B: Evaluation of a sequence of numbers (violence) (Answer: 4659, pay attention to the data is too large in advance mod)
#include <iostream>
using namespace std;
int main()
{
long long a = 1,b = 1,c = 1;
int mod = 10000;
int i = 20190323; // 这里少1
while(i -- )
{
long long t = (a + b + c) % mod;
a = b;
b = c;
c = t;
}
cout << a << endl;
return 0;
}
Test question C: Maximum rainfall (structure) (thinking question, find the median of the median, Mongolian 25, answer 34, fuck)
Test Question D: Labyrinth (BFS) (Direction vector priority, read files freopen("maze.txt","r",stdin)
, find the path only need to record the predecessor node, remember to set the boundary! This kind of search questions still need to write more)
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 55;
typedef pair<int,int> PII;
char g[55][55];
PII pre[N][N];
bool st[N][N];
vector<char> res;
int n = 30, m =50;
int dx[4] = {
1,0,0,-1}, dy[4] ={
0,-1,1,0};
void bfs(int sx,int sy)
{
queue<PII> q;
q.push({
sx,sy});
st[sx][sy] = true;
while(q.size())
{
PII t = q.front();
q.pop();
for(int i = 0;i < 4;i ++ )
{
int x = t.first + dx[i], y = t.second + dy[i];
if(x >= 0 && x < n && y >= 0 && y < m && !st[x][y] && g[x][y] != '1') // 障碍物没考虑到
{
st[x][y] = true;
q.push({
x,y});
pre[x][y] = t;
}
}
}
}
int main()
{
freopen("maze.txt","r",stdin);
for(int i=0;i<30;i++) cin >> g[i];
bfs(29,49);
pre[29][49].first = -1; // 设置边界
int x = 0,y = 0;
while(pre[x][y].first != -1)
{
int new_x = pre[x][y].first, new_y = pre[x][y].second;
char op;
if(new_x - x == 1) op = 'D';
else if(x - new_x == 1) op = 'U';
else if(new_y - y == 1) op = 'R';
else op = 'L';
res.push_back(op);
x = new_x, y = new_y;
}
// 答案:(比对)
//DDDDRRURRRRRRDRRRRDDDLDDRDDDDDDDDDDDDRDDRRRURRUURRDDDDRDRRRRRRDRRURRDDDRRRRUURUUUUUUULULLUUUURRRRUULLLUUUULLUUULUURRURRURURRRDDRRRRRDDRRDDLLLDDRRDDRDDLDDDLLDDLLLDLDDDLDDRRRRRRRRRDDDDDDRR
//DDDDRRURRRRRRDRRRRDDDLDDRDDDDDDDDDDDDRDDRRRURRUURRDDDDRDRRRRRRDRRURRDDDRRRRUURUUUUUUULULLUUUURRRRUULLLUUUULLUUULUURRURRURURRRDDRRRRRDDRRDDLLLDDRRDDRDDLDDDLLDDLLLDLDDDLDDRRRRRRRRRDDDDDDRR
for(auto c : res) cout <<c;
return 0;
}