Description

Problem D

The Grand Dinner

Input: standard input

Output: standard output

Time Limit: 15 seconds

Memory Limit: 32 MB

Each team participating in this year’s ACM World Finals contest is expected to join the grand dinner to be arranged after the prize giving ceremony ends. In order to maximize the interaction among the members of different teams, it is expected
that no two members of the same team sit at the same table.

Now, given the number of members in each team (including contestants, coaches, reserves, guests etc.) and the seating capacity of each available table, you are to determine whether it is possible for the teams to sit as described in the previous paragraph.
If such an arrangement is possible you must also output one possible seating arrangement. If there are multiple possible arrangements, any one is acceptable.

Input

The input file may contain multiple test cases. The first line of each test case contains two integers
M (1 £M£ 70) and N (1 £N£ 50) denoting the number of teams and the number of tables respectively. The second line of the test case contains
M integers where the i-th (1 £i£M) integer
mi (1 £mi£ 100) indicates the number of members of team
i. The third line contains N integers where the
j-th (1 £j£N) integer nj (2 £nj£ 100) indicates the seating capacity of table
j.

A test case containing two zeros for M and N terminates the input.

Output

For each test case in the input print a line containing either 1 or
0 depending on whether or not there exists a valid seating arrangement of the team members. In case of a successful arrangement print
M additional lines where the i-th (1 £i£ M) of these lines contains a table number (an integer from
1 to N) for each of the members of team
i
.

 

Sample Input

4 5

4 5 3 5

3 5 2 6 4

4 5

4 5 3 5

3 5 2 6 3

0 0

 

 

Sample Output

1

1 2 4 5

1 2 3 4 5

2 4 5

1 2 3 4 5

0

题意:有m个队伍,n个桌子,要求每一个队伍里的人不能出如今同一个桌子上,问是否有这样的可能

思路:贪心的每次将桌子能坐的人排序,从大的往小的坐

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 110; struct Node {
int id, num;
bool operator <(const Node &a) const {
return num > a.num;
}
} a[maxn], b[maxn]; struct team {
int index[maxn];
} res[maxn];
int n, m;
int tmp[maxn]; int main() { while (scanf("%d%d", &m, &n) != EOF && n+m) {
int flag = 1;
for (int i = 1; i <= m; i++) {
scanf("%d", &a[i].num);
tmp[i] = a[i].num;
a[i].id = i;
if (a[i].num > n)
flag = 0;
}
for (int i = 1; i <= n; i++) {
scanf("%d", &b[i].num);
b[i].id = i;
}
for (int i = 1; i <= m && flag; i++) {
sort(b+1, b+1+n);
for (int j = 1; j <= a[i].num; j++) {
if (b[j].num > 0) {
res[a[i].id].index[j] = b[j].id;
b[j].num--;
}
else {
flag = 0;
break;
}
}
}
if (!flag) {
printf("0\n");
continue;
}
printf("1\n");
for (int i = 1; i <= m; i++) {
sort(res[i].index+1, res[i].index+1+tmp[i]);
for (int j = 1; j <= tmp[i]; j++) {
if (j == 1)
printf("%d", res[i].index[j]);
else printf(" %d", res[i].index[j]);
}
printf("\n");
}
}
return 0;
}

UVA - 10249 The Grand Dinner的更多相关文章

  1. (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

    http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...

  2. ACM训练计划step 1 [非原创]

    (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...

  3. 算法竞赛入门经典+挑战编程+USACO

    下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...

  4. UVA 10217 A Dinner with Schwarzenegger!!!---数学

    题目链接: https://cn.vjudge.net/problem/UVA-10217 题目大意: 有若干人排队买电影票,如果某个人的生日与排在他前面的某个人的生日相同,那么他讲中奖.中奖的机会只 ...

  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. 关于史考特证券(scottrade Inc)资金转出的手续费问题

    投资美股账户的朋友可能开始的时候并没有关心史考特账户转出的费用,其实,仔细算一下这个费用还是蛮贵的,根据官网的文档可以明确知道,转出史考特账户资金到国内银行的费用由以下几项组成: 1. 国际电汇资金费 ...

  2. 浅谈web移动端适配问题

    一.布局方案 目前在解决移动端页面适配问题方案选择上,目前用得比较多是百分比布局,弹性布局flex,rem布局,本文将重点跟大家探讨rem布局. 二.viewport 在介绍rem布局之前,首先跟大家 ...

  3. idea 新建的xml文件显示为文本问题

    由于是新手 在用idea 中出现了 显示问题,一开始 都随它去 ,结果发现几次 都一样 由于 mybatis配置的config 我都命名为 mybatis-config.xml 网上搜索了下 没有搜到 ...

  4. 最大流——Dinic算法

    前面花了很长时间弄明白了压入-重标记的各种方法,结果号称是O(V3)的算法测demo的时候居然TLE了一个点,看了题解发现所有人都是用Dinic算法写的,但它的复杂度O(V2E)明显高于前者,具体是怎 ...

  5. hibernate flushMode 错误

    1 十一月 15, 2017 10:13:36 上午 org.apache.struts2.dispatcher.Dispatcher error 2 严重: Exception occurred d ...

  6. (转)Ubuntu 12.04 中安装和配置 Java JDK

    http://www.cnblogs.com/bluestorm/archive/2012/05/10/2493592.html 先去 Oracle下载Linux下的JDK压缩包,我下载的是jdk-7 ...

  7. Python之re正则模块二

    13.编译的标志 可以用re.I.re.M等参数,也可以直接在表达式中添加"?(iLmsux)"标志 *s:单行,“.”匹配包括换行符在内的所有字符 *i:忽略大小写 *L:让&q ...

  8. 第二个MapReduce

    大家在学习Hadoop的MapReduce的时候,90%的第一个程序都是WordCount,所以在这里分享一下我的第二个MapReduce程序.对于学习编程语言的人来说,有时候代码是最好的沟通方式之一 ...

  9. 斯坦福大学自然语言处理第一课——引言(Introduction)

    一.课程介绍 斯坦福大学于2012年3月在Coursera启动了在线自然语言处理课程,由NLP领域大牛Dan Jurafsky 和 Chirs Manning教授授课:https://class.co ...

  10. Java学习笔记17---方法的重载与重写

    重载是指,一个类中定义了一个成员方法后,通过修改参数个数.参数类型或参数顺序,重新实现该方法,则这两个方法互为对方的重载方法. 重写是指,子类重新实现父类的成员方法. 重载后的方法,与原方法相比: ( ...