codeforces 351A Jeff and Rounding(区间枚举)

题意
给2n个实数。
拿n个出来做floor,剩下的取ceil。
d为操作前后元素的和之差的绝对值,求最小的d。
思路
PS:感觉像这样的
现将所有的元素统一操作一遍,然后从中间选若干个
遇到的题有贪心,dp,枚举。。
快形成一种思路了,应该总结下类似的题。。
设小数部分x[i]
先将所有的数取floor,d = x[i]
然后只要选n个数出来ceil
将floor换成ceil就是加上1 (ceil(a[i]) = floor(a[i])+x+1-x)
但是x = 0.0的数,ceil和floor的结果都是自己
设满足 x = 0.0 的数的个数为m
1)m >= n
枚举区间 [d, d+2n-m]
2)m < n
枚举区间 [d+n-m, d+n]

#include<bits/stdc++.h>

using namespace std;

#define SPEED_UP iostream::sync_with_stdio(false);
#define FIXED_FLOAT cout.setf(ios::fixed, ios::floatfield);
#define rep(i, s, t) for(int (i)=(s);(i)<=(t);++(i))
#define urep(i, s, t) for(int (i)=(s);(i)>=(t);--(i))
#define in_bound(l, r, i) (l)<=(i)&&(i)<(r)
#define pb push_back

typedef long long LL;

const int inf = INT_MAX/2;
const int Maxn = 4005;
const LL Mod = 1000000007;
string s;
LL k, p;

LL opt_pow_n(LL x, unsigned int n)
{
    LL pw = 1;
    while(n > 0){
        if (n&1)
            pw = pw*x%Mod;
        x = x*x%Mod;
        n = n >> 1;
    }
    return pw;
}

LL go(LL n) {
    if (n == 1) return 1;
    LL tmp = go(n/2);
    if (n&1) {
        return ((tmp+opt_pow_n(p, n/2)*tmp%Mod)%Mod+opt_pow_n(p, n-1))%Mod;
    }
    else {
        return (tmp+opt_pow_n(p, n/2)*tmp%Mod)%Mod;
    }
}


LL solve() {
    LL ans = 0, n = s.length();
    p = opt_pow_n(2, n);
    LL base = go(k);
    //cout << "sum of gp: " << base << endl;
    rep(i, 0, n-1)
        if (s[i] == '5' || s[i] == '0') {
            LL a0 = opt_pow_n(2, i);
            ans = (ans+a0*base%Mod)%Mod;
        }
    return ans;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
#endif
    SPEED_UP
    cin >> s >> k;
    cout << solve() << endl;

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值