ACbaodui

牛浩宇  •  1个月前


9456 - 珠算(abacus)

通过次数

94

提交次数

263

时间限制 : 1 秒
内存限制 : 512 MB

算盘是一种手动操作计算辅助工具形式。它起源于中国,是中国古代的一项重要发明。在阿拉伯数字出现前,算盘是世界广为使用的计算工具。

一般的算盘多为木制(或塑料制品),矩形木框内排列一串串等数目的算珠称为档,中有一道横梁把珠分隔为上下两部分,上半部每算珠代表5,下半部每算珠代表1,当需要进行计算或者计数时就把下珠往上拨,把上珠往下拨。每串珠从右至左代表了十进位的个、十、百、千、万位数

求从初始状态拨动珠子到指定数值,需要的最少波动珠数。

                <h4>输入</h4>
                <div class="content-wrapper">
                    <div class="markdown"><p>  输入的第一行包含一个正整数,表示输入的数值的个数。<br />

接下来行,每行一个正整数,表示需要表示的数值大小。

                <h4>输出</h4>
                <div class="content-wrapper">
                    <div class="markdown"><p>输出包含n行,每行仅一个数字,表示每个数值对应需要拨动的珠子数量。</p>

                <h4>样例</h4>
                <div class="content-wrapper">
                    <div class="sample-test">
                        <div class="input">
                            <h4>输入</h4>
                            <pre>2

2 257

                        </div>
                        <div class="output">
                            <h4>输出</h4>
                            <pre>2

6

                        </div>

                                                        <div class="input">
                                <h4>输入</h4>
                                <pre>12

1 9 29 4236 861 864 9945 345 4065 892 627 870

                            </div>
                            <div class="output">
                                <h4>输出</h4>
                                <pre>1

5 7 11 7 10 15 8 7 11 7 7

                            </div>
                        
                                                        <div class="input">
                                <h4>输入</h4>
                                <pre>13

82 4527 6741555 2067750104 255000000 2004000404 125400000 49017271711 896111279424 304555 113722 2387220 247400

                            </div>
                            <div class="output">
                                <h4>输出</h4>
                                <pre>6

10 13 16 4 14 8 24 34 10 12 16 13

                            </div>
                                                </div>
                </div>

                                        <h4>提示</h4>
                    <div class="content-wrapper">
                        <div class="markdown"><p>当需要表示数值2时,需要把最右边的柱子的下珠往上拨2个。</p>

当需要表示数值257时,需要把从右往左数第一根柱子,对应个位,需要拨动3次一次上珠,两次下珠;第二根柱子对应十位,需要拨动1次上珠;第三根柱子对应百位,需要拨动2次下珠,共计拨动6次。

对于所有测试数据有:1≤n≤100,1≤a<10^{18}

                                        <h4>来源</h4>
                    <div class="content-wrapper">
                        <div class="markdown"><p>云南编程挑战赛</p>

                                </div>
            <div class="problem-footer">
                <a class="btn btn-default" href="/p/9455"><span class="glyphicon glyphicon-arrow-left"></span> 上一题</a>
                <a class="btn btn-default" href="/p/9458">下一题 <span class="glyphicon glyphicon-arrow-right"></span></a>                </div>
        </div>
        <div class="problem-right">
            <form id="w0" class="problem-editor" action="/p/9456" method="post">

            <div class="field-solution-language required" style="margin: 0">

All C C++ Java Python3

            <div class="code-input field-solution-source required">

            <div class="problem-footer">
                <button type="submit" class="btn btn-primary">提交</button>                    <div>
                                                <button type="button" class="btn btn-default" data-toggle="modal" data-target="#w1">我的提交</button>
15秒前
                        <span>
                            <a href="/solution/source?id=258646" onclick="return false" data-click="solution_info" data-pjax="0"><strong class="text-success"data-verdict="4" data-submissionid="258646" waiting="false">Accepted</strong></a>                            </span>
                        <span>
                            <a href="/solution/source?id=258646" title="查看源码" onclick="return false" data-click="solution_info" data-pjax="0"><span class="glyphicon glyphicon-edit"></span></a>                            </span>
                                        </div>
            </div>
            </form>            </div>
    </div>
</div>

</div>

© 2019 - 2024王码编程  滇ICP备19007937号-1
如果您有任何问题,请联系我们 YNOIer@163.com
您是本系统的第453753位访问者

Split(['.problem-left', '.problem-right'], {

sizes: [50, 50],

});

    CodeMirror.fromTextArea(document.getElementById("solution-source"),{
        theme: "darcula",
        lineNumbers: true,
        styleActiveLine: true,
        indentUnit: 4,
        autofocus: true,
        matchBrackets: true,
        autoRefresh: true,
        lineWrapping: true, //代码折叠
        foldGutter: true,
        autoCloseBrackets: true
    });

jQuery('#w1').modal({"show":false}); jQuery('#w0').yiiActiveForm([{"id":"solution-language","name":"language","container":".field-solution-language","input":"#solution-language","validate":function (attribute, value, messages, deferred, $form) {yii.validation.number(value, messages, {"pattern":/^\s[+-]?\d+\s/,"message":"语言必须是整数。","skipOnEmpty":1});yii.validation.required(value, messages, {"message":"语言不能为空。"});yii.validation.range(value, messages, {"range":["0","1","2","3"],"not":false,"message":"Please select a language","skipOnEmpty":1});}},{"id":"solution-source","name":"source","container":".field-solution-source","input":"#solution-source","validate":function (attribute, value, messages, deferred, form) {yii.validation.required(value, messages, {"message":"代码不能为空。"});yii.validation.string(value, messages, {"message":"代码必须是一条字符串。","skipOnEmpty":1});}}], []); jQuery('#solution-info').modal({"show":false}); $('[data-click=solution_info]').click(function() {

.ajax({     url: (this).attr('href'),
    type:'post',
    error: function(){alert('error');},
    success:function(html){
        ('#solution-content').html(html);         ('#solution-info').modal('show');
    }   
});

});

function updateVerdictByKey(submission) {

$.get({
    url: "/solution/verdict?id=" + submission.attr('data-submissionid'),
    success: function(data) {
        
        var obj = JSON.parse(data);
        submission.attr("waiting", obj.waiting);
        submission.text(obj.result);
        if (obj.verdict === "4") {
            submission.attr("class", "text-success")
        }
        if (obj.waiting === "true") {
            submission.append('<img src="/images/loading.gif" alt="loading">');
        }
    }
});

} var waitingCount = $("strong[waiting=true]").length;

if (waitingCount > 0) {

console.log("There is waitingCount=" + waitingCount + ", starting submissionsEventCatcher...");
var interval = null;
var waitingQueue = [];
("strong[waiting=true]").each(function(){     waitingQueue.push((this));
});
waitingQueue.reverse();
var testWaitingsDone = function () {
    updateVerdictByKey(waitingQueue[0]);
    var waitingCount = ("strong[waiting=true]").length;     while (waitingCount < waitingQueue.length) {         if (waitingCount < waitingQueue.length) {             waitingQueue.shift();         }         if (waitingQueue.length === 0) {             break;         }         updateVerdictByKey(waitingQueue[0]);         waitingCount = ("strong[waiting=true]").length;
    }
    console.log("There is waitingCount=" + waitingCount + ", starting submissionsEventCatcher...");
    
    if (interval && waitingCount === 0) {
        console.log("Stopping submissionsEventCatcher.");
        clearInterval(interval);
        interval = null;
    }
}
interval = setInterval(testWaitingsDone, 200);

} });


评论:

请先登录,才能进行评论