Codeforces 日常切题
1.A. Elections
题解:在三个数中找出最大的数,然后分别输出这三个数至少要加多少才能大于最大数的值。
AC代码如下:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
inline int gcd(ll a,ll b){if(a%b==0) return b; return gcd(b,a%b);}
int main()
{
int t;
cin>>t;
while(t--)
{
ll a,b,c;
cin>>a>>b>>c;
ll maxn=max(a,max(b,c));
ll a1=maxn-a;
ll b1=maxn-b;
ll c1=maxn-c;
if((a==maxn)+(b==maxn)+(c==maxn)>=2)
{
a1++,b1++,c1++;
}
else
{
if(a!=maxn) a1++;
if(b!=maxn) b1++;
if(c!=maxn) c1++;
}
printf("%lld %lld %lld\n",a1,b1,c1);
}
return 0;
}
2.B. Make it Divisible by 25
题解:查找n至少要修改多少个数值才能被25整除
AC代码如下:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
inline int gcd(ll a,ll b){if(a%b==0) return b; return gcd(b,a%b);}
int main()
{
int t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
vector<int>k;
while(n)
{
k.push_back(n%10);
n=n/10;
}
int i,j,flag=0,sum1=0,sum2=0;
for(i=0;i<k.size()-1;i++)
{
if(flag==0)
{
if(k[i]==5)
flag=1;
else
sum1++;
}
else
{
if(k[i]==2||k[i]==7)
break;
sum1++;
}
}
flag=0;
for(i=0;i<k.size()-1;i++)
{
if(flag==0)
{
if(k[i]==0)
flag=1;
else
sum2++;
}
else
{
if(k[i]==0||k[i]==5)
break;
sum2++;
}
}
cout<<min(sum1,sum2)<<endl;
}
return 0;
}