zoukankan      html  css  js  c++  java
  • M

    Time Limit : 1 Second      Memory Limit : 65536 KB

    Source : 第十届山东省ACM省赛

    Problem Link : ZOJ 4125

    Author : Houge  Date : 2019-5-19

    题目大意:

      有初始金钱g,每次死亡金钱数都会减少为g/2(向上取整),问死亡k次后金钱还剩多少。

    分析:

      签到题之一。类似抽屉原理,死亡次数大于一个阈值以后便不用再循环遍历,直接输出1即可,这样可大量节省时间。注意还有一个特判。

    代码:

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 int main()
     6 {
     7     int t;
     8     scanf("%d",&t);
     9     while(t--)
    10     {
    11         int n,k,i;
    12         scanf("%d%d",&n,&k);
    13         if(n==0)    //特判
    14         {
    15             printf("0
    ");
    16             continue;
    17         }
    18         if(k>35)    //死亡次数大于35(稍微给大一点也无妨)便不用再循环
    19         {
    20             printf("1
    ");
    21             continue;
    22         }
    23         for(i=0;i<k;i++)
    24         {
    25             if(n%2==0) n/=2;
    26             else n=n/2+1;
    27         }
    28         printf("%d
    ",n);
    29     }
    30     return 0;
    31 }
  • 相关阅读:
    android 如何在手机上 安装两个同样的app
    Ubuntu 16.04 安装Gitlab
    VScode开发C++常用插件
    过滤text字段为空的数据
    ES标签搜索并解决评分排序问题
    3
    2
    1
    9
    Maven3种打包方式
  • 原文地址:https://www.cnblogs.com/CSGOBESTGAMEEVER/p/10891197.html
Copyright © 2011-2022 走看看