hdu 4451
来源:互联网 发布:西单有mac专柜吗 编辑:程序博客网 时间:2024/05/21 07:55
Dressing
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3775 Accepted Submission(s): 1704
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.
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.
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 202 2 21clothes 1 pants 12 2 22clothes 1 pants 1pants 1 shoes 10 0 0
Sample Output
865
Source
2012 Asia JinHua Regional Contest
题意:
给出n,m,k 种衣服,裤子,鞋子
可以组合成 n*m*k种,然后其中mm不喜欢哪种衣服和裤子搭配,或者裤子和鞋子搭配
求可以搭配的方式种数
#include <stdio.h>#include <string.h>int visp[1005],viss[1005];int main(){ int n,m,k; //freopen("in.txt","r",stdin); while(scanf("%d%d%d",&n,&m,&k),n+m+k) { memset(visp,0,sizeof(visp)); memset(viss,0,sizeof(viss)); int ans = n*m*k; char str1[20],str2[20]; int a,b; int t; scanf("%d",&t); while(t--) { scanf("%s%d%s%d",str1,&a,str2,&b); if(!strcmp(str1,"clothes")) { visp[b]++; ans = ans - k + viss[b]; } if(!strcmp(str1,"pants")) { viss[a]++; ans = ans - n + visp[a]; } } printf("%d\n",ans); } return 0;}
0 0
- hdu 4451
- HDU-4451
- hdu 4451
- hdu 4451 Dressing
- hdu 4451 Dressing
- hdu 4451 Dressing
- hdu 4451 Dressing
- Hdu 4451 Dressing
- hdu 4451 Dressing
- HDU 4451 水
- hdu 4451 简单题
- hdu 4451 Dressing
- hdu 4451 Dressing
- hdu 4451Dressing题解
- HDU 4451 Dressing
- hdu-4451 思维题
- hdu
- hdu
- ArcEngine的ToolbarControl解析
- resin与tomcat之比较
- SQL一些常用的查询语句
- HDU 3664 Permutation Counting(DP)
- 智应能用来发财吗?
- hdu 4451
- 压力测试中的一些关键概念:集合点,事务,检查点,思考时间。
- 项目经理面试题
- hdu1179Ollivanders: Makers of Fine Wands since 382 BC.(二分匹配)
- PHP新人的第一篇博客 ~~~~~~环境的配置与导入MySQL数据库~~~
- POJ3122
- HBase的协处理器编码实战
- 如何在 Linux 系统中添加桌面图标
- 单例设计模式中懒汉式并发访问的安全问题