哈理工校园编程练习赛杭电 acm 4451 C . Dressing
2015-03-15 18:12
477 查看
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;
}
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 4256 H.The Famous Clock
- 哈理工校园编程练习赛杭电 acm 4450 B.Draw Something
- 哈理工校园编程练习赛杭电 acm 4432 G.Sum of divisors
- 哈理工校园编程练习赛杭电 acm 4438 D.Hunters
- 哈理工校园编程练习赛杭电 acm 2069 A.Coin Change
- 哈理工校园编程练习赛杭电 acm 4442 E.Physical Examination
- 哈理工校园编程练习赛杭电 acm F. 4452 Running Rabbits
- 杭电 HDU ACM Transportation (哈理工练习赛 费用流拆边)
- 哈理工练习赛 杭电 HDU Prime Path 1973 poj 3126 Prime Path
- 第37届ACM/ICPC 金华赛区现场赛最水四道题 HDU 4442 Physical Examination HDU 4450 Draw Something HDU 4451 Dressing HDU 4452 Running Rabbits
- ACM学习历程—Hihocoder [Offer收割]编程练习赛1
- 哈理工acm练习赛 K - Tangled in Cables
- 杭电ACM求数列的和
- 杭电acm 4142Triangle(小学生题,判断三角形)
- 杭电acm 3613Best Reward(字符串)
- 2017微软秋季校园招聘在线编程笔试-#1402 : MS Recognition
- 【C编程练习】2013华为校园招聘机试题目题5:将一个int类型的数字转化为字符串,并判断有无重复字符串(长度应大于2)有返回1,无返回2
- 杭电OJ第十五届ACM第一题 Hearthstone
- hihocoder1368即 [Offer收割]编程练习赛7第四题
- 杭电ACM 1175