一开始就想到网络流。。后来一想暴力能不能过。自己写的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. 笔记-scrapy-setting

    笔记-scrapy-setting 1.     简介 Scrapy设置允许您自定义所有Scrapy组件的行为,包括核心,扩展,管道和蜘蛛本身. 可以使用不同的机制来填充设置,每种机制都有不同的优先级 ...

  2. TouTiao开源项目 分析笔记2

    1.Constant常量定义类 1.1.源代码 public class Constant { public static final String USER_AGENT_MOBILE = " ...

  3. 20145202马超 《Java程序设计》第八周学习总结

    第十四章 NIO与NIO2 NIO使用频道(channel)来衔接数据节点,对数据区的标记提供了clear(),rewind(),flip(),compact()等高级操作. 想要取得channel的 ...

  4. 16 Django-admin管理工具

      admin组件使用 Django 提供了基于 web 的管理工具. Django 自动管理工具是 django.contrib 的一部分.你可以在项目的 settings.py 中的 INSTAL ...

  5. Spring 各种注解备注

    Spring 各种注解备注 felix_feng 关注 2016.12.28 10:34* 字数 2092 阅读 790评论 0喜欢 6 转载 (http://blog.csdn.net/sudilu ...

  6. pip 代理设置,坑爹的代理继续

    Linux ubuntu 3.2.0-23-generic-pae #36-Ubuntu SMP Tue Apr 10 22:19:09 UTC 2012 i686 i686 i386 GNU/Lin ...

  7. Jenkins拾遗--第二篇(初步配置Jenkins)

    插件配置 第一次安装Jenkins的时候会让你配置插件.这里有一个建议:就是把所有插件都看一遍,如果用不到,就不要勾选.Jenkins插件兼容性有的时候不是很好,多装多出事儿,保持最小集就好.浏览一遍 ...

  8. USACO Section1.3 Wormholes 解题报告

    wormhole解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------- ...

  9. day06_05 字典

    1.0 字典 1.1 补充知识:用id可以查找出变量的内存地址 a = 10 print(id(a)) #找出内存地址 #>>>506528496 b = 15 print(id(b ...

  10. HDU 1939 HE IS OFFSIDE

    He is offside! Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...