10940
这道题本来感觉用链表模拟一下应该不超时,但不知为什么就是超时,没办法,只好找规律,
打出1-20的数据一眼就能看出规律来了,一开始我对1没处理WA了,1要单独处理
//============================================================================
// Name : 10940.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <cstdio>
#include <list>
using namespace std;
int d[50];
int n;
int main(){
d[0] = 1;
for(int i = 1;i <= 25;i++){
d[i] = d[i-1]*2;
// printf("%d\n", d[i]);
}
while(scanf("%d", &n)&&n){
if(n == 1){
printf("1\n");
continue;
}
for(int i = 0;i < 25;i++){
if(n <= d[i]){
n-=d[i-1];
break;
}
}
printf("%d\n", 2*n);
}
return 0;
}

浙公网安备 33010602011771号