哈理工校园编程练习赛杭电 acm 4451 C . Dressing
来源:互联网 发布:火锅英雄 知乎 编辑:程序博客网 时间:2024/05/16 10:33
Dressing
http://acm.hdu.edu.cn/showproblem.php?pid=4451
Time Limit: 2000/1000 MS (Java/Others) MemoryLimit: 32768/32768 K (Java/Others) Total Submission(s): 1112 Accepted Submission(s): 471
ProblemDescription
Wangpenghas N clothes, M pants and K shoes so theoretically he can have N×M×K differentcombinations of dressing. One day he wears his pants Nike, shoes Adiwang to goto school happily. When he opens the door, his mom asks him to come back andswitch the dressing. Mom thinks that pants-shoes pair is disharmonious becauseAdiwang is much better than Nike. After being asked to switch again and againWangpeng figure out all the pairs mom thinks disharmonious. They can be onlyclothes-pants pairs or pants-shoes pairs. Please calculate the number ofdifferent combinations of dressing under mom’s restriction.
Input
Thereare multiple test cases. For each case, the first line contains 3 integersN,M,K(1≤N,M,K≤1000) indicating the number of clothes, pants and shoes. Secondline contains only one integer P(0≤P≤2000000) indicating the number of pairswhich mom thinks disharmonious. Next P lines each line will be one of the twoforms“clothes x pants y” or “pants y shoes z”. The first form indicates pair ofx-th clothes and y-th pants is disharmonious(1≤x≤N,1 ≤y≤M), and second formindicates 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
Foreach case, output the answer in one line.
SampleInput
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
SampleOutput
8
6
5
Source
2012 Asia JinHua Regional Contest
题意为有n种衣服(编号1-n),m种裤子(编号1-m),k种鞋(编号1-k),接下来给出不允许的搭配方式,不允许的搭配方式只有衣服与裤子,裤子与鞋,问有多少种允许的搭配方式。 注意:关系没有重复的。
解题:创建数组l[1005]代表衣服与裤子的不允许关系,下标为裤子标号,值为关系个数。 创建数组r[1005]代表裤子与鞋的关系,下标为裤子标号,值为关系个数。
则结果等于 (n-l[i])*(k-r[i]) 1<=i<=m 即排列组合关系,或者说对于L中每个元素对应的裤子标号和上衣不协调搭配的个数,r作用一样,总可能数为n*m*k可以看作m个n*k相乘
,对于从第一条开始的每一条裤子检测上衣和鞋子总可搭配数量,然后m个总数量相加;
我当时连题意都没看懂 唉 就算看着他妈答案 还理解了好大会儿 丫的蛋!
#include<iostream>
intmain()
{
using namespace std;
intL[1111],r[1111],n;
chars[20];
int x,y,z;
while(cin>>x>>y>>z,x+y+z)
{
memset(L,0,sizeof(L));
memset(r,0,sizeof(r));
cin>>n;
int v,v2;
for(int i=0;i<n;i++)
{
scanf("%s%d",s,&v);
if(s[0]=='c')
{
scanf("%s%d",s,&v2);
L[v2]++;
}
else
{
scanf("%s%d",s,&v2);
r[v]++;
}
}
int res=0;
for(int j=1;j<=y;j++)
res+=(x-L[j])*(z-r[j]);
cout<<res<<endl;
}
return0;
}
- 哈理工校园编程练习赛杭电 acm 4451 C . Dressing
- 哈理工校园编程练习赛杭电 acm 4438 D.Hunters
- 哈理工校园编程练习赛杭电 acm 2069 A.Coin Change
- 哈理工校园编程练习赛杭电 acm 4442 E.Physical Examination
- 哈理工校园编程练习赛杭电 acm 4256 H.The Famous Clock
- 哈理工校园编程练习赛杭电 acm 4432 G.Sum of divisors
- 哈理工校园编程练习赛杭电 acm F. 4452 Running Rabbits
- 哈理工校园编程练习赛杭电 acm 4450 B.Draw Something
- 哈理工校园编程练习赛杭电 acm 4442 E.Physical Examination
- 哈理工acm练习赛 K - Tangled in Cables
- C语言练习题(ACM编程练习)
- 杭电 HDU ACM Transportation (哈理工练习赛 费用流拆边)
- C语言 南阳理工ACM 34.韩信点兵
- C语言 南阳理工ACM 611.练练
- hdu 4451 Dressing
- hdu 4451 Dressing
- hdu 4451 Dressing
- hdu 4451 Dressing
- wsmhzy
- 安卓的各种动画资源
- html代码与xhtml代码的区别
- Python核心编程 第18章 多线程
- 如何用电脑共享wifi,解决信号不稳定
- 哈理工校园编程练习赛杭电 acm 4451 C . Dressing
- 折半查找
- 敏捷软件开发 原理、模式与实践 读书笔记
- 透过stats命令分析Memcached的内部状态
- String学习
- Nth Largest Value
- 10000 pcs free gift of chinese top grade brown film faced plywood
- vim文本编辑
- 哈理工校园编程练习赛杭电 acm 4442 E.Physical Examination