现在的位置: 首页 > 综合 > 正文

hdu4451

2013年09月07日 ⁄ 综合 ⁄ 共 2165字 ⁄ 字号 评论关闭
 

Dressing

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

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 <iostream>
#include <stdio.h>
#include <vector>
#include <string.h>
using namespace std;
#define MAXN 1005
vector <int> next[MAXN][2];
char str1[10],str2[10];
int main()
{
    int c,s,p,i,j,sum,ask,n,a,b;
    while(scanf("%d%d%d",&c,&p,&s)!=EOF)
    {
        if(c==0&&p==0&&s==0)
        break;
        //memset(next,-1,sizeof(next));
        for(i=0;i<MAXN;i++)
            for(j=0;j<2;j++)
            {
                next[i][j].clear();
            }
        scanf("%d",&ask);
        while(ask--)
        {
            scanf("%s%d%s%d",str1,&a,str2,&b);
            //printf("%c %c",str1[0],str2[0]);
            if(str1[0]=='c'&&str2[0]=='p')
            {
                next[a][1].push_back(b);
            }
            else{
                next[a][0].push_back(b);
            }


        }
            sum=p*s*c;
            for(i=1;i<=c;i++)
            {

                sum-=s*next[i][1].size();
                for(j=0;j<next[i][1].size();j++)
                {
                    int temp=next[i][1][j];
                    sum+=next[temp][0].size();

                }
            }
             for(i=1;i<=p;i++)
            {

                sum-=c*next[i][0].size();
            }

            printf("%d\n",sum);

    }
    return 0;
}
【上篇】
【下篇】

抱歉!评论已关闭.