T1 B3835 [GESP202303 一级] 每月天数
这题要判断平年与闰年。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, y;
bool run(ll x){
if (x % 400 == 0){
return 1;
}
if (x % 100 == 0){
return 0;
}
if (x % 4 == 0){
return 1;
}
return 0;
}
int main(){
cin >> n >> y;
if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12){
cout << 31;
return 0;
}
else if (y == 4 || y == 6 || y == 9 || y == 11){
cout << 30;
return 0;
}
else{
if (run(n)){
cout << 29;
}
else{
cout << 28;
}
return 0;
}
}
T3 B2107 图像旋转
题目就是要将一个n行m列的k图像顺时针旋转90度,然后输出
#include<bits/stdc++.h>
using namespace std;
int n, m, a[105][105];
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
cin >> a[i][j];
}
}
for (int i = 1; i <= m; i++){
for (int j = n; j >= 1; j--){
cout << a[j][i] << " ";
}
cout << "\n";
}
}
T4 P2240 【深基12.例1】部分背包问题
这道题需要求金币的最大价值。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
double t, sum;
struct mm{
double m, v;
double jz;
}a[105];
bool cmp(mm x, mm y){
return x.jz > y.jz;
}
int main(){
cin >> n >> t;
for (int i = 1; i <= n; i++){
cin >> a[i].m >> a[i].v;
a[i].jz = a[i].v / a[i].m;
}
sort(a + 1, a + n + 1, cmp);
for (int i = 1; i <= n; i++){
if (t >= a[i].m){
sum += a[i].v;
t -= a[i].m;
}
else{
sum += a[i].jz * t;
break;
}
if (t == 0) break;
}
printf("%.2lf", sum);
}
P5638 【CSGRound2】光骓者的荣耀
这道题需要我们求它最短的时间。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, k;
ll a[1000005], sum[1000005];
int main(){
cin >> n >> k;
if (k >= n - 1){
cout << 0;
return 0;
}
for (int i = 1; i <= n; i++){
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
}
long long ans = sum[k];
for (int i = 1; i <= n - k; i++){
ans = max(ans, sum[i + k - 1] - sum[i - 1]);
}
cout << sum[n - 1] - ans;
}