- 问答
蓝桥杯答案
- 2025-3-31 19:59:46 @
A. 在小小的日历里面数呀数呀数
xfxcy 的专属日期问题模板,公主请抄。
#include <bits/stdc++.h>
using namespace std;
#define ls u << 1
#define rs u << 1 | 1
#define LL long long
#define int long long
#define PII pair <int, int>
#define fi first
#define se second
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define i128 __int128
#define pcnt(x) __builtin_popcount(x)
#define mem(a,goal) memset(a, (goal), sizeof(a))
#define rep(x,start,end) for(int x = (start) - ((start) > (end)); x != (end) - ((start) > (end)); ((start) < (end) ? x ++ : x --))
#define aLL(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
const int INF = 998244353;
const int mod = 1e9 + 7;
const int N = 100010;
int a[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int b[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool check(int x)
{
if(x % 4 == 0 && x % 100 != 0 || x % 400 == 0) return true;
return false;
}
void solve()
{
//2116
//32872
int res = 0;
for(int i = 2025; i < 2116; ++ i)
{
if(check(i))//判断闰年用 b 数组多一天
{
for(int j = 1; j <= 12; ++ j)
{
for(int k = 1; k <= b[j]; ++ k)
{
int num = i * 10000;
num += j * 100;
num += k;
if(num > 20250329) res ++;
}
}
}
else
{
for(int j = 1; j <= 12; ++ j)
{
for(int k = 1; k <= a[j]; ++ k)
{
int num = i * 10000;
num += j * 100;
num += k;
if(num > 20250329) res ++;
}
}
}
}
cout << res + 1 << '\n';//加上一月一日
}
signed main()
{
int t = 1;
while (t --) solve();
return 0;
}
B. 好数
纯暴力
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int n, res;
int check(int x)
{
int cnt = 1;//cnt % 2 == 0 or 1 判断当前位置是奇数位置还是偶数位置
while(x)
{
if(cnt % 2 != x % 10 % 2) return 0;
x /= 10;
cnt ++;
}
return 1;
}
int main()
{
cin >> n;
for(int i = 1; i <= n; ++ i) if(check(i)) res ++;
cout << res << '\n';
return 0;
}
C. R 格式
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int n;
string s;
string cal(string & s, int n)
{
string res = "";
reverse(s.begin(), s.end());
int t = 0;
for(int i = 0; i < s.size(); ++ i)
{
if(s[i] != '.')
{
t += (s[i] - '0') * n;
res += to_string(t % 10);
t /= 10;
}
else res += '.';
}
while(t)
{
res += to_string(t % 10);
t /= 10;
}
reverse(res.begin(), res.end());
return res;
}
int main()
{
cin >> n >> s;
for(int i = 0; i < n; ++ i) s = cal(s, 2);
int pos = s.find('.');
vector<int> res;
if(s[pos + 1] >= '5')//四舍五入
{
int num = 1;
for(int i = pos - 1; i >= 0; -- i)
{
num = (s[i] - '0' + num);
res.push_back(num % 10);
num /= 10;
}
if(num) res.push_back(num % 10);
for(int j = res.size() - 1; j >= 0; -- j) cout << res[j];
}
else
{
for(int j = 0; j < s.size(); ++ j)
{
if(s[j] != '.')
{
cout << s[j];
}
else break;
}
return 0;
}
return 0;
}
D. 冶炼金属
设答案为 , 因为能炼出 个但炼不出 个所以有 且 即
最小值 ,最大值
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int n;
scanf("%d", &n);
int minn = 1, maxx = 1e9;
while (n -- )
{
int a, b;
scanf("%d%d", &a, &b);
minn = max(minn, a / (b + 1) + 1);
maxx = min(maxx, a / b);
}
printf("%d %d\n", minn, maxx);
return 0;
}
0 条评论
目前还没有评论...