hdu 4956

http://acm.hdu.edu.cn/showproblem.php?pid=4956

首先给出一个范围 [l, r],问能否从中找到一个数证明 Hanamichi’s solution 的解法(对于某个数 X,偶数位的数字之和 -  奇数位的数字之和  = 3  而且 这个 X 满足 X mod 11 = 3 )是错的。也就是在范围里寻找是否存在不能同时满足:①偶数位的数字之和 -  奇数位的数字之和  = 3; ②X mod 11 = 3;

暴力

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include<set>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
bool sum(LL n)
{
    int ans = 0,cnt = 0;
    while(n){
        if(cnt&1)
            ans -= n%10;
        else
            ans += n%10;
        n/=10;
        cnt++;
    }
    //cout<<ans<<endl;
    if(ans == 3)
        return true;
    return false;
}
int main() {
    //cout<<sum(102);
    int _;
    RD(_);
    LL l,r;
    while(_--){
        scanf("%I64d%I64d",&l,&r);
        LL ll = l/11,rr = (r+8)/11,ans;
        ans = 11*ll+3;
        while(ans<l)
            ans+=11;
        while(sum(ans)){
            ans+=11;
            if(ans > r)
                break;
        }
        if(ans>r){
            puts("-1");
        }
        else
            printf("%I64d
",ans);
    }
    return 0;
}


原文地址:https://www.cnblogs.com/zibaohun/p/4046847.html