答案: 第二:
#include<iostream>
using namespace std;
void func(int s[],int sum,int &max,int &min)
{ int i;
max=s[0];
min=s[0];
for(i=1;i<sum;i++)
{
if(s[i]>max) max=s[i];
if(s[i]<min) min=s[i];
}
}
int main()
{
int j,su,k=0,s[64],ma,mi,out[256];
while(1)
{ cin>>su;
if(su==0||su>64) break;
else
{
for(j=0;j<su;j++)
cin>>s[j];
func(s,su,ma,mi);
out[k]=ma+mi;
k++;
}
}
for(j=0;j<k;j++)
cout<<out[j]<<endl;
return 0;
}
第3:
#include<iostream>
using namespace std;
const int MSoE=12;
const int MAX=40+1;
bool Cake[MAX][MAX]={0};
int SoE[MSoE+1]={0};
int currentmax=MSoE;
int s,nn;
bool sta=0;
void set(int i,int j,int len){
for (int ii=i;ii<i+len;ii++){
for (int jj=j;jj<j+len;jj++){
Cake[ii][jj]=1;
}
}
}
void putback(int i,int j,int len){
for (int ii=i;ii<i+len;ii++){
for (int jj=j;jj<j+len;jj++){
Cake[ii][jj]=0;
}
}
}
bool check(int i,int j,int len){
for (int jj=j;jj<len+j;jj++){
if (Cake[i][jj]==1)return 0;
}
return 1;
}
void put(){
if (nn==0){sta=1;return;}
int i,j;
for (i=0;i<s;i++){
for(j=0;j<s;j++){
if (Cake[i][j]==0){
int len=currentmax;
while(SoE[len]==0){len--;}
while(len){
if(SoE[len]==0||j+len>s||i+len>s||!check(i,j,len)){len--;continue;}
set(i,j,len);
SoE[len]--;
nn--;
put();
if (sta==1)return;
putback(i,j,len);
SoE[len]++;
nn++;
len--;
}
if (Cake[i][j]==0)return;
}
}
}
}
int main(){
int t,n;
scanf("%d",&t);
while(t--){
int i;
for (i=0;i<s;i++){
memset(Cake[i],0,s);
}
for (i=0;i<MSoE;i++){
SoE[i]=0;
}
currentmax=MSoE;
scanf("%d %d",&s,&n);
nn=n;
int size;
int space=0;
while(n--){
scanf("%d",&size);
SoE[size]++;
space+=size*size;
}
if (space!=s*s){
printf("HUTUTU!\n");
continue;
}
while(SoE[currentmax]==0){
currentmax--;
}
put();
if (sta==1){
printf("KHOOOOB!\n");
}
else printf("HUTUTU!\n");
sta=0;
}
return 0;
}
上一个:跪求高手帮助做一C++程序
下一个:VB和C++哪个比较好学