HDU 4956 Poor Hanamichi

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

时间: 2024-12-20 22:41:41

HDU 4956 Poor Hanamichi的相关文章

hdu 4956 Poor Hanamichi BestCoder Round #5(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4956 Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7    Accepted Submission(s): 4 Problem Description Hanamichi is taking part in

hdu 4956 Poor Hanamichi 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4956(它放在题库后面的格式有一点点问题啦,所以就把它粘下来,方便读者观看) 题目意思:给出一个范围 [l, r] 你, 问是否能从中找到一个数证明 Hanamichi’s solution 的解法是错的. Hanamichi’s solution 是这样的: 对于某个数 X,从右往左数它的每一位数字(假设第一位是从0开始数).它 偶数位的数字之和 -  奇数位的数字之和  = 3  而且 这个 X

[BestCoder Round #5] hdu 4956 Poor Hanamichi (数学题)

Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 743    Accepted Submission(s): 275 Problem Description Hanamichi is taking part in a programming contest, and he is assigned to so

【HDOJ】4956 Poor Hanamichi

基本数学题一道,看错位数,当成大数减做了,而且还把方向看反了.所求为最接近l的值. 1 #include <cstdio> 2 3 int f(__int64 x) { 4 int i, sum; 5 6 i = sum = 0; 7 while (x) { 8 if (i & 1) 9 sum -= x%10; 10 else 11 sum += x%10; 12 ++i; 13 x/=10; 14 } 15 return sum; 16 } 17 18 int main() { 1

HDU 4952 Poor Mitsui(贪心)

HDU 4957 Poor Mitsui 题目链接 思路:利用相邻交换法去贪心即可,注意容积为0的情况,这是个坑点 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 45; struct SB { int a, b; } sb[N]; bool cmp(SB x, SB y) { return x.b * y.a < x.

HDU 4803 Poor Warehouse Keeper(贪心)

http://acm.hdu.edu.cn/showproblem.php?pid=4803 贪心的策略是,每次尽量加价格,加到能满足条件的最大值,然后加一下数量,这样反复直到到达答案. 然后加到满足条件最大值一步不能模拟,可以推一下公式就能直接算出来了 代码: #include <stdio.h> #include <string.h> const double eps = 1e-9; double x, y; int main() { while (~scanf("%

Poor Hanamichi

Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Hanamichi is taking part in a programming contest, and he is assigned to solve a

hdu 4803 Poor Warehouse Keeper(贪心+数学)

题目链接:hdu 4803 Poor Warehouse Keeper 题目大意:有以个屏幕可以显示两个值,一个是数量x,一个是总价y.有两种操作,一种是加一次总价,变成x,x+y:一种是加一个数量,这要的话总价也会相应加上一个的价钱,变成x+1,y+y/x.总价显示的为取整后的整数,小数部分忽略.给定一个目标x,y,初始状态为1,1,求最少需要多少次可以目标状态,不可以达到的话输出-1. 解题思路:如果是加一次总价的话,单价就在变大:如果是加一次数量的话,单价是不变的.总而言之,单价是只会往上

HDU 4957 Poor Mitsui

题解:记答案为ans,已知,对一个确定的顺序,计算所用的时间长短就是从最后向前计算,计算方法如下: ans+=(p[i].b+ans*p[i].a)/(v-p[i].a) 那么,应该如何调整顺序使得答案最小呢?我们将这个式子拆开得到 ans+=p[i].b/(v-p[i].a)+(ans*p[i].a)/(v-p[i].a) 显然,与之前的ans和p[i].b/v-p[i].a有关,p[i].b/(v-p[i].a)的值越小,产生的ans就越小,那么在下一次计算时,(ans*p[i].a)/(v