CF2044C

我自己想到的ac代码
include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int m,a,b,c;
cin>>m>>a>>b>>c;
if(a>=m&&b>=m)
{
cout<<2m<<endl;
}
if(a<m&&b<m)
{
if(c>2m-a-b)
{
cout<<2m<<endl;
}
else{
cout<<a+b+c<<endl;
}
}
if(a>=m&&b<m)
{
if(c>=m-b)
{
cout<<2m<<endl;
}
else{
cout<<m+b+c<<endl;
}
}
if(b>=m&&a<m)
{
if(c>=m-a)
{
cout<<2*m<<endl;
}
else{
cout<<m+a+c<<endl;
}
}
}
}
虽然太过于复杂了一点,但是能写出来就很开心了。
ai教的ac代码
include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int m,a,b,c;
cin>>m>>a>>b>>c;
int used=min(a,m)+min(b,m);
int left=2*m-used;
cout<<used+min(c,left)<<endl;
}
}
思路1.先固定分配,再填剩余。
2.首先我们能固定的一定是a,b的位置。所以固定好a,b后看情况将剩下的c填入。

浙公网安备 33010602011771号