⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2422.cpp

📁 这是哈尔滨工业大学acmOJ的源代码
💻 CPP
字号:
/* This Code is Submitted by wywcgs for Problem 2422 on 2006-12-04 at 12:43:25 */
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int L = 84;
const int N = 1024;

int main()
{
	int n, k, w[N];
	
	for(int t = 1; scanf("%d %d", &n, &k) != EOF && n != 0; t++) {
		if(t != 1) printf("\n");
		for(int i = 0; i < n; i++) {
			char str[L]; scanf("%s", str);
			w[i] = strlen(str);
		}
		printf("Case %d: ", t);
		if(n%k != 0) { printf("no\n"); continue; }
		sort(w, w+n);
		int m = n / k;
		bool can = true;
		for(int i = 0; i < m; i++) {
			int sum = 0;
			for(int j = 0; j < k; j++) sum += w[i*k+j];
			for(int j = 0; j < k; j++)
				if(sum > (w[i*k+j]+2)*k || sum < (w[i*k+j]-2)*k) can = false;
			if(!can) break;
		}
		printf("%s\n", can ? "yes" : "no");
	}
	
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -