A 水题: 判断7种情况有没就行了
代码语言:javascript复制#include<bits/stdc .h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int a[3];
cin>>a[0]>>a[1]>>a[2];
sort(a,a 3);
int ans=0;
if(a[2]) ans ,a[2]--;
if(a[1]) ans ,a[1]--;
if(a[0]) ans ,a[0]--;
if(a[2]&&a[1]) ans ,a[2]--,a[1]--;
if(a[2]&&a[0]) ans ,a[2]--,a[0]--;
if(a[1]&&a[0]) ans ,a[1]--,a[0]--;
if(a[2]&&a[1]&&a[0]) ans ,a[2]--,a[1]--,a[0]--;
cout<<ans<<endl;
}
return 0;
}
B 思维
代码语言:javascript复制#include <bits/stdc .h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n,x,y;
cin>>n>>x>>y;
int ans=x y;
if(ans<=n) cout<<1<<" ";
else cout<<min(ans-n 1,n)<<" ";
cout<<min(ans-1,n)<<endl;
}
return 0;
}
C 暴力枚举每个点为最大值 往两边去更新
代码语言:javascript复制#include <bits/stdc .h>
#define maxn 1005
#define f(i, x, y) for (ll i = x; i <= y; i )
using namespace std;
typedef long long ll;
ll a[maxn];
ll flag;
int main(){
ll n;
ll pos, ans = -1;
cin>>n;
f(i, 1, n) cin >> a[i];
f(i, 1, n){
ll x = a[i], mid = a[i];
for(ll j = i - 1; j >= 1; j--) {
x = min(a[j], mid);
mid = min(a[j], mid);
}
mid = a[i];
f(j, i 1, n){
x = min(a[j], mid);
mid = min(a[j], mid);
}
if (x > ans){
ans = x;
pos = i;
}
}
flag = a[pos];
for(ll i = pos - 1; i >= 1; i--) {
a[i] = min(flag, a[i]);
flag = min(flag, a[i]);
}
flag = a[pos];
f(i, pos 1, n){
a[i] = min(flag, a[i]);
flag = min(flag, a[i]);
}
for(int i=1;i<n;i ) cout << a[i] << " ";
cout<<a[n]<<endl;
return 0;
}
D 数状DP
未解决