#CS41010. 阅读程序10-数论10
阅读程序10-数论10
阅读程序
注意:切勿用电脑直接运行代码得出答案,请用大脑+笔+纸运行代码答题,否则是在浪费你的时间。
第10节:数论
第10题【NOIP】2011
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
const int SIZE=10000;
const int LENGTH=10;
int n,m,a[SIZE][LENGTH];
int h(int u,int v){
int ans,i;
ans=0;
for(i=1;i<=n;i++)
12 if( a[u][i]!=a[v][i])
ans++;
return ans;
}
int main(){
int sum,i,j;
cin>>n;
memset(a,0,sizeof(a));
m=1;
21 while(1)
{
i=1;
while( (i<=n) && (a[m][i]==1) )
i++;
if(i>n)
break;
m++;
a[m][i]=1;
for(j=i+1;j<=n;j++)
a[m][j]=a[m-1][j];
}
sum=0;
for(i=1;i<=m;i++)
for(j=1;j<=m;j++)
sum+=h(i,j);
cout<<sum<<endl;
return 0;
}
●判断题
(1)第21行至多执行n次。
{{ select(10-1) }}
- 正确
- 错误
(2)将第12行的!=改成==,结果不影响。
{{ select(10-2) }}
- 正确
- 错误
(3)输入的n为11,不会数组越界。
{{ select(10-3) }}
- 正确
- 错误
(4)该程序可以正常运行。
{{ select(10-4) }}
- 正确
- 错误
●选择题
(5)输入7,输出结果为()。
{{ select(10-5) }}
- 7
- 6
- 57344
- 114514
(6)该算法的时间复杂度为()。
{{ select(10-6) }}
- O(1)
- O(n)
- O()
- O()