題意: 這是本次的簽到題,不過沒有以前遇到的簽到題那麼水。有 m 條魚,n 只貓,每隻貓喫完一條魚需要
思路: 數據很小。我們可以模擬一下流程:按照喫魚速度給貓排個序,然後每一分鐘開始時,按排好的順序給沒有魚的貓發魚,每一分鐘結束時每隻貓都喫掉一部分魚,這樣繼續迭代,直到到時間了爲止。
代碼:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<utility>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<iostream>
#include<algorithm>
#include<sstream>
using namespace std;
typedef long long LL;
int m, n, x;
int c[110];
int eat[110];
int main()
{
//freopen("in.txt", "r", stdin);
while(scanf("%d%d%d", &m, &n, &x) == 3){
for(int i=0; i<n; i++){
scanf("%d", &c[i]);
}
sort(c, c+n);
memset(eat, 0, sizeof(eat));
for(int i=0; i<x; i++){
for(int j=0; j<n && m>0; j++){ //給沒有魚的貓發魚
if(eat[j] == 0){
eat[j] = c[j];
m--;
}
}
for(int j=0; j<n; j++){ //每隻貓都喫掉一部分魚
eat[j]--;
}
}
int inc = 0;
for(int i=0; i<n; i++){
if(eat[i]>0 && eat[i]<c[i]) inc++;
}
printf("%d %d\n", m, inc);
}
return 0;
}