A、
STr
最大间隙问题
#include using namespace std;
const int MAX=200001;
double num[MAX];
bool run ()
{
int n;
if (scanf ("%d", &n)=E0F) return false;
int i;
double max=0. 0, min=INT_MAX;
for (i=0;i
{
scanf ("%lf",&num[i]);
if (num[i] >max) max=num[i];
if(numEi]
}
int *cnt二new int[n];
double *low二new double[n];
double *high二new double[n];
for (i=0;i
{
crrt [i]=0;
low[i]=max; high[i]二 min;
}
double ave=(max-min)/(n~l);
for(i=0;i
{
int tmp=(int)((num[i]-min)/ave);
ent[tmp]++;
if(num[i]>high[tmp]) high[tmp]=num[i]; if(num[i]
double t=high[0], res=0. 0; for(i=l;i
{
if (ent[i]>0)
{
double tmp=low[i]-t; if(tmp>res)res=tmp;
t=high[i];
}
}
cout〈〈 res?endl;
return true;
}
int main()
{
while (run ());
return 0;
B、 金币列阵问题
^include
^include
using namespace std;
const int size = 100;
int k, n, m, ccount, best;
int b0[size+l][size+1], bl[size+1][size+1], b[size+l][size+1]; bool found;
void print ()
{
for (int i = 1; i <= n; i++)
{
for(int j 二 1; j <= m; j++) cout ? bl[i][j] ? cout ? endl;
}
}
void transl (int x)//行翻转
for (int i = 1; i <= m; i++)
bl[x][i] = bl[x][i]J;
ccount++;
}
void trans2 (int x, int y)//列交换
{
for (int i = 1; i〈= n; i++) swap(bl[i][x], bl[i][y]);
if (x != y) ccount++;
}
bool same(int x, int y)
{
for (int i = 1; i <= n; i++)
if (bO[i][x] != bl[i][y])
return false;
return true;
}
void acpy(int a[size+l][size+1], int b[size+l][size+1])
for(int
i = 1;
i <= n;
i++)
for(int
j = 1;
j <= m; j++)
=b[i][j];
/
void
answer ()
int
x, y, j,p;
cin ? 1
for(int
(
i = 1;
i <= k;
i++)
cin ?
n >> m;
//原状态bO
for ( x = 1; x <= n; x++)
for ( y = 1; y <= m; y++) cin >> bO[x][y];
〃目标状态 bl
for ( x = 1; x <= n; x++)
for (int y = 1; ym; y++) cin ? bl[x][y]; acpy (b, bl);
best = m + n + 1;
for( j = 1; j <= m; j++)
acpy (bl, b);
ccount = 0;
trans2(l, j) ; //列变换int p;
for ( p = 1; p <= n; p++)
if (bO[p] [1] != bl[p]⑴)
trans l(p) ; //行变换
for(p = 1; p <= m; p++)//找列相等的(bl
的q列和bO的p列相等)
{
found