Problem Description
让你写出一个序列,满足长度是n,里面含有a个«Oh…» b个«Wow!» 。。«Wow!» 代表你加进去的这个数比前面所有数的和都大。«Oh…» 代表你加进去的这个数比前面任何一个数都大。特别注意同时满足«Wow!» 和«Oh…» 优先«Wow!» 。第一个数不理。
**代码:构造等比数列1,2,4,8….这样可以满足加进来这个数比前所有数的和都大。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n, a, b, top, i;
int ans[105];
while(~scanf("%d %d %d", &n, &a, &b))
{
top = 0;
int c = 1;
ans[top++] = c;
//第一个数构造为1
for(i = 2; i <= n; i++)
{
if(b)
//优先«Wow!» 所以先把b处理完,直接让c * 2存入
{
b--;
c= c * 2;
}
else if(a&&i>2)
//如果是«Oh...» 得加条件i>2因为如果第二个数就是c++。那么2>1 这样就满足«Wow!» 。所以得先让序列先变成1,1。
{
a--;
c++;
}
ans[top++]=c;
}
if(a || b) printf("-1\n");
//没有构造成功,输出-1
else
{
for(i = 0; i < top; i++)
{
if(i) printf(" ");
printf("%d", ans[i]);
}
printf("\n");
}
}
return 0;
}