HDU 4451 Dressing
HDU 4451 Dressing
题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4451
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
题意:
给你n件衣服,m条裤子,k双鞋子。然后给你p个冲突。求有多少种搭配方式。
题解:
先是对于每条裤子统计能搭配的鞋子数量,然后暴力扫一遍衣服和裤子的搭配,累加起来即可。
代码:
#include <bits/stdc++.h>
using namespace std;
int n,m,k,p;
const int maxn = 1100;
int C[maxn],P[maxn],S[maxn];
bool rec[maxn][maxn];
int main()
{
while (scanf("%d %d %d",&n,&m,&k)){
if (n == 0 && m == 0 && k == 0)
break;
memset(rec,0,sizeof rec);
for (int i = 1; i <= m; i++)
P[i] = k;
scanf("%d",&p);
char in1[10],in2[10];
int x1,x2;
while (p--){
scanf("%s %d %s %d",in1,&x1,in2,&x2);
if (in1[0] == 'c'){
rec[x1][x2] = true;
}else {
P[x1]--;
}
}
long long ans = 0;
for (int i = 1; i <= n;i++){
for (int j = 1; j <= m; j++){
if (rec[i][j])
continue;
ans += P[j];
}
}
printf("%lld\n",ans);
}
}
HDU 4451 Dressing的更多相关文章
- 【HDU 4451 Dressing】水题,组合数
有衣服.裤子.鞋数量分别为n,m,k,给出p对不和谐的衣-裤或裤-鞋搭配,问一共有多少种和谐的衣裤鞋的搭配. 全部的组合有Cn1Cm1Ck1种. 设p对中有p1对衣-裤,p2对裤-鞋,则不和谐的搭配共 ...
- hdu 4451 Dressing 排列组合/水题
Dressing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- hdu 4451 Dressing 衣服裤子鞋 简单容斥
Dressing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- hdu 4451 37届金华赛区 J题
题意:给出衣服裤子鞋子的数目,有一些衣服和裤子,裤子和鞋子不能搭配,求最终的搭配方案总数 wa点很多,我写wa了很多次,代码能力需要进一步提升 #include<cstdio> #incl ...
- HDU 4451 容斥原理
题目大意: n件衣服,m条裤子,k双鞋子进行搭配 妈妈指明了哪些衣服和裤子不能搭配,哪些裤子和鞋子不能搭配,问最后有几种搭配方法 先假设都能搭配 n*m*k 每次遇到衣服和裤子不能搭的,就要减一次k, ...
- hdu 4046 Panda 树状数组
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4046 When I wrote down this letter, you may have been ...
- hdu 1151 Air Raid(二分图最小路径覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS Memory Limit: 10000K To ...
- HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)
HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others) Memory Limit: ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
随机推荐
- Servlet的Request.getInputStream()只能读取一次问题
Servlet的Request.getInputStream()只能读取一次问题 这个星期公司的项目接口进行改造,公司的接口有的采用了WebService的方式,有的使用的是Http协议+Servle ...
- Design Patterns in Smalltalk MVC 在Smalltalk的MVC设计模式
Design Patterns in Smalltalk MVC在Smalltalk的MVC设计模式 The Model/View/Controller (MVC) triad ofclasse ...
- 关闭Windows 2008下面应用程序出错后的提示
写了一个服务器端程序,没有能处理所有的错误,总有一些错误会抛出到系统中去.于是写了一个进程守护者,一旦发现服务器端退出,可以在第一时间重新启动服务器,也算是一种折中的方案吧.理论上讲应该是可行的,但是 ...
- javascript深入之location对象和history对象
浏览器的location 和history对象: 一.location对象: 1>location.reload() 相当于按浏览器上的“刷新”(IE)或“Reload”(Netscape)键. ...
- C# 数据库连接测试以及备份
现在我们要做一个如图5.1的数据库连接配置,从界面上看有三个功能需要实现:从配置文件中读取数据库连接的相关属性.备份数据库.测试连接. 现在我们就一个一个开始讲解. 图5.1 1.从配置文件中读取数据 ...
- Linux-gate.so技术细节
1. linux-gate.so是什么参考这里:http://www.trilithium.com/johan/2005/08/linux-gate/简而言之,linux-gate.so是为了实现用户 ...
- java基础知识拾遗(三)
1.类加载 bootstrap classloader -引导(也称为原始)类加载器,它负责加载Java的核心类. extension classloader -扩展类加载器,它负责加载JRE的扩展目 ...
- Oracle多关键字查询
因项目需要,在某查询页面的查询字段支持多关键字查询,支持空格隔开查询条件,故实现如下: 使用的原理是:ORACLE中的支持正则表达式的函数REGEXP_LIKE, '|' 指明两项之间的一个选择.例子 ...
- 使用gulp构建自动化工作流
简单易用 高效构建 高质量的生态圈 可能很多人会说现在提gulp也太落后了吧,但我想说写点东西并不是为了讨论它是否过时,而是来帮助我们自己来记忆.整理和学习.任何工具,我需要,我才去使用它,正如此时我 ...
- 双色球机选算法java实现
双色球机选算法java实现 一.代码 package com.hdwang; import java.util.Random; /** * Created by admin on 2017/1/10. ...
题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4451
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
题意:
给你n件衣服,m条裤子,k双鞋子。然后给你p个冲突。求有多少种搭配方式。
题解:
先是对于每条裤子统计能搭配的鞋子数量,然后暴力扫一遍衣服和裤子的搭配,累加起来即可。
代码:
#include <bits/stdc++.h>
using namespace std;
int n,m,k,p;
const int maxn = 1100;
int C[maxn],P[maxn],S[maxn];
bool rec[maxn][maxn];
int main()
{
while (scanf("%d %d %d",&n,&m,&k)){
if (n == 0 && m == 0 && k == 0)
break;
memset(rec,0,sizeof rec);
for (int i = 1; i <= m; i++)
P[i] = k;
scanf("%d",&p);
char in1[10],in2[10];
int x1,x2;
while (p--){
scanf("%s %d %s %d",in1,&x1,in2,&x2);
if (in1[0] == 'c'){
rec[x1][x2] = true;
}else {
P[x1]--;
}
}
long long ans = 0;
for (int i = 1; i <= n;i++){
for (int j = 1; j <= m; j++){
if (rec[i][j])
continue;
ans += P[j];
}
}
printf("%lld\n",ans);
}
}
有衣服.裤子.鞋数量分别为n,m,k,给出p对不和谐的衣-裤或裤-鞋搭配,问一共有多少种和谐的衣裤鞋的搭配. 全部的组合有Cn1Cm1Ck1种. 设p对中有p1对衣-裤,p2对裤-鞋,则不和谐的搭配共 ...
Dressing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
Dressing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
题意:给出衣服裤子鞋子的数目,有一些衣服和裤子,裤子和鞋子不能搭配,求最终的搭配方案总数 wa点很多,我写wa了很多次,代码能力需要进一步提升 #include<cstdio> #incl ...
题目大意: n件衣服,m条裤子,k双鞋子进行搭配 妈妈指明了哪些衣服和裤子不能搭配,哪些裤子和鞋子不能搭配,问最后有几种搭配方法 先假设都能搭配 n*m*k 每次遇到衣服和裤子不能搭的,就要减一次k, ...
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4046 When I wrote down this letter, you may have been ...
http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS Memory Limit: 10000K To ...
HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others) Memory Limit: ...
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
Servlet的Request.getInputStream()只能读取一次问题 这个星期公司的项目接口进行改造,公司的接口有的采用了WebService的方式,有的使用的是Http协议+Servle ...
Design Patterns in Smalltalk MVC在Smalltalk的MVC设计模式 The Model/View/Controller (MVC) triad ofclasse ...
写了一个服务器端程序,没有能处理所有的错误,总有一些错误会抛出到系统中去.于是写了一个进程守护者,一旦发现服务器端退出,可以在第一时间重新启动服务器,也算是一种折中的方案吧.理论上讲应该是可行的,但是 ...
浏览器的location 和history对象: 一.location对象: 1>location.reload() 相当于按浏览器上的“刷新”(IE)或“Reload”(Netscape)键. ...
现在我们要做一个如图5.1的数据库连接配置,从界面上看有三个功能需要实现:从配置文件中读取数据库连接的相关属性.备份数据库.测试连接. 现在我们就一个一个开始讲解. 图5.1 1.从配置文件中读取数据 ...
1. linux-gate.so是什么参考这里:http://www.trilithium.com/johan/2005/08/linux-gate/简而言之,linux-gate.so是为了实现用户 ...
1.类加载 bootstrap classloader -引导(也称为原始)类加载器,它负责加载Java的核心类. extension classloader -扩展类加载器,它负责加载JRE的扩展目 ...
因项目需要,在某查询页面的查询字段支持多关键字查询,支持空格隔开查询条件,故实现如下: 使用的原理是:ORACLE中的支持正则表达式的函数REGEXP_LIKE, '|' 指明两项之间的一个选择.例子 ...
简单易用 高效构建 高质量的生态圈 可能很多人会说现在提gulp也太落后了吧,但我想说写点东西并不是为了讨论它是否过时,而是来帮助我们自己来记忆.整理和学习.任何工具,我需要,我才去使用它,正如此时我 ...
双色球机选算法java实现 一.代码 package com.hdwang; import java.util.Random; /** * Created by admin on 2017/1/10. ...