zoukankan      html  css  js  c++  java
  • sdut 2351 In Danger (找规律)

    题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2351

    题意:xyez, xy表示一个十进制数,z表示xy后面有几个0,这些个人成一个约瑟夫环,隔一个人杀一个人。。

    求哪个位置上的人会幸存,用一般的方法会超时。

    周赛的题,没做出来, 打表以后会找出来规律, 每2^n 都是1会幸存,

    剩下的成1 2 3 1 3 5 7 1 3 5 7 9 11 13 15

    这样的规律。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <algorithm>
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     int i, a, b, len, sum;
    11     int cnt;
    12     char s[100];
    13     while(~scanf("%s", s) && strcmp(s,"00e0")!=0)
    14     {
    15         b = 1;
    16         a = (s[0] - 48)*10 + s[1] - 48;
    17         len = s[3] - 48;
    18         while(len--)
    19         {
    20             b *= 10;
    21         }
    22         a = a*b;
    23         sum = 1;
    24         for(i = 1; i <= 30; i++)
    25         {
    26             if(sum > a)
    27             break;
    28             sum *= 2;
    29         }
    30         sum /= 2;
    31         cnt = 1;
    32         for(i = sum; i < a; i++)
    33         cnt += 2;
    34         printf("%d
    ", cnt);
    35     }
    36     return 0;
    37 }
  • 相关阅读:
    继承作业0920
    类与对象
    类和对象基础题
    类和对象数组
    数组
    字符串
    2.1面向对象
    7.1 Java集合概述
    Java动态代理的两种实现方法
    18.5.2动态代理和AOP
  • 原文地址:https://www.cnblogs.com/bfshm/p/3560875.html
Copyright © 2011-2022 走看看