uva729 - The Hamming Distance Problem(Hamming距离问题)
2013-02-15 14:24
411 查看
题意比较简单,简单的让我有点害怕自己犯想当然的毛病
给三个数据 t-测试数据组数, n-字符串的长度, h-字符串中‘1’的个数。(其余的一定是‘0’)
(我用的是STL中的库函数next_permutation())
代码如下:
#include <cstdio>
#include <algorithm>
using namespace std;
int main ()
{
int t, n, h;
char p[20];
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&h);
p
=0;
for(int i = n-1; i >=0; i--)
if(n-i<=h)p[i] = '1';
else p[i] = '0';
do
{
printf("%s\n",p);
}
while(next_permutation(p,p+n));
if(t)puts("");
}
return 0;
}
给三个数据 t-测试数据组数, n-字符串的长度, h-字符串中‘1’的个数。(其余的一定是‘0’)
(我用的是STL中的库函数next_permutation())
代码如下:
#include <cstdio>
#include <algorithm>
using namespace std;
int main ()
{
int t, n, h;
char p[20];
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&h);
p
=0;
for(int i = n-1; i >=0; i--)
if(n-i<=h)p[i] = '1';
else p[i] = '0';
do
{
printf("%s\n",p);
}
while(next_permutation(p,p+n));
if(t)puts("");
}
return 0;
}
相关文章推荐
- UVa 729 - The Hamming Distance Problem
- uva 729 The Hamming Distance Problem
- UVa 729 - The Hamming Distance Problem
- UVa 729 The Hamming Distance Problem
- UVa 729 - The Hamming Distance Problem
- UVA 729 - The Hamming Distance Problem
- UVa-729-The Hamming Distance Problem
- uva - 729 - The Hamming Distance Problem
- UVa-729-The Hamming Distance Problem
- uva 729 - The Hamming Distance Problem(全排列)
- uva729 The Hamming Distance Problem
- uva 729 The Hamming Distance Problem
- UVA 729 The Hamming Distance Problem
- UVA 729 - The Hamming Distance Problem
- UVA 729 The Hamming Distance Problem
- UVa 729 The Hamming Distance Problem (全排列输出&小细节)
- UVA - 729 The Hamming Distance Problem
- UVa 729 - The Hamming Distance Problem
- UVA 729 - The Hamming Distance Problem
- UVA - 729 The Hamming Distance Problem