http://acm.hdu.edu.cn/showproblem.php?pid=4450
金华的比赛太残酷了,4题是打铁还是银牌取决于手速和准确率啊!
这个题目也是上面的一道水题,因为
clothes —— pants——shoes中,所禁止的搭配都有pants,所以可以枚举pants,
对于每一个pants,找到可以搭配的clothes和shoes相乘,就可以了。
#include <cstdio>
#include <cstring>
using namespace std;
struct node {
int a, b;
};
node p[1100];
int main() {
int N, M, K;
while(scanf("%d%d%d", &N, &M, &K), N) {
int ans = 0;
for(int i = 0; i < M; i++) { p[i].a = 0; p[i].b = 0; }
int n, tmp;
scanf("%d", &n);
char s[100];
for(int i = 0; i < n; i++) {
scanf("%s%d", s, &tmp);
if(strcmp(s, "pants") == 0) { p[tmp-1].b++; }
scanf("%s%d", s, &tmp);
if(strcmp("pants", s) == 0) { p[tmp-1].a++; }
}
//puts(">>>");
for(int i = 0; i < M; i++) {
//printf("%d %d\n", p[i].a , p[i].b);
ans += (N - p[i].a) * (K - p[i].b);
}
printf("%d\n", ans);
}
return 0;
}
如果改变题目,也对clothes 和 shoes之间有要求,那么应该如何处理呢?
看到的大神指教一下!