第十四届蓝桥杯三月真题刷题训练——第 8 天（3.11）

Cauchy 2023-03-11 20:24:06
``````int n, m;

void solve() {
n = qmi(2, 20), m = qmi(2, 19);
n -= 1;
int a = gcd(n, m);
n /= a;
m /= a;
cout << n << "/" << m << endl;
}``````
``````#include <iostream>
using namespace std;

int months[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool check(int y, int m, int d) //判断是否是合法日期
{
if (d <= 0 || m <= 0 || m >= 13) return false;
if (m != 2)
{
if (d > months[m]) return false;
}
else
{
int days = months[2] + (y % 4 == 0 && y % 100 != 0 || y % 400 == 0);
if (d > days) return false;
}

return true;
}

int flip(int x)
{
int res = 0;
while (x)
{
res = res * 10 + x % 10;
x /= 10;
}
return res;
}

bool st1, st2;
int ans1, ans2;

int main()
{
int n;
cin >> n;

for (int i = n + 1; i <= 989991231; i++)
{
int year = i / 10000, month = i % 10000 / 100, day = i % 100;
if (check(year, month, day))
{
if (i % 10000 == flip(year) && !st1)
st1 = true, ans1 = i;

if (i % 10000 == flip(year) && (month / 10 == day / 10) && (month % 10 == day % 10) && !st2)
st2 = true, ans2 = i;
}

if (st1 && st2) break;
}

printf("%d\n%d\n", ans1, ans2);
return 0;
}``````
``````int n, m;

int dp[N][N];
vII csm[N][N];

struct node {
int x, y;
};

bool check(int x, int y) {
return x >= 1 && x <= n && y >= 1 && y <= n;
}

void bfs() {
memset(dp, 0x3f, sizeof dp);
queue<node> q;
q.push({n, n});
dp[n][n] = 0;
int walk[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};
while (q.size()) {
auto t = q.front(); q.pop();
int x = t.x;
int y = t.y;
for (int i = 0; i < 4; i++) {
int dx = x + walk[i][0];
int dy = y + walk[i][1];
if (check(dx, dy)) {
if (dp[dx][dy] > dp[x][y] + 1) {
q.push({dx, dy});
dp[dx][dy] = dp[x][y] + 1;
}
}
}
for (auto c: csm[x][y]) {
int dx = c.fi, dy = c.se;
if (dp[dx][dy] > dp[x][y] + 1) {
q.push({dx, dy});
dp[dx][dy] = dp[x][y] + 1;
}
}
}
}

void solve() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b, c, d; cin >> a >> b >> c >> d;
csm[a][b].pb({c, d});
csm[c][d].pb({a, b});
}
bfs();
int res = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
res += dp[i][j];

printf("%.2lf\n", res * 1.0 / (n * n));
}``````
``````#include <iostream>
using namespace std;
long long f[30000000];
long long n,m,p,sum;
int main()
{
cin>>n>>m>>p;
f[1]=1;
sum=1;
for(int i=2;i<=n;i++){
f[i]=f[i-1]+f[i-2];
sum+=f[i];
}
if(m>n){
for(int i=n+1;i<=m;i++){
f[i]=f[i-1]+f[i-2];
}
}
cout<<sum%f[m]%p;
return 0;
}``````

...全文
4 回复 打赏 收藏 举报

4.3w+

2023-03-11 20:24

刷题！