uva 11045 My T-shirt suits me

原题:
Our friend Victor participates as an instructor in an environmental volunteer program. His boss asked Victor to distribute N T-shirts to M volunteers, one T-shirt each volunteer, where N is multiple of six, and N ≥ M. There are the same number of T-shirts of each one of the six available sizes: XXL, XL, L, M , S, and XS. Victor has a little problem because only two sizes of the T-shirts suit each volunteer. You must write a program to decide if Victor can distribute T-shirts in such a way that all volunteers get a T-shirt that suit them. If N ̸= M, there can be some remaining T-shirts.
Input
The first line of the input contains the number of test cases. For each test case, there is a line with two numbers N and M. N is multiple of 6, 1 ≤ N ≤ 36, and indicates the number of T-shirts. Number M, 1 ≤ M ≤ 30, indicates the number of volunteers, with N ≥ M. Subsequently, M lines are listed where each line contains, separated by one space, the two sizes that suit each volunteer (XXL, XL, L, M , S, or XS).
Output
For each test case you are to print a line containing ‘YES’ if there is, at least, one distribution where T-shirts suit all volunteers, or ‘NO’, in other case.
Sample Input
3
18 6
L XL
XL L
XXL XL
S XS
M S
M L
6 4
S XL
L S
L XL
L XL
6 1
L M
Sample Output
YES
NO
YES

中文:
(来自lucky 猫)
我們的朋友Victor參加一個環保團體。它的老闆要他把 N 件 T-shirt 分給 M 個義工,每人一件。在這裡 N 一定是 6 的倍數,且 N >= M。T-shirt 有6種 size, 分別是:XXL, XL, L, M, S, XS。每種 size T-shirt 的數量都一樣。現在 Victor 有一個小問題,因為每個義工都只有2種 T-shirt 的 size 適合他。

你必須寫一個程式來決定是否 Victor 可以發給每個義工一件適合他們的 T-shirt。假如 N 不等於 M,那可以有一些 T-shirt 剩下。

Input

輸入的第一列有一個整數代表以下有幾組測試資料。每組測試資料的第一列有2個正整數 N, M。N 是 6 的倍數,1 <= N <= 36, 代表 T-shirt 的數目。M ,1 <= M <= 30,代表義工的數目,N >= M。接下來的 M 列,每列有2個 size,分別代表各義工適合的 size。

Output

每組測試資料輸出一列,輸出能否發給每個義工一件適合他們的 T-shirt。

#include <bits/stdc++.h>
using namespace std;
const int maxn=100;
const int inf=100000;
int n,m;
struct Edge
{
    int from,to,cap,flow;
    Edge(int u,int v,int c,int f):from(u),to(v),cap(c),flow(f) {}
};
struct EdmondsKarp
{
    int n,m;
    vector<Edge> edges;
    vector<int> G[maxn];
    int a[maxn];
    int p[maxn];

    void init(int n)
    {
        for(int i=0;i<=n;i++)
            G[i].clear();
        edges.clear();
    }

    void AddEdge(int from,int to,int cap)
    {
        edges.push_back(Edge(from,to,cap,0));
        edges.push_back(Edge(to,from,0,0));
        m=edges.size();
        G[from].push_back(m-2);
        G[to].push_back(m-1);
    }

    int Maxflow(int s,int t)
    {
        int flow=0;
        while(true)
        {
            memset(a,0,sizeof(a));
            queue<int> Q;
            Q.push(s);
            a[s]=INT_MAX;
            while(!Q.empty())
            {
                int x=Q.front();
                Q.pop();
                for(int i=0;i<G[x].size();i++)
                {
                    Edge& e = edges[G[x][i]];
                    if(!a[e.to]&&e.cap>e.flow)
                    {
                        p[e.to]=G[x][i];
                        a[e.to]=min(a[x],e.cap-e.flow);
                        Q.push(e.to);
                    }
                }
                if(a[t])
                    break;
            }
            if(!a[t])
                break;
            for(int u=t;u!=s;u=edges[p[u]].from)
            {
                edges[p[u]].flow+=a[t];
                edges[p[u]^1].flow-=a[t];
            }
            flow+=a[t];
        }
        return flow;
    }
};

int get_node(string s)
{
    if(s=="L")
        return 31;
    if(s=="M")
        return 32;
    if(s=="S")
        return 33;
    if(s=="XS")
        return 34;
    if(s=="XL")
        return 35;
    if(s=="XXL")
        return 36;
}

EdmondsKarp EK;
int main()
{
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--)
    {
        EK.init(50);
        cin>>n>>m;
        for(int i=1;i<=6;i++)
            EK.AddEdge(30+i,37,n/6);
        for(int i=1;i<=m;i++)
        {
            string s1,s2;
            cin>>s1>>s2;
            int n1=get_node(s1);
            int n2=get_node(s2);
            EK.AddEdge(i,n1,1);
            EK.AddEdge(i,n2,1);
            EK.AddEdge(0,i,1);
        }
        int ans=EK.Maxflow(0,37);
//        cout<<ans<<endl;
        if(ans==m)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;

    }
    return 0;
}

思路:

二分图问题,可以用匈牙利算法解决,也可以用最大流方法解决。
使用最大流方法的思路如图所示
以样例数据中的第二个为例子
S是源点,T是汇点,红圈代表员工,篮圈代表衣服,红圈和篮圈
源点到员工的容量标记为1,表示每个员工只能选一个衣服,每个员工到衣服之间同样标记为容量1,表示每人只能选一件衣服,衣服到汇点的容量用每件衣服的总数量表示
最后判断衣服的数量(也就是得到的最大流)和员工的数量是否相等即可
这里写图片描述

  • 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、付费专栏及课程。

余额充值