2-09. 装箱问题模拟(20)

来源:互联网 发布:梁家辉 座山雕 知乎 编辑:程序博客网 时间:2024/05/16 09:54
#include <cstring>#include<iostream>using namespace std;#define Size 1000int main(){        int box[Size+1];        int pos[Size+1];        memset( pos, 0, sizeof(pos) );        memset( box, 0, sizeof(box) );        int N;        cin>>N;        int sth[Size+1];        int i, j, ans=0;        for( i=0; i<N; i++ )        {                cin>>sth[i];                for( j=1; (100-box[j])<sth[i]; j++ );                if( j>ans )                    ans=j;                box[j]+=sth[i];                pos[i]=j;        }        for( int i=0; i<N; i++ )        {            cout<<sth[i]<<" "<<pos[i]<<endl;        }        cout<<ans<<endl;        return 0;}

0 0
原创粉丝点击