zoukankan      html  css  js  c++  java
  • HDU 2439 The Mussels

    The Mussels

    Time Limit: 1000ms
    Memory Limit: 32768KB
    This problem will be judged on HDU. Original ID: 2439
    64-bit integer IO format: %I64d      Java class name: Main
     
    "To be or not to be, that is the question." Now FJ( Frank&John) faces a serious problem.

    FJ is breeding mussels these days. The mussels all want to be put into a culturist with a grade no little than their own grades. FJ accept their requirements.

    FJ provides culturists of different grades, all having a certain capacity. FJ first put mussels into culturists with the same grade until they are full. Then he may put some mussels into some potential culturists that still have capacity.

    Now, FJ wants to know how many mussels can be put into the culturists.
     

    Input

    For each data set:
    The first line contains two integers, n and m(0<n<=100000,0<m<=1000000), indicating the number of culturists and the number of mussels. The ith culturist has a grade i, and grade 1 is considered the highest.

    The second line contains n integers indicating the culturists' capacity in order.

    The third line contains m integers all in the range 1~n, indicating the mussels' grade in order.

    Proceed to the end of file.
     

    Output

    A single integer, which is the number of mussels that can be put into the culturists.
     

    Sample Input

    4 4
    100 4 4 4
    1 2 3 4
    4 3
    1 1 1 1
    4 2 2

    Sample Output

    4
    3

    Source

     
    解题:贪心+模拟,直接按照题目意思去做就是了。。。
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <climits>
     7 #include <vector>
     8 #include <queue>
     9 #include <cstdlib>
    10 #include <string>
    11 #include <set>
    12 #include <stack>
    13 #define LL long long
    14 #define pii pair<int,int>
    15 #define INF 0x3f3f3f3f
    16 using namespace std;
    17 int cul[100010],tmp,n,m;
    18 void myscanf(int &x){
    19     char ch;
    20     while((ch = getchar()) < '0' || ch > '9');
    21     x = 0;
    22     x = x*10 + ch - '0';
    23     while((ch = getchar()) >= '0' && ch <= '9') x = x*10 + ch - '0';
    24 }
    25 int main() {
    26     while(~scanf("%d %d",&n,&m)){
    27         for(int i = 1; i <= n; i++)
    28             myscanf(cul[i]);
    29         int ans = 0;
    30         for(int i = 1; i <= m; i++){
    31             myscanf(tmp);
    32             if(cul[tmp]){
    33                 --cul[tmp];
    34                 ++ans;
    35             }else{
    36                 for(int j = tmp; j; --j){
    37                     if(cul[j]){
    38                         --cul[j];
    39                         ++ans;
    40                         break;
    41                     }
    42                 }
    43             }
    44         }
    45         printf("%d
    ",ans);
    46     }
    47     return 0;
    48 }
    View Code
  • 相关阅读:
    Google's Innovation Factory (and how testing adapts)
    虎年拜年帖
    [ZZ]让测试也敏捷起来
    Selenimu做爬虫续
    OKR的解说
    春秋航空的机上店铺
    免费TK域名试用
    快速排序_C语言实现
    第一篇博客
    C、C++代码格式优化软件献给编程爱好者
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4006711.html
Copyright © 2011-2022 走看看