加载中...

C_down
• 博客等级：
• 博客积分：0
• 博客访问：74,925
• 关注人气：27
• 获赠金笔：0支
• 赠出金笔：0支
• 荣誉徽章：

hdu 4451（水题）

(2012-10-30 11:15:42)

Dressing

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 338 Accepted Submission(s): 148

Problem Description
Wangpeng has N clothes, M pants and K shoes so theoretically he can have N×M×K different combinations of dressing.
One day he wears his pants Nike, shoes Adiwang to go to school happily. When he opens the door, his mom asks him to come back and switch the dressing. Mom thinks that pants-shoes pair is disharmonious because Adiwang is much better than Nike. After being asked to switch again and again Wangpeng figure out all the pairs mom thinks disharmonious. They can be only clothes-pants pairs or pants-shoes pairs.
Please calculate the number of different combinations of dressing under mom’s restriction.

Input
There are multiple test cases.
For each case, the first line contains 3 integers N,M,K(1≤N,M,K≤1000) indicating the number of clothes, pants and shoes.
Second line contains only one integer P(0≤P≤2000000) indicating the number of pairs which mom thinks disharmonious.
Next P lines each line will be one of the two forms“clothes x pants y” or “pants y shoes z”.
The first form indicates pair of x-th clothes and y-th pants is disharmonious(1≤x≤N,1 ≤y≤M), and second form indicates pair of y-th pants and z-th shoes is disharmonious(1≤y≤M,1≤z≤K).
Input ends with “0 0 0”.
It is guaranteed that all the pairs are different.

Output
For each case, output the answer in one line.

Sample Input
2 2 2 0 2 2 2 1 clothes 1 pants 1 2 2 2 2 clothes 1 pants 1 pants 1 shoes 1 0 0 0

Sample Output
8 6 5

Source

Recommend
zhuyuanchen520

#include
#include
#include
#include
using namespace
std;
#define N 1010

int
edge[2000200];
int
mark[N];

int
main()
{

int
n,m,k;
while
(scanf("%d%d%d",&n,&m,&k)&&(m+n+k))
{

memset(mark,0,sizeof(mark));
char
c[10],c1[10];
int
p;
int
sum=0;
int
cnt=0;
scanf("%d",&p);
for
(int i=0;i<</FONT>p;i++)
{

int
x,y;
scanf("%s %d %s %d",c,&x,c1,&y);
if
(c[0]=='c')
{

mark[y]++;
sum+=k;
}

else

{

//sum+=m-mark[x];
edge[cnt++]=x;
}
}

for
(int i=0;i<</FONT>cnt;i++)
sum += n-mark[edge[i]];
printf("%d\n",m*n*k-sum);
}

return
0;
}

0

• 评论加载中，请稍候...

发评论

以上网友发言只代表其个人观点，不代表新浪网的观点或立场。

< 前一篇hdu 4450

新浪BLOG意见反馈留言板　电话：4000520066 提示音后按1键（按当地市话标准计费）　欢迎批评指正

新浪公司 版权所有