一开始就想到网络流。。后来一想暴力能不能过。自己写的T了。看了别人有暴力过的。

暴力的思路就是6进制数字表示给予的衣服的数量。然后每个人的需求表示成01 的6位串然后爆搜。

网络流就建一个源一个汇 然后针对输入 i  - i + 6 边权为N/6; 然后M个人由衣服连M个人边权为1。与源直接相连的点就INF求最大流值判断即可。

别人的建图更简单一些。不需要设置INF;思路一样

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
int src,tag;
int N,M;
const int INF = 0x3f3f3f3f ;
char size[][] = {"xxa","XXL","XL","L","M","S","XS"};
int d[],cap[][];
bool inq[];
int flow[][];
int p[];
void read()
{
scanf("%d%d",&N,&M);
N /= ;
memset(cap,,sizeof(cap));
for (int i = ; i <= ; i++) { cap[][i] = INF; cap[i][i + ] = N; }
for (int j = ; j <= M; j++)
{
char a[],b[];
scanf("%s%s",a,b);
int s1 = -, s2;
for (int i = ; i <= ; i++)
{
if (strcmp(size[i],a) == )
s1 = i;
if (strcmp(size[i],b) == )
s2 = i;
}
//printf("%d %d\n",s1,s2);
cap[s1 + ][ + j] = ;
cap[s2 + ][ + j] = ;
cap[ + j][ + M + ] = ;
}
src = ;
tag = + M + ;
}
int Edmons_karp()
{
queue<int>q;
int a[];
while (!q.empty()) q.pop();
memset(flow,,sizeof(flow));
int ans = ;
while (true)
{
memset(a,,sizeof(a));
a[src] = INF;
q.push(src);
while(!q.empty())
{
int u = q.front(); q.pop();
for (int v = ; v <= tag; v++)
if (!a[v] && cap[u][v] > flow[u][v])
{
p[v] = u;
q.push(v);
a[v] = min(a[u],cap[u][v] - flow[u][v]);
}
}
if (a[tag] == ) break;
for (int u = tag; u != src; u = p[u])
{
flow[p[u]][u] += a[tag];
flow[u][p[u]] -= a[tag];
}
ans += a[tag];
}
return ans;
}
int main()
{
//freopen("sample.txt","r",stdin);
int T;
scanf("%d",&T);
while (T--)
{
read();
int ans = Edmons_karp();
//printf("%d\n",ans);
if (ans >= M) printf("YES\n");
else printf("NO\n");
}
return ;
}

TLE 的代码也贴一下吧

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
int st[];
int N,M;
bool found;
char size[][] = {"XXL","XL","L","M","S","XS"};
int res;
void read()
{
res = ;
scanf("%d%d",&N,&M);
N /= ;
char tmp[];
for (int i = ; i < ; i++)
tmp[i] = N + '';
tmp[] = '\0';
sscanf(tmp,"%d",&res);
memset(st,,sizeof(st));
for (int i = ; i <= M; i++)
{
char a[],b[];
scanf("%s%s",a,b);
int j;
for (j = ; j < ; j++) if (strcmp(a,size[j]) == ) break;
st[i] |= << j;
for (j = ; j < ; j++) if (strcmp(b,size[j]) == ) break;
st[i] |= << j;
}
}
void calcu(int cur, int sta, int cnt)
{
if (found) return ;
if (cnt >= M) { found = true; return ; }
int temp = sta;
bool change = false;
char str[];
for (int i = cur; i <= M; i++)
{
int a = -,b = -;
for (int j = ; j < ; j++)
{
if (st[i] & ( << j))
{
if (a == -)
{
a = j;
}
else
b = j;
}
}
sprintf(str,"%d",temp);
if (str[a] - '' > )
{
change = true;
str[a]--;
sscanf(str,"%d",&temp);
calcu(cur + , temp, cnt + );
str[a]++;
}
temp = sta;
if (str[b] - '' > )
{
change = true;
str[b]--;
sscanf(str,"%d",&temp);
calcu(cur + , temp, cnt + );
str[b]++;
}
if (!change) return ;
}
}
int main()
{
//freopen("sample.txt","r",stdin);
int T;
scanf("%d",&T);
while (T--)
{
found = false;
read();
calcu(,res,);
if (found) printf("YES\n");
else printf("NO\n");
}
return ;
}

UVA 11045 My T-shirt suits me的更多相关文章

  1. UVa 11045 My T-shirt suits me / 二分图

    二分图建图 判断是否是完全匹配就行 最大流也行 #include <cstdio> #include <cstring> const int MAX = 300; int a[ ...

  2. Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 7. Graph Algorithms and Implementation Techniques

    uva 10803 计算从任何一个点到图中的另一个点经历的途中必须每隔10千米 都必须有一个点然后就这样 floy 及解决了 ************************************* ...

  3. UVA 11045-My T-shirt suits me(二分图匹配)

    题意:有N件T恤,N是6的倍数,因为有6种型号,每种件数相同,有M个人,每个人有两种型号的T恤适合他,每个人可以挑其中的一种,问能否所有的人都能分配到T恤. 解析:典型的二分图匹配,每N/6为同种T恤 ...

  4. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  5. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  6. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  7. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  8. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  9. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

随机推荐

  1. [回文树][BZOJ2160][国家集训队]拉拉队排练

    题面 Description 艾利斯顿商学院篮球队要参加一年一度的市篮球比赛了.拉拉队是篮球比赛的一个看点,好的拉拉队往往能帮助球队增加士气,赢得最终的比赛.所以作为拉拉队队长的楚雨荨同学知道,帮助篮 ...

  2. Spark&Hive结合起来

    1.spark与Hive结合起来 前提:当你spark的版本是1.6.1的时候,你的Hive版本要1.2.1,用别的版本会有问题 我们在做的时候,Hive的版本很简单,我们只需要解压缩,告诉他Hive ...

  3. 第四模块:网络编程进阶&数据库开发 口述

    进程即正在执行的一个过程.进程是对正在运行程序的一个抽象. 子进程死了之后 ,父进程关闭的时候要清理掉子进程的僵尸进程(收尸),孤儿进程是指父进程先死掉了的,交给init管理. join() 等待子进 ...

  4. 1082: [SCOI2005]栅栏

    链接 思路 二分+搜索+剪枝. 首先二分一个答案,表示最多可以切出x块.(一个结论:切出的一定是从较小的前x块.如果一个木材可以满足很多个需要的木材,那么切出最小的,就意味着以后再选时的机会更多.) ...

  5. 【活动】参加葡萄城控件主办的“谁是报表达人”知识评测活动,赢取iPad Mini2

    一.参与资格 从事报表开发的博客园用户 二.活动时间 4月1日-4月30日 三. 活动形式 在活动期间,活动参与者只要回答从题库中随机抽出的与报表相关的六道题,就可以知道自己的报表知识等级.同时活动主 ...

  6. leetcode 【 Linked List Swap Nodes in Pairs 】 python 实现

    题目: Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For ...

  7. 一个初学者的辛酸路程-jQuery

    前言: 主要概要: 1.HTML+CSS补充 2.DOM事件 3.jQuery示例 内容概要: 1.布局 代码如下 <!DOCTYPE html> <html lang=" ...

  8. Lua1

    使用lua进行脚本编程有很多优点: 1 代码体积小 2 执行速度快 3 安全性较高等 4 但是最大的优点是修改后的代码不需要重新编译即可生效,而高级语言的代码经过修改后需要经过重新编译或者解释后才能生 ...

  9. wxPython 界面编程的有关事件

    在事件处理的过程中涉及四个要素: 1.事件. 它是用户对界面的操作,在wxPython中事件被封装成事件类wx.Event及其子类,例如按钮事件类wx.CommandEvent,鼠标事件类是wx.Mo ...

  10. python 多版本的兼容

    1.针对linux版本 linux版本的话,首先调用whereis python 来获取到多版本的路径. root@Ulord-14:~# whereis pythonpython: /usr/bin ...