2021年蓝桥杯省赛C++B组题解-创新互联
题单传送门
为甘孜州等地区用户提供了全套网页设计制作服务,及甘孜州网站建设行业解决方案。主营业务为网站制作、网站设计、甘孜州网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!卡片#include#include
#include#includeusing namespace std;
int main(){int cnt[15] = {0};
int num = 0;
while(++num){int t = num;
while(t){ cnt[t % 10]++;
if(cnt[t % 10] >2021){ cout<< num - 1<< endl;
return 0;
}
t /= 10;
}
}
return 0;
}
直线#include#include
#include#include#includeusing namespace std;
typedef pairPDD;
int main() {vectorv;
for (int x1 = 0; x1< 20; ++x1)
for (int y1 = 0; y1< 21; ++y1)
for (int x2 = 0; x2< 20; ++x2)
for (int y2 = 0; y2< 21; ++y2) {if (x1 != x2) {double k = 1.0 * (y2 - y1) / (x2 - x1);
double b = y1 - k * x1;
v.push_back({k, b});
}
}
sort(v.begin(), v.end());
int ans = 1;
for (int i = 1; i< v.size(); ++i) {if (v[i].first - v[i - 1].first >1e-8 || v[i].second - v[i - 1].second >1e-8) { ans++;
}
}
cout<< ans + 20<< endl;
return 0;
}
货物摆放#include#include
#include#includeusing namespace std;
typedef long long LL;
int main() {LL n = 2021041820210418;
LL ans = 0;
for (LL i = 1; i<= n / i; ++i) {if (n % i != 0) continue;
LL t = n / i;
for (LL j = i; j<= t / j; ++j) { if (t % j != 0) continue;
LL k = t / j;
if (k< j || i >j) continue;
if (i == j && i == k) ans += 1;
else if (i == j || i == k || j == k) ans += 3;
else ans += 6;
}
}
cout<< ans<< endl;
return 0;
}
路径#include#include
#include#includeusing namespace std;
typedef long long LL;
LL f[3000];
int gcd(int a, int b){return b ? gcd(b, a % b) : a;
}
int main() {memset(f, 0x3f, sizeof f);
f[1] = 0;
for(int i = 2; i<= 2021; ++i){int l = max(1, i - 21);
for(int j = l; j< i; ++j){ f[i] = min(f[i], f[j] + 1ll * (i * j) / gcd(i, j));
}
}
cout<< f[2021]<< endl;
return 0;
}
空间#include#include
#include#includeusing namespace std;
int main() {cout<< 256 * 1024 * 1024 / 4<< endl;
return 0;
}
砝码称重#include#include
#include#includeusing namespace std;
typedef long long LL;
const int N = 110, M = 1e5 + 10;
int dp[N][M], w[N];
int main(){int n;
cin >>n;
int sum = 0;
for(int i = 1; i<= n; ++i){cin >>w[i];
sum += w[i];
}
dp[0][0] = 1;
for(int i = 1; i<= n; ++i){for(int j = 0; j<= sum; ++j){ dp[i][j] = dp[i - 1][abs(j - w[i])] + dp[i - 1][j + w[i]] + dp[i - 1][j];
}
}
int ans = 0;
for(int i = 1; i<= sum; ++i){if (dp[n][i] != 0) { ans++;
}
}
cout<< ans<< endl;
return 0;
}
括号序列#include#include
#include#includeusing namespace std;
typedef long long LL;
const int N = 5e3 + 10, mod = 1e9 + 7;
int f[N][N], n;
string s;
LL get() {memset(f, 0, sizeof(f));
f[0][0] = 1;
for (int i = 1; i<= n; i++) {if (s[i - 1] == '(' ) { for (int j = 1; j<= n; j++)
f[i][j] = f[i - 1][j - 1];
}
else { f[i][0] = (f[i - 1][1] + f[i - 1][0]) % mod;
for (int j = 1; j<= n; j++)
f[i][j] = (f[i - 1][j + 1] + f[i][j - 1]) % mod;
}
}
for (int i = 0; i<= n; i++)
if (f[n][i]) return f[n][i];
return -1;
}
int main(){cin >>s;
n = s.length();
LL x = get();
reverse(s.begin(), s.end());
for (int i = 0; i< n; i++) {if (s[i] == ')') s[i] = '(';
else s[i] = ')';
}
LL y = get();
cout<< (x * y) % mod<< endl;
return 0;
}
时间显示#include#include
#include#includeusing namespace std;
int main(){long long n;
int t;
cin >>t;
for(int i = 1; i<= t; i++)
{cin >>n;
n /= 1000;
n %= 24 * 60 * 60;
printf("%02d:%02d:%02d\n", n / 60 / 60, n / 60 % 60, n % 60);
}
return 0;
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
当前文章:2021年蓝桥杯省赛C++B组题解-创新互联
网页地址:http://azwzsj.com/article/ppcsj.html