Dressing

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2674    Accepted Submission(s): 1179

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
 


今天上午陪队友一起做的题目之中的一个,我之前没看这题,后来才看的;

思路:先记录好不和谐的衣服和裤子与裤子和鞋子。再枚举衣服和裤子,假设衣服和裤子能够搭配就看鞋子。然后累加能够搭配的就ok了

AC代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
using namespace std; int a[1010][1010], b[1010][1010], c[1010]; int main()
{
int N, M, K, P;
char str1[10], str2[10];
int t1, t2;
while(scanf("%d %d %d", &N, &M, &K)==3, N || M || K)
{
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(c, 0, sizeof(c));
scanf("%d", &P);
while(P--)
{
scanf("%s %d %s %d", &str1, &t1, &str2, &t2);
if(strcmp(str1,"clothes")==0)
{
a[t1][t2]=1;
}
else
{
b[t1][t2]=1;
c[t1]++;
}
}
int ans=0;
for(int i=1;i<=N;i++)
for(int j=1;j<=M;j++)
if(a[i][j]==0)
ans+=(K-c[j]);
printf("%d\n",ans);
}
return 0;
}




最新文章

  1. boost.python笔记
  2. zabbix安装unixODBC配置完之后报错
  3. java中对象产生初始化过程
  4. 关于学习angularJS 的 心里路程(二)
  5. Three.js typescript definitely typed 文件
  6. Ubuntu 12.04搭建l2tp服务器记录。
  7. 拿到阿里,网易游戏,腾讯,smartx的offer的过程
  8. 利用mciSendString播放音频
  9. 数据库表转换成javaBean对象小工具
  10. PHP 中的BOM BUG
  11. Android程序Crash时的异常上报
  12. Android涉及到的设计模式(转)
  13. MyEclipse导入Maven项目pom文件第一行报错,运行Tomcat报Log4j错误--解决方法
  14. 磁盘分区-gdisk用法
  15. SQL随记(一)
  16. TTL与非门电路的工作原理
  17. [JVM-1]Java运行时数据区域
  18. 有关 Azure IaaS VM 磁盘以及托管和非托管高级磁盘的常见问题解答
  19. BZOJ5020 [THUWC 2017]在美妙的数学王国中畅游LCT
  20. C语言程序设计I—第六周教学

热门文章

  1. E20170813-ts
  2. 搭建go开发环境
  3. Cookie、Token与Session介绍(非原创)
  4. Django:提交表单报错:RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you have A
  5. A - Diverse Team
  6. position中的absolute、fixed区别
  7. SEO之如何做301转向
  8. GO 协程 通道实例以及验证SnowFlake算法
  9. ArcGIS API For Android Errors汇总
  10. [WIFI插座][阅读记录][SoC][RT5350] 00.目录 RALINK AP SDK 4.1.0.0 USER&rsquo;s MANUAL