UVa 11045 - My T-shirt suits me(最大流)

题目转的有点远,不过如果对最大流问题比较熟悉的话也不难看出问题的本质。

下面描述建图过程。

1、设一个原点0,1到6为六种型号衣服对应的点,然后7到m+6是m个人对应的点,最后一个点m+7对应终结点。

2、原点到型号点的容量为n/6(根据题意),一个人对应两种型号衣服,每条线的容量都是1(每个人对应两种衣服),最后每个人到终点的容量都为1(每个人只需要一件衣服)。这样图就建好了。

#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;

const int N = 40;
const int inf = 1000000;
int n, m, T, s, t;
int cap[N][N], flow[N][N], p[N];

int maxFlow()
{
    queue<int> q;
    int ans = 0, a[N];
    while(true)
    {
        q.push(s);
        memset(a, 0, sizeof(a) );
        a[s] = inf;
        while (!q.empty())
        {
            int u = q.front(); q.pop();
            for ( int i = 0; i <= t; ++i )
            {
                if ( !a[i] && cap[u][i] > flow[u][i] )
                {
                    p[i] = u; q.push(i);
                    a[i] = min( a[u], cap[u][i] - flow[u][i] );
                }
            }
        }
        if ( a[t] == 0 )
            break;
        for ( int i = t; i != s; i = p[i] )
        {
            flow[p[i]][i] += a[t];
            flow[i][p[i]] -= a[t];
        }
        ans += a[t];
    }
    return ans;
}
int num( string s )
{
    if ( s == "XS" ) return 1;
    else if ( s == "S") return 2;
    else if ( s == "M") return 3;
    else if ( s == "L") return 4;
    else if ( s == "XL") return 5;
    else if ( s == "XXL") return 6;
}
int main()
{
    cin>>T;
    while ( T-- )
    {
        cin>>n>>m;
        s = 0, t = m + 7;
        int f = n / 6;
        memset(flow, 0, sizeof(flow));
        memset(cap, 0, sizeof(cap));
        for ( int i = 7; i <= 6 + m; ++i )
        {
            string a, b;
            cin >> a >> b;
            cap[num(a)][i] = 1;
            cap[num(b)][i] = 1;
            cap[i][t] = 1;
        }
        for ( int i = 1; i <= 6; ++i )
            cap[0][i] += f;
        int ans = maxFlow();
        if (ans < m)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }
    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的evaluate-hand函数的示例,它可以评估德州扑克中的手牌强度: ```clojure (defn evaluate-hand [hand board] (let [cards (concat hand board) suits (map first cards) ranks (map second cards) count-ranks (frequencies ranks) flush-suit (some #(if (>= % 5) %) (vals (frequencies suits)))] (cond (and flush-suit (= (count board) 5)) ;; Flush (+ 500 (apply max ranks)) (some #(= % 4) count-ranks) ;; Four-of-a-kind (+ 400 (first (->> count-ranks (filter #(= (val %) 4)) first))) (and (some #(= % 3) count-ranks) (some #(= % 2) count-ranks)) ;; Full house (+ 300 (* 10 (first (->> count-ranks (filter #(= (val %) 3)) first))) (first (->> count-ranks (filter #(= (val %) 2)) first))) (and flush-suit (= (count board) 5)) ;; Flush (+ 200 (apply max ranks)) (let [straight-ranks (->> ranks (distinct) sort (partition-by #(apply - %) identity) (filter #(>= (count %) 5)) first)] (when straight-ranks (if (= (count straight-ranks) 1) ;; Straight (+ 100 (last straight-ranks)) ;; Straight flush (+ 800 (last straight-ranks))))) (some #(= % 3) count-ranks) ;; Three-of-a-kind (+ 50 (first (->> count-ranks (filter #(= (val %) 3)) first))) (let [pairs (->> count-ranks (filter #(= (val %) 2)) keys)] (cond (= (count pairs) 2) ;; Two pairs (+ 30 (* 10 (apply max pairs)) (apply min pairs)) (= (count pairs) 1) ;; One pair (+ 10 (first pairs)) :else ;; High card (apply max ranks)))))) ``` 该函数首先将手牌和公共牌组合成一副牌,并将其分成花色和点数两个部分。然后,它计算每个点数的出现次数,并检查是否有同花色的牌。根据规则集,它为每种情况分配一个分数,并返回最终的分数。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值