hdu 4451 Dressing

本文探讨了通过画图来解决复杂算法问题的方法,展示了这种方法如何提供直观且易于理解的解决方案。同时,介绍了算法设计与实现的关键步骤,包括排序、动态规划等常见算法的应用。此外,还讨论了画图在调试和优化代码过程中的作用,以及如何通过画图提高编程效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

画个图是个明智的选择。

解法不唯一。

#include <iostream>
#include <vector>
#include <stack>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>

using namespace std;
/*  define */
#define sf(a) scanf("%d",&a)
#define sf3(a,b,c) scanf("%d%d%d",&(a),&(b),&(c))
#define sfs(a) scanf("%s",a)
#define clr(a) memset(a,0,sizeof(a))
#define pfI(a) printf("%I64d\n",a)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define rep1(i,a,b) for(int i=(a);i<(b);i++)
/*  define */

int gcd(int a,int b){
    return b==0?a:gcd(b,a%b);
}
typedef long long ll;

const int inf = (1<<29);

int hash1[1050],hash2[1050];

int main(){
    int n,m,k,p,x,y;
    char str1[50],str2[50];
    while(~sf3(n,m,k) && (n+m+k)){
        ll ans=n*m*k;
        sf(p);
        clr(hash1);
        clr(hash2);
        rep1(i,0,p){
            sfs(str1);
            sf(x);
            sfs(str2);
            sf(y);
            if(str1[0]=='c' && str2[0]=='p'){
                ans-=(ll)k;
                hash1[y]++;
            }
            else if(str1[0]=='p' && str2[0]=='s'){
                ans-=(ll)n;
                hash2[x]++;
            }
        }
        for(int i=1;i<=1000;i++){
            ans+=((ll)hash1[i]*(ll)hash2[i]);
        }
        pfI(ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值