zoukankan      html  css  js  c++  java
  • 贪婪之骑士

    http://www.2cto.com/kf/201310/253108.html

    o(n+m)的复杂度 水

     
    龙有n个头 m个骑士 能力值为x的骑士可以砍掉龙的一个半径不超过x的头 要花x的money 求最小花费砍光头 不行输出Loowater is doomed!
    #include<stdio.h>
    #include<algorithm>
    using namespace std;
    #define maxn 200010
    int a[maxn],b[maxn];
    int main()
    {
    int n,m;
    while(scanf("%d%d",&n,&m)==2)
    {
    if (m == 0 && n == 0) break;
    for(int i=0; i<n; i++) scanf("%d",&a[i]);
    for (int j=0; j<m; j++) scanf("%d",&b[j]);
    sort(a,a+n);
    sort(b,b+m);
    int cur=0;
    int cost=0;
    for (int i=0; i<m; i++) //ÆïÊ¿
    {
    if(b[i]>=a[cur])
    {
    cost+=b[i];
    if(++cur==n) break;
    }
    }
    if(cur<n)printf("Loowater is doomed!
    ");
    else printf("%d
    ",cost);
    
    }
    return 0;
    }
  • 相关阅读:
    虚拟机网络配置常见问题总结
    Python
    Python
    Python
    Python
    Python
    Python
    MySQL
    MySQL
    MySQL
  • 原文地址:https://www.cnblogs.com/SSYYGAM/p/4212520.html
Copyright © 2011-2022 走看看