标签:
Input
Output
Sample Input
Sample Output
/* 像容斥原理,总和减去分别再加上重复减去的 */ #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int MAX = 1005; int p1[MAX], p2[MAX]; int main() { int n, m , k, p; int t1, t2; char s1[10], s2[10]; while(~scanf("%d%d%d", &n, &m, &k)){ memset(p1, 0, sizeof(p1)); memset(p2, 0, sizeof(p2)); if(n == 0 && m == 0 && k == 0) break; scanf("%d", &p); int sum = m * k * n; for(int i = 1; i <= p ; i++){ scanf("%s%d%s%d", s1, &t1, s2, &t2); if(s1[0] == ‘c‘){ p1[t2] ++; sum -= k; } else if(s1[0] == ‘p‘ ){ p2[t1] ++; sum -= n; } } int sum1 = 0; for(int i = 1; i <= m; i++){ sum1 += p1[i] * p2[i]; } sum += sum1; printf("%d\n",sum); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zero-begin/p/4655770.html