码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 4956 Poor Hanamichi

时间:2014-08-17 22:49:22      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   os   io   for   ar   代码   

HDU 4956 Poor Hanamichi

题目链接

思路:直接从l往上找判断即可

代码:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

typedef long long ll;

int t;
ll l, r;

bool judge(ll num) {
    ll flag = 1;
    ll ans = 0;
    while (num) {
	ans += num % 10 * flag;
	flag *= -1;
	num /= 10;
    }
    return (ans == 3);
}

ll solve() {
    ll i = l;
    for (; i <= r; i++)
	if (i % 11 == 3)
	    break;
    for (; i <= r; i += 11) {
	if (!judge(i)) return i;
    }
    return -1;
}

int main() {
    scanf("%d", &t);
    while (t--) {
	scanf("%I64d%I64d", &l, &r);
	printf("%I64d\n", solve());
    }
    return 0;
}


HDU 4956 Poor Hanamichi,布布扣,bubuko.com

HDU 4956 Poor Hanamichi

标签:style   http   color   os   io   for   ar   代码   

原文地址:http://blog.csdn.net/accelerator_/article/details/38645193

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!