zoukankan      html  css  js  c++  java
  • Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation(贪心)

    题目:http://codeforces.com/contest/389/problem/C

    题意:给n个箱子,给n个箱子所能承受的重量,每个箱子的重量为1;

    很简单的贪心,比赛的时候没想出来。、、、、、

    先从小到大排一下序,然后从最上层向下找,只要能承受住重量就行。而且因为已经排序了找的都是尽量小的。。。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <algorithm>
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     int n,a[110],f[110],sum,x;
    11     int i,j;
    12     while(cin>>n)
    13     {
    14         sum=0;
    15         for(i=0; i<n; i++)
    16         cin>>a[i];
    17 
    18         sort(a,a+n);
    19         memset(f,0,sizeof(f));
    20         for(j=0; j<n; j++)
    21         {
    22             x=0;
    23             for(i=0; i<n; i++)
    24             {
    25                if(a[i]>=x&&f[i]==0)
    26                {
    27                    x++;
    28                    f[i]=1;
    29                }
    30             }
    31             if(x==0)
    32             break;
    33             sum++;
    34         }
    35         printf("%d
    ",sum);
    36     }
    37     return 0;
    38 }
  • 相关阅读:
    Velocity Obstacle
    游戏AI技术 2
    游戏AI技术
    状态同步
    Realtime Rendering 1.1
    Steering Behaviors
    Realtime Rendering 6
    网络同步
    War3编辑器
    Realtime Rendering 5
  • 原文地址:https://www.cnblogs.com/bfshm/p/3541832.html
Copyright © 2011-2022 走看看