UCF Local Programming Contest 2018

比赛链接

C题 解题思路:


给予长度为n的数组,数值为 1- n ,可以将数组的数移动到最前或最后的位置,求最后数组从小到大排序时操作的最小次数。

我们发现规律,其中不需要移动的就是连续的上升子序列,所以我们求出最长的连续上升子序列 res, 然后输出 n - res 即可。

代码:
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 100010;

int n;
int dp[N];

int main()
{
    cin >> n ;
    int res = 0;
    for (int i = 1, x; i <= n; i++){
        scanf("%d",&x);
        dp[x] = dp[x -1] + 1;
        res = max(dp[x],res);
    }

    cout << n - res << endl;

    return 0;
}



D题 解题思路:


这题比较迷,只要是根据第一个公式得出式子,X * Y= 10 ^ z , 因此可以得出 X 是 2,5的倍数的乘积。

再由 X * W = N, 那么我们算 有多少个 2 和 5 因子的组合就OK。


代码:
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

typedef long long ll;

ll ans[100010];

ll mod_exp(ll a,ll b){
    ll res = 1;
    ll exp = a;
    while(b){
        if (b & 1) res = res * exp;
        exp = exp * exp;
        b>>=1;
    }
    return res;
}

int main(){
    ll n;
    scanf("%lld",&n);
    int a = 0, b = 0;
    while(n % 2 == 0 && n != 0){
        a ++;
        n /= 2;
    }
    while(n % 5 == 0 && n != 0){
        b ++;
        n /= 5;
    }
    int m = 0;
    for (int i = 0; i <= a; i ++){
        ll x = mod_exp(2,i);
        for (int j = 0; j <= b; j ++){
            ll y = mod_exp(5,j);
            ans[m++] = x * y;
        }
    }
    sort(ans, ans + m);
    printf("%d\n", m);
    for (int i = 0; i < m; i++){
        printf("%lld\n",ans[i]);
    }
    return 0;
}




H题 解题思路:



一开始想麻烦了,以为是循环的那种,然后结果是暴力。
从0循环到999就OK,判断下取最小值(0 的时候一开始没看见)


代码:
#include <map>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 100010;

bool a[10];
int b[10000];

int t, m;

bool check(int x){
    if (x == 0 && !a[0]) return false;
    int k = m;
    while(x){
        int l = x % 10;
        if (!a[l]) return false;
        x /= 10;
    }
    return true;
}

int main()
{
    int n;
    memset(a,true, sizeof a);
    scanf("%d",&n);
    for (int i = 0, x; i < n; i++){
        scanf("%d",&x);
        a[x] = false;
    }
    scanf("%d",&m);
    int res = 1000;
    for (int i = 1; i <= 999; i ++){
        if (check(i)){
            res = min(res,abs(m - i));
        }
    }
    printf("%d",res);
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值