HDU 4451 Dressing
HDU
2023-09-11 14:15:28 时间
Dressing
Time Limit: 1000ms
Memory Limit: 32768KB
This problem will be judged on HDU. Original ID: 445164-bit integer IO format: %I64d Java class name: Main
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 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
解题:由于只有三种,衣服,裤子,鞋子,两层循环枚举即可。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 1010; 18 bool a[maxn][maxn],b[maxn][maxn]; 19 int c[maxn]; 20 int main() { 21 int n,m,k,t,u,v,ans; 22 char sa[10],sb[10]; 23 while(scanf("%d %d %d",&n,&m,&k),n||m||k){ 24 memset(a,false,sizeof(a)); 25 memset(b,false,sizeof(b)); 26 memset(c,0,sizeof(c)); 27 scanf("%d",&t); 28 for(int i = ans = 0; i < t; i++){ 29 scanf("%s %d %s %d",sa,&u,sb,&v); 30 if(sa[0] == 'c') a[u][v] = true; 31 else{b[u][v] = true;c[u]++;} 32 } 33 for(int i = 1; i <= n; i++){ 34 for(int j = 1; j <= m; j++) 35 if(!a[i][j]) ans += k-c[j]; 36 } 37 printf("%d\n",ans); 38 } 39 return 0; 40 }
相关文章
- HDU 4294 Multiple
- 2015 Multi-University Training Contest 3 hdu 5324 Boring Class
- 2015 Multi-University Training Contest 3 hdu 5318 The Goddess Of The Moon
- HDU 1853 Cyclic Tour
- HDU 1540 Tunnel Warfare
- HDU 5510 Bazinga (KMP)
- HDU 2561 第二小整数 (排序)
- Legal or Not HDU - 3342 (拓扑排序)
- HDU 1495 很可乐 (DFS)
- hdu 1817 Necklace of Beads (polya)