用ceil和floor的时候,记得保证参数是double
#include#include #include using namespace std;vector numsStartWith;char str[10];int main() { int K; int N; int i; numsStartWith.resize(10); for (i = 0; i < numsStartWith.size(); ++i) numsStartWith[i] = 0; scanf("%d %d", &K, &N); for (i = 0; i < N; ++i) { scanf("%s", str); ++numsStartWith[str[0] - '0']; } int ans = 0; for (i = 1; i <= 9; ++i) { if (numsStartWith[i] == 0) continue; ans = ans + (int)ceil((double)numsStartWith[i] / K); } printf("%d\n", ans + 2); return 0;}