题目描述
A想玩个游戏,游戏规则是,有n个人,编号从1-n,一字排开,站在奇数位置的人淘汰,剩下的人再一字排开,站在奇数位置的人淘汰,以此重复几次,最后只剩最后一个人,问最后一个人的编号是多少?
输入
输入一个正整数n(≤n≤1e100);
输出
输出一个整数,代表最后剩余的编号。
样例输入 样例输出

首先注意到数据范围特别大,需要用字符串读入

每次淘汰完一轮后剩下的第一个数总是2的倍数,有这个规律,利用大数乘法和大数除法解决

 1 #include<stdio.h>
2 #include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
#define N 1010
char str[N];
int arr[N];
int num[N];
int main()
{
int i;
while(scanf("%s",str)!=EOF)
{
int len=strlen(str);
for(i=;i<len;i++)
arr[i]=str[i]-'';
int m=,flag=;
num[]=;
while((arr[len-]!=)||(flag!=))//循环只剩下一个人时结束
{
for(int i=;i<len;i++)
{
if(arr[i]==) continue;
if(arr[i]%==)
{
arr[i]=arr[i]/;
}
else
{
if(i==len-)
arr[i]=arr[i]/;
else
{
arr[i]=arr[i]/;
arr[i+]+=;
}
}
}
for(int i=; i<=; i++)//完全套用大数阶乘的代码
{
for(int j=; j<=m; j++)
num[j]=num[j]*i;
for(int k=; k<=m; k++)
{
num[k]+=num[k-]/;
num[k-]=num[k-]%;//注意和上一个的顺序
}
while(num[m]>)
{
num[m+]=num[m]/;
num[m]%=;
m++;
}
}
flag=;
for(int i=;i<len-;i++)
{
if(arr[i]!=)
flag=;
}
}
for(int i=m; i>=; i--)
printf("%d",num[i]);
printf("\n");
}
return ;
}

2082 : Only choose one的更多相关文章

  1. Mybatis的choose when otherwise

    <select id="getCount" resultType="int"> select count(1) from <choose> ...

  2. mybatis:choose when otherwise标签

    choose标签是按顺序判断其内部when标签中的test条件是否成立,如果有一个成立,则 choose 结束. 当 choose 中所有 when 的条件都不满则时,则执行 otherwise 中的 ...

  3. 理解 OpenStack + Ceph (9): Ceph 的size/min_size/choose/chooseleaf/scrubbing/repair 等概念

    本系列文章会深入研究 Ceph 以及 Ceph 和 OpenStack 的集成: (1)安装和部署 (2)Ceph RBD 接口和工具 (3)Ceph 物理和逻辑结构 (4)Ceph 的基础数据结构 ...

  4. UVA - 10375 Choose and divide[唯一分解定理]

    UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  5. jstl catch if choose标签

    catch标签: catch标签用来处理异常 属性: * var :用来出现异常保存到的变量. 代码: <c:catch var="e"> <% int i = ...

  6. uva10375 Choose and Divide(唯一分解定理)

    uva10375 Choose and Divide(唯一分解定理) 题意: 已知C(m,n)=m! / (n!*(m-n!)),输入整数p,q,r,s(p>=q,r>=s,p,q,r,s ...

  7. 升级到macos sierra xcode8 requires additional components to support runing and debugging choose Install to add required components

    升级到macos sierra xcode8 报提示:requires additional components to support runing and debugging choose Ins ...

  8. FZU Problem 2082 过路费 树链剖分

    Problem 2082 过路费    Problem Description 有n座城市,由n-1条路相连通,使得任意两座城市之间可达.每条路有过路费,要交过路费才能通过.每条路的过路费经常会更新, ...

  9. Choose Concurrency-Friendly Data Structures

    What is a high-performance data structure? To answer that question, we're used to applying normal co ...

随机推荐

  1. react球形文字旋转标签

    /* * 球形文字旋转标签模块 * */ import React, {Component, PropTypes} from "react"; import ReactDOM fr ...

  2. echarts 自适应方法 x和y x2和y2

    grid:{ x:65, y:20, x2:30, y2:30},

  3. DOM4j 修改和删除

    XML文件 <?xml version="1.0" encoding="UTF-8"?> <contactList> <conta ...

  4. c/c++面试题一

    1.找错 void test1() { char string[10]; char *str1="0123456789"; strcpy(string,str1); } 试题一字符 ...

  5. Linux特殊符号

    第1章 回顾昨天 1.1 linux如何让一个服务/脚本开机自启动? chkconfig /etc/rc.local 1.2 被chkconfig管理 需要什么条件 1.2.1 必须放在/etc/in ...

  6. 算法面试题(python)——如何找出数组中出现一次的数

    题目描述: 一个数组里,除了三个数是唯一出现的,其余的数都出现了偶数次,找出这三个数中任意一个.比如数组序列为[1,2,4,5,6,4,2],只有1.5.6这三个数字是唯一出现的,数字2.4均出现了偶 ...

  7. linux修改主机名+免密认证+关闭防火墙

    在很多软件安装的时候都有这些需求,因此在这里一起讲一下 修改主机名 简单的使用 hostnamectl 命令就好了 hostnamectl set-hostname NAME 免密认证 准备工作,修改 ...

  8. python 使用selenium模块实现自动搜索百度百科词条(模拟人工搜索)

    目标:模拟人工搜索百度百科词条,爬取相关信息,自动删除上一个关键词,输入新关键词,继续搜索,直到循环结束. 代码: from selenium import webdriver from seleni ...

  9. getString与optString的区别

    JSONObject.getString("key"):当对象中没有key属性的时候,会抛出No value for "key"的异常: public Stri ...

  10. Android四大组件之Service --- 服务的生命周期

    一旦在项目的任何位置调用了Context的startService() 方法,相应的服务就会启动起来,并回调onStartCommand() 方法.如果这个服务之前还没有创建过,onCreate() ...