#include<iostream>
using namespace std;
int num[105];
int ans[105];
void init()
{
int temp=2;
for(int i=0; i<30; i++)
{
num[i]=temp-1;
temp*=2; }
} int main()
{
int t,n;
cin>>t;
init();
while(t--)
{
cin>>n;
if(n==0)
{
cout<<"0 []"<<endl;
continue;;
}
cout<<n<<" [";
int ct=0;
for(int i=29; i>=0; i--)
{
while(n>=num[i])
{
n=n-num[i];
ans[++ct]=i;
if(n==0)
break;
}
} for(int i=ct;i>0; i--)
{
cout<<ans[i]; if(i!=0) cout<<",";
else cout<<"]"<<endl;
} }
}

  注意:while的使用 和++i i++

题意的理解

UVA2639的更多相关文章

随机推荐

  1. Hibernate里save(),saveOrUpdate(),merge(),update()的区别

    save()方法用于将一个临时对象转变为持久化对象,也就是将一个新的业务实体保存到数据库中:update()方法用于将一个游离对象重新转变为持久化对象,也就是更新一个已经存在的业务实体到数据库中:sa ...

  2. asp.net页面关闭的时候如何触发事件?

      <script type="text/javascript"> var pb_strConfirmCloseMessage; var pb_blnCloseWind ...

  3. OllyUni.dll

    OllyUni.dll 周银辉 好像很多人找不到OllyUni.dll ,下载在这里:http://www.phenoelit.org/win/index.html 注:在OllyDBG2.0中用不了 ...

  4. .Net开源微型ORM框架测评

    什么是ORM? 对象关系映射(英语:Object Relation Mapping,简称ORM,或O/RM,或O/R mapping),是一种程序技术,用于实现面向对象编程语言里不同类型系统的数据之间 ...

  5. 【转】error LNK2019: 无法解析的外部符号 "__declspec(dllimport)

    生成DLL文件的字符集是Unicode而生成exe文件的字符集为默认的ASCII. 只要统一字符集即可解决问题: VS2005的c++项目默认字符集是使用 Unicode 字符集,在项目属性-> ...

  6. BeautifulSoup 的用法

    转自:http://cuiqingcai.com/1319.html Beautiful Soup支持Python标准库中的HTML解析器,还支持一些第三方的解析器,如果我们不安装它,则 Python ...

  7. bzoj 2648 KD-tree

    稍微看了一下KD-tree的讲义,大概明白了它的原理,但是实现不出来... 所以无耻的抄了一下黄学长的... #include<iostream> #include<cstdio&g ...

  8. 【Codeforces717G】Underfail Hash + 最大费用最大流

    G. Underfail time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  9. 关于redis的keys命令的性能问题

    KEYS pattern 查找所有符合给定模式 pattern 的 key . KEYS * 匹配数据库中所有 key . KEYS h?llo 匹配 hello , hallo 和 hxllo 等. ...

  10. Bzoj1176 [Balkan2007]Mokia

    Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 2000  Solved: 890 Description 维护一个W*W的矩阵,初始值均为S.每次操作 ...