一开始就想到网络流。。后来一想暴力能不能过。自己写的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. Linux两种方式rd.break和init重置root管理员密码

    centos7/rhel7进入单用户方式和重置密码方式发生了较大变化,GRUB由b引导变成了ctrl+x引导. 重置密码主要有rd.break和init两种方法. rd.break方法: 1.启动的时 ...

  2. Eclipse+Tomcat7.0+MySQL 连接池设置

    http://blog.sina.com.cn/s/blog_85d71fb70101ab99.html 工程名:JavaWeb 第一步:配置server.xml 在Tomcat的server.xml ...

  3. 小白日记54:kali渗透测试之Web渗透-补充概念(AJAX,WEB Service)

    补充概念 AJAX(异步javascript和XML) Asynchronous javascript and xml 是一个概念,而非一种新的编程语言,是一组现有技术的组合 通过客户端脚本动态更新页 ...

  4. Enhacing the content with JavaScript

    What not to do :  In theory , you could use JavaScript to add important content to a web page. Howev ...

  5. Android 布局错乱 Android花屏

    最近做项目,妈的,有个一个很难受的bug. 这个bug ,自己这里没有手机,没有办法复现,找到了手机之后.解决了. 我先给大家看下什么叫布局错乱,花屏: 来张正常的图片: 正常情况下是这样的.然后, ...

  6. python 10月30日复习

    1.把一个数字的list从小到大排序,然后写入文件,然后从文件中读取出来文件内容,然后反序,在追加到文件的下一行中 import codecs list1 = [2,23,8,54,86,12] li ...

  7. Java设计模式-----装饰者

    对方法做增强,并不能添加新的接口方法.

  8. Grub Rescue修复方法[repost]

    From : http://www.2cto.com/os/201111/112327.html 症状:开机显示:GRUB loading error:unknow filesystem grub r ...

  9. Python全栈工程师(每周总结:3)

     ParisGabriel                                                           每天坚持 一天一篇 点个订阅吧  灰常感谢    当个死 ...

  10. (原)Unreal 渲染模块 渲染流程

    @author:白袍小道 浏览分享随缘,评论不喷亦可.     扯淡部分: 在temp中,乱七八糟的说了下大致的UE过程.下面我们还是稍微别那么任性,一步步来吧.     UE渲染模块牵扯到场景遍历. ...