poj 2719 Faulty Odometer

题意:

有辆车的里程表坏了,会跳过数字4,比如 3 接下来直接到5,再比如39 - 50  13 -15 239-259 39999-50000(好吧,该换车了)。如果车的里程表显示走了n公里,求实际走了多少。

打标找到了规律前10个少了1, 100少了19, 1000少了19×9+100=271, 10000中少了271*9+1000 = 2439 ............. 规律很明显了吧!!

遇题多思考,像这种题,看到数据量就知道暴力是不可能的,所以就不需要再尝试了,浪费时间,尤其是在正式比赛的时候。

以下是本人的拙代码

#include <stdio.h>

int main()
{
    int n;
    while (scanf("%d", &n) && n)
    {
        int ans = n;
        int x = n/10;
        int dec = 1;
        int mul = 10;
        while (x)
        {
            int mod = x%10;
            if (mod >= 4)
                ans -= (mod-1)*dec + mul;
            else
                ans -= mod*dec;
            dec = dec*9 + mul;
            mul *= 10;
            x /= 10;
        }
        if (n%10 >= 4)
            ans--;
        printf("%d: %d\n", n, ans);
    }
    return 0;
}

poj 2719 Faulty Odometer

时间: 2024-09-30 07:56:56

poj 2719 Faulty Odometer的相关文章

Hdu 4278 Faulty Odometer(8进制转10进制)

Faulty Odometer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1664    Accepted Submission(s): 1146 Problem Description You are given a car odometer which displays the miles traveled as an int

sicily 1240. Faulty Odometer

Description You are given a car odometer which displays the miles traveled as an integer. The odometer has a defect, however: it proceeds from the digit 3 to the digit 5, always skipping over the digit 4. This defect shows up in all positions (the on

Sicily 1780. Faulty Odometer Again

Description You are given a car odometer which displays the miles traveled as an integer. The odometer has a defect, however: it proceeds from the digit 1 to the digit 3, from the digit 4 to the digit 6 and from the digit 7 to the digit 9, always ski

HDU ACM 4278 Faulty Odometer 进制映射

分析:十进制映射到八进制后,如果跳过8到9,实际上只数了7次,如果跳过3到了4-7实际上只数了3-6次.对应关系如下. 0,1,2,3,4,5,6,7,8,9 0,1,2,-,3,4,5,6,-,7 #include<iostream> using namespace std; int main() { int a[10]={0,1,2,0,3,4,5,6,0,7},i; __int64 ans,k; char b[15]; while(gets(b) && b[0]!='0'

HDU4278 Faulty Odometer(进制转化问题)

题目大意:里程表会错过0 1 2 3 4 5 6 7 8 9中的 3 和 8 两个数字 也就是 正常的里程表显示0 1 2 3 4 5 6 7 8 9 坏掉的里程表只会显示 0 1 2 4 5 6 7 9 其实可以看做:0 1 2 3 4 5 6 7  即坏掉的里程表显示的是8进制的数字,只需先将显示的数字换成8进制数,在把8进制数字换位10进制数字就是答案. #include <iostream> #include <map> #include <sstream> #

HDU4278Faulty Odometer

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4278 Faulty Odometer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1154    Accepted Submission(s): 801 P

[GodLove]Wine93 Tarining Round #8

比赛链接: http://vjudge.net/contest/view.action?cid=47644#overview 比赛来源: 2012 ACM/ICPC Asia Regional Tianjin Online 果然我还是很受外界影响啊~~~这场打得好烂~~~ 155 / 175 Problem A HDU 4278 Faulty Odometer (水题, 简单的数位DP) 155 / 345 Problem B HDU 4279 Number  (打表找规律)   86 / 41

编程题目分类(剪辑)

1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. 模拟 12. 算术与代数 13. 组合问题 14. 数论 15. 网格,几何,计算几何 [编程入门] PC 110101, uva 100, The 3n+1 problem, 难度 1 PC 110102, uva 10189, Minesweeper, 难度 1 PC 110103, uva 10137, The T

(转)sicily题目分类

Sicily题目分类 ·         [数据结构/图论] 1310 Right-Heavy Tree   笛卡尔树相关,复杂度O(N)或O(NlogN). ·1426 Phone List         电话号码前缀检索,trie树相关. ·1443 Printer Queue      基本队列操作. ·1149 等价表达式         判断表达式是否等价(递归求解) ·1136 山海经             n长序列里求m次区间询问的最大连续子区间和.线段树/RMQ ·1252