HDU_1902,大時代1902

來源:互聯網
上載者:User

HDU_1902,大時代1902

#include<algorithm>#include<cctype>#include<cstdio>using namespace std;const int maxn = 20005;int N[maxn], M[maxn];int buffer[10];int n, m;void scan_d(int &x) {    char ch = getchar();    while(!isdigit(ch)) ch = getchar();    x = 0;    do {        x = x * 10 + ch - '0';        ch = getchar();    }while(isdigit(ch));}void print_d(int x) {    if(x == 0) putchar('0');    else {        int p = 0;        while(x) {            buffer[p++] = x % 10 + '0';            x /= 10;        }        for(int i = p-1; i >= 0; i--) putchar(buffer[i]);    }    putchar('\n');}int main() {    while(scanf("%d%d", &n, &m) == 2 && n && m) {        for(int i = 0; i < n; i++) scan_d(N[i]);        for(int i = 0; i < m; i++) scan_d(M[i]);        sort(N, N+n);sort(M, M+m);        int cur = 0;   //變數什麼時候需要用就什麼時候定義        int cost = 0;        for(int i = 0; i < m; i++)   //一共有m個騎士   能力是從小到打排列的            if(M[i] >= N[cur]) {   // 如果騎士的能力大於或者等於這個頭數                cost += M[i];  //那麼久算上這個花費                if(++cur == n) break;            }        if(cur < n) printf("Loowater is doomed!\n");          // cur < n 就說明  騎士已經用完了        else print_d(cost);    }    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.