| ||||||||||
| 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 | |||||||||
我的1827为什么错了#include<iostream>
using namespace std;
struct node//monster的数据
{
int number;
int strength;
};
int max_box;//当前分配盒子
bool operator<(node c1,node c2)
{
if(c1.number>=max_box&&c2.number>=max_box)//number大于当前分配盒子的,只需比较strength
if(c1.strength>=c2.strength)return false;
else return true;
if(c1.number>c2.number)return false;
if(c1.number<c2.number)return true;
if(c1.strength>=c2.strength)return false;//number相等时
return true;
}
void Heap(node*array,int s,int e)
{
node temp;
for(int j=2*s+1;j<e;j=j*2+1)
{
if(j+1==e||array[j+1]<array[j])
{
if(array[s]<array[j])
{
temp=array[s];
array[s]=array[j];
array[j]=temp;
s=j;
}
}
else
if(array[s]<array[j+1])
{
j++;
temp=array[s];
array[s]=array[j];
array[j]=temp;
s=j;
}
else break;
}
}
node monster[50000];
int main()
{
int m,n,total;
cin>>n>>m;
while(m&&n)
{
int i;
for(i=0;i<n;i++)//输入
{
cin>>monster[i].number;
}
for(i=0;i<n;i++)//输入
{
cin>>monster[i].strength;
}
max_box=m;//当前盒子设置为最大
for(i=n/2-1;i>=0;i--)Heap(monster,i,n);//建堆
i=n;
while(i)
{
if(max_box>monster[0].number)max_box=monster[0].number;//最大的盒子
monster[0]=monster[i-1];//删除堆顶元素,并以最后一个代替
i--;
max_box--;
if(!max_box)break;
Heap(monster,0,i);//调整成大顶堆
}
total=0;
while(i)//计算DAMAGE
{
total+=monster[i].strength;
i--;
}
cout<<total<<endl;
cin>>n>>m;
}
return 0;
}
//各位高人指点一下,我的程序错在哪了
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator