- Educational Codeforces Round 80
- Educational Codeforces Round 36
- Educational Codeforces Round 81
- Educational Codeforces Round 78
- Educational Codeforces Round 54
- Educational Codeforces Round 54
- Educational Codeforces Round 35
- Educational Codeforces Round 69
- Educational Codeforces Round 98
- Educational Codeforces Round 76
C题意: 给a,b 两个数 求 将a的数字换位置 组成的 最大的 小于 b 的数。
题解 思路 1: 将 a的每一位数存在 数组中排序,从大开始从高位开始放数,如果 加上它小于等于b,而且剩下的数 组成的最小值 加上也 小于b 则选择这个数,再选择下面一个数。贪心求得最值,我之前是这种
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int num[10];
ll ten[20];
ll a,b;
void dfs(int c,ll co)
{
if(c<0)
{
cout<<co;
exit(0);
}
else
{
for(int i=9;i>=0;i--)
{
if(num[i]>0&&ten[c]*i+co<=b)
{
num[i]--;
dfs(c-1,co+ten[c]*i);
num[i]++;
}
}
}
}
int main()
{
int cn=0;
cin>>a>>b;
ll x=a;
ten[0]=1;for(int i=1;i<19;i++)ten[i]=ten[i-1]*10;
while(x)
{
num[x%10]++;
x/=10;
cn++;
}
dfs(cn-1,0);
return 0; }
网友评论