哈理工校园编程练习赛杭电 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;

}

 

0 0
原创粉丝点击