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 ...
随机推荐
- 新版C#编译器关于函数闭包
新版C#编译器关于函数闭包的一处更改 在Visual Basic.NET中,如果你写下类似下面的代码: Public Sub Test() For i = 0 To 100 Dim func = ...
- wget ( download the whole page from the website )
---恢复内容开始--- wget -m -e robots=off -U "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1 ...
- 10161 - Ant on a Chessboard
Problem A.Ant on a Chessboard Background One day, an ant called Alice came to an M*M chessboard. She ...
- 【摘录】使用实体框架、Dapper和Chain的仓储模式实现策略
以下文章摘录来自InfoQ,是一篇不错的软问,大家细细的品味 关键要点: Dapper这类微ORM(Micro-ORM)虽然提供了最好的性能,但也需要去做最多的工作. 在无需复杂对象图时,Chain这 ...
- java 企业网站源码模版 有前后台 springmvc SSM 生成静态化
java 企业网站源码 前后台都有 静态模版引擎, 代码生成器大大提高开发效率 系统介绍 点击:获取地址 : 1.网站后台采用主流的 SSM 框架 jsp JSTL,网站后台采用freemaker静态 ...
- 浅谈href=#与href=javascript:void(0)的区别
#"包含了一个位置信息 默认的锚点是#top 也就是网页的上端 而javascript:void(0) 仅仅表示一个死链接 这就是为什么有的时候页面很长浏览链接明明是#可是跳动到了页首 而 ...
- Flexible 弹性盒子模型之CSS flex-wrap 属性
实例 让弹性盒元素在必要的时候拆行: display:flex; flex-wrap: wrap; 复制 效果预览 浏览器支持 表格中的数字表示支持该属性的第一个浏览器的版本号. 紧跟在 -webki ...
- 转载一篇nm命令使用的文章,虽然没用用这个方法解决但是文章很好
http://blog.csdn.net/acs713/article/details/13505931
- GTK+2.0学习——第一个GTK程序
#include <gtk/gtk.h> #include <stdio.h> #include <stdlib.h> /* *点击了关闭按钮之后的回调函数 *gt ...
- ASP.NET MVC Url中带点号出现404错误的解决方案
由于项目需求,项目的路由设计如下 config.Routes.MapHttpRoute( name: "Get/Put Sku", routeTemplate: "api ...
题目链接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 ...
新版C#编译器关于函数闭包的一处更改 在Visual Basic.NET中,如果你写下类似下面的代码: Public Sub Test() For i = 0 To 100 Dim func = ...
---恢复内容开始--- wget -m -e robots=off -U "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1 ...
Problem A.Ant on a Chessboard Background One day, an ant called Alice came to an M*M chessboard. She ...
以下文章摘录来自InfoQ,是一篇不错的软问,大家细细的品味 关键要点: Dapper这类微ORM(Micro-ORM)虽然提供了最好的性能,但也需要去做最多的工作. 在无需复杂对象图时,Chain这 ...
java 企业网站源码 前后台都有 静态模版引擎, 代码生成器大大提高开发效率 系统介绍 点击:获取地址 : 1.网站后台采用主流的 SSM 框架 jsp JSTL,网站后台采用freemaker静态 ...
#"包含了一个位置信息 默认的锚点是#top 也就是网页的上端 而javascript:void(0) 仅仅表示一个死链接 这就是为什么有的时候页面很长浏览链接明明是#可是跳动到了页首 而 ...
实例 让弹性盒元素在必要的时候拆行: display:flex; flex-wrap: wrap; 复制 效果预览 浏览器支持 表格中的数字表示支持该属性的第一个浏览器的版本号. 紧跟在 -webki ...
http://blog.csdn.net/acs713/article/details/13505931
#include <gtk/gtk.h> #include <stdio.h> #include <stdlib.h> /* *点击了关闭按钮之后的回调函数 *gt ...
由于项目需求,项目的路由设计如下 config.Routes.MapHttpRoute( name: "Get/Put Sku", routeTemplate: "api ...