A:
题目:
思路:
分别看面包和(奶酪+火腿)能弄几层,取它们最少的一个就是能够做的最多的层数
面包:最多可做b+b-1层
(奶酪+火腿):最多可做(c+h)+(c+h)+1)层
code:
#include <bits/stdc++.h>
using namespace std;
void solve() {
int a,b,c;
cin>>a>>b>>c;
cout<<min((2*a-1),(2*(b+c)+1))<<endl;
}
signed main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
B:
题目:
思路:
大于k的始终会被减到 k 之内(小于等于k),当全部小于等于k之后,怪兽才会开始被消灭,这个时候排个序就OK。
code:
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
void solve() {
int n, k;
cin >> n >> k;
pii a[n + 1];
auto cmp = [](pii a, pii b) -> bool {
if (a.first > b.first)return true;
else if (a.first == b.first && a.second < b.second)return true;
return false;
};
for (int i = 1; i <= n; i++) {
a[i].first = read();
a[i].second = i;
if (a[i].first >k){
if(a[i].first%k==0){
a[i].first=k;
}else{
a[i].first%=k;
}
}
}
sort(a + 1, a + n + 1, cmp);
for (int i=1;i<=n;i++){
cout<<a[i].second<<' ';
}
cout << endl;
}
signed main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}