UVA 11045 My T-shirt suits me(网络流)


  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$ \ge$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 $ \neq$ 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 MN is multiple of 6, 1$ \le$N$ \le$36, and indicates the number of T-shirts. Number M1$ \le$M$ \le$30, indicates the number of volunteers, with N$ \ge$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

题意:有6种size的T-shirt,每种n / 6件,有m个人,每人有两种size可以穿,问能否所有人都穿到T-shirt

思路:写了两种,一种暴力,一种最大流

代码:

暴力枚举

#include <stdio.h>
#include <string.h>
const int M = 35;
const char size[6][10] = {"XS", "S", "M", "L", "XL", "XXL"};
int T, n, m, s[M][2], have[6];
char a[10], b[10];

int find(char *a) {
    for (int i = 0; i < 6; i ++)
	if (strcmp(size[i], a) == 0)
	    return i;
}
void init() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < 6; i ++)
	have[i] = n / 6;
    for (int i = 0; i < m; i ++) {
	scanf("%s%s", a, b);
	s[i][0] = find(a);
	s[i][1] = find(b);
    }
}

bool dfs(int start) {
    if (start == m)
	return true;
    for (int i = 0; i < 2; i ++) {
	if (have[s[start][i]]) {
	    have[s[start][i]] --;
	    if (dfs(start + 1)) return true;
	    have[s[start][i]] ++;
	}
    }
    return false;
}

void solve() {
    init();
    if (dfs(0)) printf("YES\n");
    else printf("NO\n");
}
int main() {
    scanf("%d", &T);
    while (T --) {
	solve();
    }
    return 0;
}

最大流

#include <stdio.h>
#include <string.h>
#define INF 0x3f3f3f3f
#include <queue>
using namespace std;
const char size[6][10] = {"XS", "S", "M", "L", "XL", "XXL"};

int T, n, m, g[50][50], f[50][50], p[50], a[50];
char str1[10], str2[10];
queue<int>q;

int find(char *a) {
    for (int i = 0; i < 6; i ++) {
	if (strcmp(a, size[i]) == 0)
	    return i;
    }
}

void init() {
    scanf("%d%d", &n, &m);
    memset(g, 0, sizeof(g));
    for (int i = m + 1; i <= m + 6; i ++)
	g[0][i] = n / 6;
    for (int i = 1; i <= m; i ++) {
	scanf("%s%s", str1, str2);
	g[find(str1) + m + 1][i] = 1;
	g[find(str2) + m + 1][i] = 1;
	g[i][m + 7] = 1;
    }
}

void solve() {
    init();
    int ans = 0, s = 0, t = m + 7;
    memset(f, 0, sizeof(f));
    while (1) {
	memset(a, 0, sizeof(a));
	a[s] = INF;
	q.push(s);
	while (!q.empty()) {
	    int u = q.front(); q.pop();
	    for (int v = 1; v <= t; v ++) {
		if (!a[v] && g[u][v] - f[u][v] > 0) {
		    a[v] = min(a[u], g[u][v] - f[u][v]);
		    q.push(v); p[v] = u;
		}
	    }
	}
	if (a[t] == 0) break;
	for (int u = t; u != s; u = p[u]) {
	    f[p[u]][u] += a[t];
	    f[u][p[u]] -= a[t];
	}
	ans += a[t];
    }
    if (ans < m) printf("NO\n");
    else printf("YES\n");
}

int main() {
    scanf("%d", &T);
    while (T --) {
	solve();
    }
    return 0;
}


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

余额充值