| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 48912 人关注过本帖, 10 人收藏
标题:[全民编程]76道高难度C++练习题.含NOI竞赛题.欢迎挑战
只看楼主 加入收藏
travelling
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2007-10-22
收藏
得分:0 
     多谢供,以后有的研究了!
2007-10-31 00:13
poppylx
Rank: 1
等 级:新手上路
帖 子:367
专家分:0
注 册:2004-9-27
收藏
得分:0 

关于第一题 说说自己的算法
首先(E+G+G)%10 = E 这样可以推出 G 为 0 与 5 中的一个。
(D+F+F+个位进位)% 10 = D 可以得出 G = 0, F = 5。
再看看A与X,A+ 千位进位 =X,这里的千位进位必定为1, 得出A+1=X,A与X是两个连续的数。
同时可以看出 B+ 百位进位 >10
再看看C+2D, 由于B与Y的关系所以C+2D必定有进位,如果进位为1,则B=9,Y=0,与前面的的推导冲突。
所以进位肯定为2(不可能为3),则B=9,Y=1。
这样10个数中还剩下2 3 4 6 7 8 六个数。
再看百位上 2D+C +1(十位进位),必须进位2,所以2D+C +1 >= 20,又因为 Z!=0 && Z!=1,所以 2D+C +1 >=22.
=> D与C的平均数必须大于等于7
根据前面的A与X连续, 所以Z必定为2或4. 那么2D+C等于21或者23, 所以C必定为一素数, 所以C = 7.
则2D+7=21 或2D+7=23 => 2D=14 或 2D=16. 所以D=8.
只有最后一个E与6了,所以E=6.
证毕.

这个题似乎没必要写程序.


动于心而静如水
2007-10-31 01:01
jonc
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2007-3-25
收藏
得分:0 

做了最简单的
程序不雅观
大家见笑了

代码:
#include <iostream>
#include<iomanip>
using namespace std;
int main()
{
const int num=19;//选择N
int i,j;
char array[num][num];

for(i=0;i<num;i++)//初始化数组
for(j=0;j<num;j++)
{

if((i==0)||(i==num-1)||(j==0)||(j==num-1))
array[i][j]='T';
else
if((i==1)||(i==num-2)||(j==1)||(j==num-2))
array[i][j]='J';
else
if((i==2)||(i==num-3)||(j==2)||(j==num-3))
array[i][j]='1';
else
if((i==3)||(i==num-4)||(j==3)||(j==num-4))
array[i][j]='2';
else
if((i==4)||(i==num-5)||(j==4)||(j==num-5))
array[i][j]='3';
else
if((i==5)||(i==num-6)||(j==5)||(j==num-6))
array[i][j]='4';
else
if((i==6)||(i==num-7)||(j==6)||(j==num-7))
array[i][j]='5';
else
if((i==7)||(i==num-8)||(j==7)||(j==num-8))
array[i][j]='6';
else
if((i==8)||(i==num-9)||(j==8)||(j==num-9))
array[i][j]='7';
else
if((i==9)||(i==num-10)||(j==9)||(j==num-10))
array[i][j]='8';
else
if((i==10)||(i==num-11)||(j==10)||(j==num-11))
array[i][j]='9';//最多打印到9


}
for(i=0;i<num;i++)//打印
{
for(j=0;j<num;j++)
cout<<setw(1.5)<<array[i][j]<<" ";
cout<<""<<endl;
}


return 0;
}


菜鸟也想高飞
2007-10-31 17:32
jonc
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2007-3-25
收藏
得分:0 

第四题
在N行N列的数阵中, 数K(1〈=K〈=N)在每行和每列中出现且仅
出现一次,这样的数阵叫N阶拉丁方阵。例如下图就是一个五阶拉丁方阵。
编一程序,从键盘输入N值后,打印出所有不同的N阶拉丁方阵,并统计个数。

1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4

#include<iostream>
#include<iomanip>
using namespace std;
void linta(int );
int main()
{
int num;
cout<<"input the num(min is 1):"
<<endl;
cin>>num;//input the number
linta(num);//call the function
return 0;
}
void linta(int num)
{
int i,j,inta=0;
for(i=1;i<=num;i++)//print the lation data
for(j=1;j<=num;j++)
{
if((inta+j)%num==0)
cout<<setw(3)<<num;
else
cout<<setw(3)<<(inta+j)%num;
if(j==num)
{
inta++;
cout<<endl;
}

}

}


菜鸟也想高飞
2007-10-31 22:02
poppylx
Rank: 1
等 级:新手上路
帖 子:367
专家分:0
注 册:2004-9-27
收藏
得分:0 

/*
2. A、B、C、D、E五名学生有可能参加计算机竞赛,根据下列条件判断哪些
人参加了竞赛:

(1)A参加时,B也参加;

(2)B和C只有一个人参加;

(3)C和D或者都参加,或者都不参加;

(4)D和E中至少有一个人参加;

(5)如果E参加,那么A和D也都参加。

*/

/*
分析: 关于条件4与条件5很有意思.
如果D不参加,则E肯定参加.
但如果E参加了,则D肯定参加.
所以可以得出D时肯定参加的.
再根据条件2,3, 可以得到B与C是否参加.
这样只有A与E是不确定的.
使用穷举法, 只要满足条件1与5,便可得到结果.

昨天做了第一题,完全用笔算,今天做第二题时才感觉到昨天误解了出题者的意思.
*/



#include <iostream>
using namespace std;

const int A = 0;
const int B = 1;
const int C = 2;
const int D = 3;
const int E = 4;
const int COUNT = 5;

void PrintResult( bool bArray[], int iCount ); //输出结果


int main()
{
bool bStudent[ COUNT ];

bStudent[D] = true; //条件4与5
bStudent[C] = bStudent[D] ; //条件3
bStudent[b] = !bStudent[C]; //条件2
for( int i = 0; i < 2 ; ++i )
{
bStudent[A] = i;
for( int j = 0; j < 2; ++j )
{
bStudent[E] = j;
if( (bStudent[A] == false || (bStudent[A] == true && bStudent[b] == true)) //条件1
&& ( bStudent[E] == false || (bStudent[E] == true && bStudent[A] == true)) ) //条件5
{
PrintResult( bStudent, COUNT );
}
}
}

cin.get();
return 0;
}

//输出结果
void PrintResult( bool bArray[], int iCount )
{

for( int i = 0; i < iCount; ++i)
{
if( bArray[i] == true )
{
cout << (char)(i+'A') << ": Attend" << endl;
}
else
{
cout << (char)(i+'A') << ": Not attend" << endl;
}
}
}


动于心而静如水
2007-11-01 01:49
jonc
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2007-3-25
收藏
得分:0 

5. 输入一个十进数,将其转换成 N 进制数(0<N<=16)。

#include<iostream>
#include<iomanip>
using namespace std;
void convert(int ,int,int[],int);
int main()
{
int num,make_num,sign=1;
int array[32]={0};//,array[32]={0}
cout<<"input the num and the make_num:";
cin>>num
>>make_num;//input the number
convert(num,make_num,array,32);//call the functnio
cout<<"the "
<<num
<<" convert into "
<<make_num
<<" is : "<<endl;
for(int i=31;i>=0;i--)
{
if(!(array[i]==0&&sign==1))
{
if(array[i]==65)
cout<<"A";
else if(array[i]==66)
cout<<"B";
else if(array[i]==67)
cout<<"C";
else if(array[i]==68)
cout<<"D";
else if(array[i]==69)
cout<<"E";
else if(array[i]==70)
cout<<"F";
else
cout<<array[i];
}
}
return 0;
}
void convert(int num,int make_num,int array[],int size)
{
int Remainder=num,i=0,mold;
while(Remainder!=0)
{
mold=Remainder%make_num;

if(mold==10)
array[i++]='A';
else if(mold==11)
array[i++]='B';
else if(mold==12)
array[i++]='C';
else if(mold==13)
array[i++]='D';
else if(mold==14)
array[i++]='E';
else if(mold==15)
array[i++]='F';
else
array[i++]=mold;


Remainder/=make_num;

}
}


菜鸟也想高飞
2007-11-01 08:46
jonc
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2007-3-25
收藏
得分:0 

9. 四人玩火柴棍游戏,每一次都是三个人赢,一个人输。输的人要按赢者手中的火柴
数进行赔偿,即赢者手中有多少根火柴棍,输者就赔偿多少根。现知道玩过四次后,
每人恰好输过一次, 而且每人手中都正好有16根火柴。问此四人做游戏前手中各有
多少根火柴? 编程解决此问题。
#include<iostream>
#include<iomanip>
using namespace std;
void game(int[],int);
int main()
{
int array[4]={16,16,16,16};//初始化
static int count=0;
cout<<setw(40)
<<"采用递归调用的方法进行解析\n"
<<setw(35)
<<"设定他们输的顺序为:\n"
<<"----------------------------------------------\n"
<<setw(4)
<<" |i"
<<setw(10)
<<"array[0]"
<<setw(10)
<<"array[1]"
<<setw(10)
<<"array[2]"
<<setw(10)
<<"array[3]"
<<endl;
for(int i=4;i>=0;i--)
{

cout<<setw(3)
<<"|"
<<i;

for(int j=0;j<4;j++)
{
cout<<setw(10)
<<array[j];
}
if(count++!=4)
game(array,4);
cout<<endl;
}
cout<<"the result is the last line\n"
<<"----------------------------------------------\n"
<<endl;
return 0;
}
void game(int arr[],int num)
{
static i=1;
int j,array[3]={0};

switch (i)
{
case 1:
{
for(j=0;j<num;j++)
if(j!=3)
{
arr[j]/=2;
array[j]=arr[j];
}
else
arr[j]=(arr[j]+array[0]+array[1]+array[2]);
break;
}
case 2:
{
for(j=0;j<num;j++)
arr[j]/=2;
arr[2]=64-arr[0]-arr[1]-arr[3];
break;
}
case 3:
{
for(j=0;j<num;j++)
arr[j]/=2;
arr[1]=64-arr[0]-arr[2]-arr[3];
break;
}
case 4:
{
for(j=0;j<num;j++)
arr[j]/=2;
arr[0]=64-arr[1]-arr[2]-arr[3];
break;

break;
}
default:
cout<<"you can't get here"<<endl;
break;
}
i++;

}


菜鸟也想高飞
2007-11-01 11:46
jonc
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2007-3-25
收藏
得分:0 

8.
/* 输入两个正整数num_x,num_y,将num_x,num_y化为二进制数,然后将这两个二进制数作二进
制加法运算,再将结果化为十进制数输出。

*/
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
void convert(int ,int[],int);
void array_add(int[],int[],int[],int);
int convert2(int[],int);
int main()
{
int num_x,num_y,sign=1;
const int max=20;
int array_x[max]={0},array_y[max]={0},array_sum[max]={0};//,array_x[32]={0}

cout<<"input the num_x & num_y:\n\r";//input the num_x and num_y
cin>>num_x
>>num_y; //input the number

convert(num_x,array_x,max);//call the function

cout<<"the <"<<num_x<<"> convert into "<<"2"<<" is : ";//print the num_x convert into 2
for(int i=max-1;i>=0;i--)
{
if(!(array_x[i]==0&&sign==1))
{
cout<<array_x[i];
sign=0;
}
}
cout<<endl;

convert(num_y,array_y,max);//call the function
sign=1;
cout<<"the <"<<num_y<<"> convert into "<<"2"<<" is : ";//print the num_x convert into 2
for(int j=max-1;j>=0;j--)
{
if(!(array_y[j]==0&&sign==1))
{
cout<<array_y[j];
sign=0;
}
}
cout<<endl;
sign=1;
array_add(array_x,array_y,array_sum,max);
cout<<"the sum is: ";//print the num_x convert into 2
for(int p=max-1;p>=0;p--)
{
if(!(array_sum[p]==0&&sign==1))
{
cout<<array_sum[p];
sign=0;
}
}

cout<<endl;
cout<<"the sum in the way of 10 is:"<<convert2(array_sum,max)<<endl;
return 0;
}
void convert(int num_x,int array_x[],int size)//change into 2
{
int Remainder1=num_x,i=0;
while(Remainder1!=0)
{
array_x[i++]=Remainder1%2;
Remainder1/=2;
}
}
void array_add(int arr1[],int arr2[],int arr3[],int max)//the sum function
{
int i,j;
for(i=0,j=0;i<max;)
{
arr3[i]=arr1[i]+arr2[i]+arr3[i];
if(arr3[i]==2)
{
arr3[i]=0;
i++;
arr3[i]=1;
}else if(arr3[i]==3)
{
arr3[i]=1;
i++;
arr3[i]=1;
}
else i++;


}
}
int convert2(int arr[],int max)
{
int data=0,i;

for(i=0;i<max;i++)
{
data+=arr[i]*pow(2,i);
}
return data;
}


菜鸟也想高飞
2007-11-01 15:03
六道
Rank: 1
等 级:新手上路
帖 子:120
专家分:0
注 册:2007-9-28
收藏
得分:0 

第6题:

倒排数组
#include<iostream.h>
#include<math.h>
#include<iomanip.h>
void main()
{
int a[100],b[10][10];
int i,j,k,n;
cout<<"please input a number:";
cin>>n;
for(i=0;i<n*n;i++)
a[i]=i+1;
k=n*n-1;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++,k--)
b[i][j]=a[k];
}

cout<<"倒排数组:\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
cout<<setw(4)<<b[i][j];
cout<<endl;
}
}

回转数组

#include<iostream.h>
#include<iomanip.h>
void main()
{
int s[100],a[10][10];
int i,j,n;
static k;
cout<<"please input a number:";
cin>>n;
for(i=0;i<n*n;i++)
s[i]=i+1;

for(i=0;i<=n/2;i++)
{
for(j=i;j<n-i;j++)
{
a[j][i]=s[k];
k++;
}
for(j=i+1;j<n-i;j++)
{
a[n-i-1][j]=s[k];
k++;
}
for(j=n-2-i;j>=i;j--)
{
a[j][n-1-i]=s[k];
k++;
}
for(j=n-2-i;j>=i+1;j--)
{
a[i][j]=s[k];
k++;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
cout<<setw(4)<<a[i][j];
cout<<endl;
}
}


★孤独的人是可耻的★
2007-11-01 23:13
六道
Rank: 1
等 级:新手上路
帖 子:120
专家分:0
注 册:2007-9-28
收藏
得分:0 

第5题:
#include<stdio.h>
main()

{
int i=0,base,n,j,num[20];
printf("enter data that will be converted\n");
scanf("%d",&n);
printf("enter base\n");
scanf("%d",&base);
j=n;
do
{
i++;
num[i]=n%base;
n=n/base;
} while(n!=0);
printf("the data %d has been converted into the %d--base data:\n",j,base);
for(;i>=0;i--)
printf("%d",num[i]);
printf("\n");
}


★孤独的人是可耻的★
2007-11-01 23:25
快速回复:[全民编程]76道高难度C++练习题.含NOI竞赛题.欢迎挑战
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015623 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved