| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
好郁闷阿, 不知道为什么总是WA?那位牛人帮我看看?#include< iostream.h >
#include< memory.h >
int istrue( int * , int );// 判断删除一个墙之后,是否符合条件
int main()
{
int wall[ 101 ][ 2 ]; //记录每堵墙的起始位置
int a[ 101 ];//a 记录每列要穿过的墙的个数,b[i]记录第i堵墙包含的超出范围的列的个数
int test , Nwall , energy , min[101] , max[101] , inum;//test为测试的次数,Nwall墙的个数,energy每列能够穿过的最多的墙的个数
//min, max 记录每堵墙的起始位置
cin >> test;
for( int i = 0; i < test; i ++ )
{
int count = 0; //count 记录删除的墙的个数
memset( a , 0 , 101 * sizeof( int ) );
memset( min , 0 , 101 * sizeof( int ) );
memset( max , 0 , 101 * sizeof( int ) );
memset( wall , 0 , 202 * sizeof( int ) );
cin >> Nwall >> energy;
for( int j = 0; j < Nwall; j ++ )
{
for( int i = 0; i < 2; i ++)
{
cin >> wall[ j ][ i ];
cin >> inum;
}
if( wall[ j ][ 0 ] <= wall[ j ][ 1 ] )
{
min[ j ] = wall[ j ][ 0 ];
max[ j ] = wall[ j ][ 1 ];
}
else
{
min[ j ] = wall[ j ][ 1 ];
max[ j ] = wall[ j ][ 0 ];
}
for( int k = min[ j ]; k <= max[ j ]; k ++ )
a[ k ] ++;
} //输入数据,并处理:将每列的墙的个数保存在数组a中
/* for(j=0; j<Nwall; j++)
cout<<min[j]<<" "<<max[j]<<" * ";
cout<<a[j]<<" * ";
cout<<endl;*/
for(j=0; j<101; j++)
{
if(a[j]>energy)
{
int m=-1, idex;
for(int h=0; h<101; h++)
if(j>=min[h]&&j<=max[h]&&max[h]>m)
{
m=max[h];
idex=h;
}
for(int k=min[idex]; k<=max[idex]; k++)
{
a[k]--;
}
min[idex]=-1;
max[idex]=-1;
count++;
}
}
cout << count << endl;
}
return 0;
}
int istrue( int* a, int max )
{
for( int i = 0; i < 101; i ++)
if( a[ i ] > max )
return 0;
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator