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 ...
随机推荐
- Ext.ux.form.SuperBoxSelect
Ext.ux.form.SuperBoxSelect 在B/S系统中,下拉列表(select/dropdownlist/combobox)的应用随处可见,为了增强用户体验,开发人员也常常会做一些带联想 ...
- 设置共享文件夹,samba和chmod到底谁的权限大
1,必备知识.已经知道的请跳过. 首先科普一下这两个东西:samba和chmod其实是完全不同层面的东西,一个是共享服务协议,一个是权限设置语句.但是他们有一个共同的用途:可以用来实现设置一个共享文件 ...
- Jquery控制点击时一、二级菜单自由隐藏与出现
一.基本HTML和CSS HTML中产生一.二级导航的代码: {loop $nav $key $value} <div class=”u_con”> <span class=” xg ...
- <我的外骨骼,诺基>后的访谈
<我的外骨骼,诺基>后的访谈 在接下采访任务之前,我对杨贵福的了解仅仅限于:有名的科幻作家,男性,成年.我虽然读过他的许多作品,但在这些作品中并不能找到作者的影子.我试着从作品的行文风格中 ...
- java类静态域、块,非静态域、块,构造函数的初始化顺序
原文:http://ini.iteye.com/blog/2007835 面试的时候,经常会遇到这样的考题:给你两个类的代码,它们之间是继承的关系,每个类里只有构造器方法和一些变量, 构造器里可能还有 ...
- java String源码学习
public final class String implements java.io.Serializable, Comparable<String>, CharSequence { ...
- 驱动07.USB驱动程序
1 了解USB识别的过程 eg:在Windows系统下的一个现象:把手机的USB设备接到PC 1. 右下角弹出"发现android phone" 2. 跳出一个对话框,提示你安装驱 ...
- .net在网页中生成二维码和条形码
二维码: 1.下载ThoughtWorks.QRCode.dll文件 2.创建Web项目,添加引用刚才下载的文件 3.在项目中添加aspx窗体,编写代码如下 <%@ Page Language= ...
- jquery中动态新增的元素节点无法触发事件解决办法
在使用jquery中动态新增的元素节点时会发现添加的事件是无法触发的,我们下面就为各位来详细的介绍此问题的解决办法. 比如做一个ajax读取留言列表的时候,每条留言后面有个回复按钮,class为“re ...
- Intellij Idea + Maven + Git + Struts2 HelloWorld
1.在intellij Idea上新建Maven项目,输入相应的groupId,artifactId,项目名称: 2.在项目的pom文件中,引入struts2的核心依赖struts2-core: &l ...
题目链接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 ...
Ext.ux.form.SuperBoxSelect 在B/S系统中,下拉列表(select/dropdownlist/combobox)的应用随处可见,为了增强用户体验,开发人员也常常会做一些带联想 ...
1,必备知识.已经知道的请跳过. 首先科普一下这两个东西:samba和chmod其实是完全不同层面的东西,一个是共享服务协议,一个是权限设置语句.但是他们有一个共同的用途:可以用来实现设置一个共享文件 ...
一.基本HTML和CSS HTML中产生一.二级导航的代码: {loop $nav $key $value} <div class=”u_con”> <span class=” xg ...
<我的外骨骼,诺基>后的访谈 在接下采访任务之前,我对杨贵福的了解仅仅限于:有名的科幻作家,男性,成年.我虽然读过他的许多作品,但在这些作品中并不能找到作者的影子.我试着从作品的行文风格中 ...
原文:http://ini.iteye.com/blog/2007835 面试的时候,经常会遇到这样的考题:给你两个类的代码,它们之间是继承的关系,每个类里只有构造器方法和一些变量, 构造器里可能还有 ...
public final class String implements java.io.Serializable, Comparable<String>, CharSequence { ...
1 了解USB识别的过程 eg:在Windows系统下的一个现象:把手机的USB设备接到PC 1. 右下角弹出"发现android phone" 2. 跳出一个对话框,提示你安装驱 ...
二维码: 1.下载ThoughtWorks.QRCode.dll文件 2.创建Web项目,添加引用刚才下载的文件 3.在项目中添加aspx窗体,编写代码如下 <%@ Page Language= ...
在使用jquery中动态新增的元素节点时会发现添加的事件是无法触发的,我们下面就为各位来详细的介绍此问题的解决办法. 比如做一个ajax读取留言列表的时候,每条留言后面有个回复按钮,class为“re ...
1.在intellij Idea上新建Maven项目,输入相应的groupId,artifactId,项目名称: 2.在项目的pom文件中,引入struts2的核心依赖struts2-core: &l ...