当前位置: 首页 > news >正文

VJ_Dressing_思维

VJ_Dressing_思维

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

InputcopyOutputcopy
 
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
 
8 6 5

// VJ_Dressing_思维
#include<bits/stdc++.h>
using namespace std;
#define int long long

const int N=1111;
int ab[N],bc[N];
char s1[N],s2[N];

signed main()
{
    int a,b,c,n,x,y,ans;

    while( ~scanf("%lld%lld%lld",&a,&b,&c ) && ( a+b+c ) )
    {
        ans=a*b*c;
        memset( ab,0,sizeof( ab ) );
        memset( bc,0,sizeof( bc ) );

        scanf("%lld",&n );
        while( n-- )
        {
            scanf("%s %lld %s %lld",s1,&x,s2,&y );
            if( s1[0]=='c' )  	{ ab[y]++; ans+=bc[y]-c; }      // y_is_b
            else                { bc[x]++; ans+=ab[x]-a; }      // x_is_b
        }
        printf("%lld\n",ans );
    }
    return 0;
}
// 01 推导公式
    // 抽象实例化 暴力确定实例的结果 由果导因 猜测公式
    // a(3) b(4) c(5)
    // n(5)
    // ab12    //
    // ab22
    // bc23    //
    // bc24
    // bc25
    // 2*3 重复

// 02 降低时间复杂度
    // 保存+遍历 时间复杂度太高 
    // 解决: 有没有一边读取一边计算的方法?
    // 最终的去重 是cnt_b1 cnt_b2的数量积 
    // 那么每次cnt++ 实际上就是对cnt'进行了去重 (cnt cnt'是对立面)

相关文章:

  • 关于我的vsc不能远程debug这件事
  • [English]英语积累本
  • java-php-python-ssm爱馨敬老院网站计算机毕业设计
  • 9.24 Day59---网络相关知识
  • [leetcode top100] 0924 找到数组中消失的数,合并二叉树,比特位计数,汉明距离
  • Java · 图书管理系统代码练习 · 抽象类 · 封装 · 继承 · 多态 · 接口
  • C语言 文件包含和条件编译
  • Vue入门【三】-- 详解computed计算属性
  • 线程池概念2
  • 一键部署设计稿至线上 —— D2C国产神器
  • 死锁检测实现
  • jsp杂草信息分类系统myeclipse开发sql数据库BS模式java编程网页结构serlvet技术mvc框架
  • 2022牛客多校(八)
  • jenkins 持续集成/项目部署
  • 彻底掌握Makefile(二)
  • 【附node操作实例】redis简明入门系列—字符串类型
  • co模块的前端实现
  • css布局,左右固定中间自适应实现
  • js面向对象
  • leetcode讲解--894. All Possible Full Binary Trees
  • Nacos系列:Nacos的Java SDK使用
  • nginx 负载服务器优化
  • nodejs:开发并发布一个nodejs包
  • Nodejs和JavaWeb协助开发
  • python大佬养成计划----difflib模块
  • 爱情 北京女病人
  • 从tcpdump抓包看TCP/IP协议
  • 动态魔术使用DBMS_SQL
  • 欢迎参加第二届中国游戏开发者大会
  • 体验javascript之美-第五课 匿名函数自执行和闭包是一回事儿吗?
  • 想使用 MongoDB ,你应该了解这8个方面!
  • 延迟脚本的方式
  • 优化 Vue 项目编译文件大小
  • 你学不懂C语言,是因为不懂编写C程序的7个步骤 ...
  • (13)[Xamarin.Android] 不同分辨率下的图片使用概论
  • (20050108)又读《平凡的世界》
  • (办公)springboot配置aop处理请求.
  • (附源码)springboot家庭财务分析系统 毕业设计641323
  • (附源码)计算机毕业设计ssm本地美食推荐平台
  • (简单) HDU 2612 Find a way,BFS。
  • (使用vite搭建vue3项目(vite + vue3 + vue router + pinia + element plus))
  • (算法)求1到1亿间的质数或素数
  • (新)网络工程师考点串讲与真题详解
  • ./configure、make、make install 命令
  • .NET / MSBuild 扩展编译时什么时候用 BeforeTargets / AfterTargets 什么时候用 DependsOnTargets?
  • .NET/C# 使用反射调用含 ref 或 out 参数的方法
  • .net开源工作流引擎ccflow表单数据返回值Pop分组模式和表格模式对比
  • @entity 不限字节长度的类型_一文读懂Redis常见对象类型的底层数据结构
  • @RequestParam,@RequestBody和@PathVariable 区别
  • [.NET]桃源网络硬盘 v7.4
  • [AIGC] 开源流程引擎哪个好,如何选型?
  • [C]编译和预处理详解
  • [CDOJ 838]母仪天下 【线段树手速练习 15分钟内敲完算合格】
  • [delphi]保证程序只运行一个实例
  • [ERROR ImagePull]: failed to pull image k8s.gcr.io/kube-controller-manager失败