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

    注意事项: 不要轻易中途变换思路修改代码 发现有样例无法通过可以用if强行通过 注意输入输出形式(long long为lld,无符号为llu). 开过1亿的int型数组 Long long能读入输出1 ...

  2. Android 渗透小知识点

    客户端用于 ADB 通信的默认端口始终是 5037,设备使用从 5555 到 5585 的端口 adb devices用于显示所有已连接设备, 有时候会出现一些问题, 这时候需要使用adb kill- ...

  3. android 布局preview 技巧

    最近开始看老外写的文章,博客,嗯,不能说比国人写的好,但是感觉看着很爽.真的,一手资料就是爽. 嗯,自己做得不错,第一次看外文博客,我知道自己怎么看的,一句话一句话看下来的,越看越有感觉. 下面这个 ...

  4. USACO Section1.1 Broken Necklace 解题报告

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

  5. apache的/etc/httpd/conf/httpd.conf和/usr/local/apache2/conf/httpd.conf区别

    一.问题 centos系统用yum安装完apache后,重启后有时会失效,然后去网上找资料,发现有的说重启命令是这样的: /etc/init.d/httpd restart 而有的呢,说重启命令应该是 ...

  6. XSS注入常用语句积累

    <script>alert('hello,gaga!');</script> //经典语句,哈哈! >"'><img src="javas ...

  7. 自动化测试(二)如何用python写一个用户登陆功能

    需求信息: 写一个判断登录的程序: 输入: username password 最大错误次数是3次,输入3次都没有登录成功,提示错误次数达到上限 需要判断输入是否为空,什么也不输入,输入一个空格.n个 ...

  8. python 学习分享-socketserver

    SocketServer内部使用 IO多路复用 以及 “多线程” 和 “多进程” ,从而实现并发处理多个客户端请求的Socket服务端.即:每个客户端请求连接到服务器时,Socket服务端都会在服务器 ...

  9. spring boot打war包启动Tomcat失败

    Tomcat启动失败:最后一个causy by :java.lang.NoSuchMethodError: org.apache.tomcat.util.res.StringManager.getMa ...

  10. codebolocks 中文使用手册1.1

    Code::Blocks手册 使用篇 中文翻译版- 原手册下载:http://www.codeblocks.org/docs/manual_en.pdf 译者:JGood 译者言:工欲善其事,必先利其 ...