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 ...
随机推荐
- oracle中backup模式
在数据库打开的情况下备份(归档模式),把表空间或者数据库置于backup 模式下, 如: SQL> alter database begin backup; Database altered ...
- 实战 ASP.NET MVC Web API
实战 ASP.NET MVC Web API Web API 框架基于 ASP.NET MVC 框架开发,是一个面向 Http 协议的通信框架.相对于 WCF 而言,Web API 只面向于 Http ...
- $(window).height() 文档高度问题
遇到一个这样的问题: 有个项目做的好好的,测试时一步一步小心过来,做了一段时间后,发现前面的完成的功能出了问题了 首先描述下出问题的功能: 做滚动条下拉加载的时候用的网上找的一种方法 $(window ...
- Software Industry Revolution----POJ3898----DP
题目地址:http://poj.org/problem?id=3898 题目意思: 给你一个模式串,再给你一个原串,要你去匹配 模式串里面的?可对应任意一个字符 *号可对应0个或多个字符 其中a=1, ...
- 写一些脚本的心得总结系列第4篇-------从数据库同步到redis
5.从数据库同步到redis的. redis把数据放内存里,读取都非常方便,也提供了远超memcache的丰富数据结构.下面我举2个例子,比如1)把数据从数据库写入到redis: <?php $ ...
- kubernetes入门之skydns
部署kubernetes dns服务 kubernetes可以为pod提供dns内部域名解析服务.其主要作用是为pod提供可以直接通过service的名字解析为对应service的ip的功能. 部署k ...
- 详述JavaScript数组
摘要 数组是JavaScript中的常用类型,本文详述了数组的基本知识以及一些常用的数组方法,并对每种方法进行了详细解释 数组定义 用字面量直接定义 var arr=[0,0,0]; //注意,是方括 ...
- [ios2]OS 6 SDK: 在应用内展示App Store【转】
出于什么样的原因你会希望用户从你的iOS app中进入App Store呢?可能你想用户去App Store 为你的应用评分,也可能你希望用户看到你其他的iOS app.iOS 6引入了SKStore ...
- 驱动10.nor flash
1 比较nor/nand flash NOR NAND接口: RAM-Like,引脚多 引脚少, ...
- 使用redis缓存数据需要注意的问题以及个人的一些思考和理解
之前我有博客也尝试过使用redis,在实际的项目中确实作用挺大的.至少对于数据的频繁读取来说都起着至关重要的作用. 但是随着技术的学习,慢慢的业务要复杂起来,以后也许会用到redis集群,所以在这边查 ...
题目链接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 ...
在数据库打开的情况下备份(归档模式),把表空间或者数据库置于backup 模式下, 如: SQL> alter database begin backup; Database altered ...
实战 ASP.NET MVC Web API Web API 框架基于 ASP.NET MVC 框架开发,是一个面向 Http 协议的通信框架.相对于 WCF 而言,Web API 只面向于 Http ...
遇到一个这样的问题: 有个项目做的好好的,测试时一步一步小心过来,做了一段时间后,发现前面的完成的功能出了问题了 首先描述下出问题的功能: 做滚动条下拉加载的时候用的网上找的一种方法 $(window ...
题目地址:http://poj.org/problem?id=3898 题目意思: 给你一个模式串,再给你一个原串,要你去匹配 模式串里面的?可对应任意一个字符 *号可对应0个或多个字符 其中a=1, ...
5.从数据库同步到redis的. redis把数据放内存里,读取都非常方便,也提供了远超memcache的丰富数据结构.下面我举2个例子,比如1)把数据从数据库写入到redis: <?php $ ...
部署kubernetes dns服务 kubernetes可以为pod提供dns内部域名解析服务.其主要作用是为pod提供可以直接通过service的名字解析为对应service的ip的功能. 部署k ...
摘要 数组是JavaScript中的常用类型,本文详述了数组的基本知识以及一些常用的数组方法,并对每种方法进行了详细解释 数组定义 用字面量直接定义 var arr=[0,0,0]; //注意,是方括 ...
出于什么样的原因你会希望用户从你的iOS app中进入App Store呢?可能你想用户去App Store 为你的应用评分,也可能你希望用户看到你其他的iOS app.iOS 6引入了SKStore ...
1 比较nor/nand flash NOR NAND接口: RAM-Like,引脚多 引脚少, ...
之前我有博客也尝试过使用redis,在实际的项目中确实作用挺大的.至少对于数据的频繁读取来说都起着至关重要的作用. 但是随着技术的学习,慢慢的业务要复杂起来,以后也许会用到redis集群,所以在这边查 ...