Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

太水了

Posted by KatrineYang at 2016-09-22 09:54:54 on Problem 1362 and last updated at 2016-09-22 09:55:27
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

vector<int> r;

void c(int n){
	if(!n) return;
	int k = 2;
	for(; (1<<k)-1<=n; k++);
	if(n==(1<<k)-2){
		for(int i = 0; i < 2; i++) r.push_back(k-2);
		return;
	}
	r.push_back(k-2);
	c(n-(1<<(k-1))+1);
}

int main() {
	int t;
	scanf("%d", &t);
	for(int I = 0; I < t; I++){
		r.clear();
		int n;
		scanf("%d", &n);
		printf("%d [", n);
		c(n);
		int z = r.size();
		for(int i = z-1; i >= 0; i--){
			printf("%d", r[i]);
			if(i) printf(",");
		}
		printf("]\n");
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator