A. Toda 2
time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

A group of n friends enjoys playing popular video game Toda 2. There is a rating system describing skill level of each player, initially the rating of the i-th friend is ri.

The friends decided to take part in the championship as a team. But they should have equal ratings to be allowed to compose a single team consisting of all n friends. So the friends are faced with the problem: how to make all their ratings equal.

One way to change ratings is to willingly lose in some matches. Friends can form a party consisting of two to five (but not more than n) friends and play a match in the game. When the party loses, the rating of each of its members decreases by 1. A rating can't become negative, so ri = 0 doesn't change after losing.

The friends can take part in multiple matches, each time making a party from any subset of friends (but remember about constraints on party size: from 2 to 5 members).

The friends want to make their ratings equal but as high as possible.

Help the friends develop a strategy of losing the matches so that all their ratings become equal and the resulting rating is maximum possible.

Input

The first line contains a single integer n (2 ≤ n ≤ 100) — the number of friends.

The second line contains n non-negative integers r1, r2, ..., rn (0 ≤ ri ≤ 100), where ri is the initial rating of the i-th friend.

Output

In the first line, print a single integer R — the final rating of each of the friends.

In the second line, print integer t — the number of matches the friends have to play. Each of the following t lines should contain ncharacters '0' or '1', where the j-th character of the i-th line is equal to:

  • '0', if friend j should not play in match i,
  • '1', if friend j should play in match i.

Each line should contain between two and five characters '1', inclusive.

The value t should not exceed 104, it is guaranteed that such solution exists.

Remember that you shouldn't minimize the value t, but you should maximize R. If there are multiple solutions, print any of them.

思路:贪心;

因为可以同时操作2-5个,那么我们只要讨论时操作2个或三个就行了因为2,3能组成其他数,然后每次分类,当当前的数有偶数个,那么每次操作2个,当前为1的时候也操作2个,否则操作3个,并且选出的是最大的,这个用优先队列维护。

  1 #include<stdio.h>
2 #include<algorithm>
3 #include<stdlib.h>
4 #include<queue>
5 #include<string.h>
6 #include<iostream>
7 #include<math.h>
8 using namespace std;
9 typedef struct node
10 {
11 int id;
12 int cost;
13 bool operator<(const node&cx)const
14 {
15 return cx.cost > cost;
16 }
17 } ss;
18 int ans[1000];
19 int ab[10005][105];
20 priority_queue<ss>que;
21 int flag[1005];
22 int main(void)
23 {
24 int n;
25 scanf("%d",&n);
26 int i,j;
27 for(i = 0; i < n; i++)
28 {
29 scanf("%d",&ans[i]);
30 }
31 memset(ab,0,sizeof(ab));
32 while(!que.empty())
33 que.pop();
34 memset(flag,0,sizeof(flag));
35 int cn = 0;
36 for(i = 0; i < n; i++)
37 {
38 if(!flag[ans[i]])
39 {
40 cn++;
41 }
42 flag[ans[i]]++;
43 ss ak;
44 ak.cost = ans[i];
45 ak.id = i;
46 que.push(ak);
47 }
48 int cnt = 0;
49 while(cn>1)
50 {
51 ss a = que.top();
52 que.pop();
53 ss b = que.top();
54 que.pop();
55 if(a.cost!=b.cost)
56 {
57 if(a.cost>0)
58 {
59 flag[a.cost]--;
60 if(flag[a.cost]==0)cn--;
61 if(flag[a.cost-1]==0)cn++;
62 a.cost--;
63 flag[a.cost]++;
64 }
65 if(b.cost>0)
66 {
67 flag[b.cost]--;
68 if(flag[b.cost]==0)cn--;
69 if(flag[b.cost-1]==0)cn++;
70 b.cost--;
71 flag[b.cost]++;
72 }
73 ab[cnt][a.id]++;
74 ab[cnt][b.id]++;
75 }
76 else if(flag[a.cost]%2==0)
77 {
78 if(a.cost>0)
79 {
80 flag[a.cost]--;
81 if(flag[a.cost]==0)cn--;
82 if(flag[a.cost-1]==0)cn++;
83 a.cost--;
84 flag[a.cost]++;
85 }
86 if(b.cost>0)
87 {
88 flag[b.cost]--;
89 if(flag[b.cost]==0)cn--;
90 if(flag[b.cost-1]==0)cn++;
91 b.cost--;
92 flag[b.cost]++;
93 }
94 ab[cnt][a.id]++;
95 ab[cnt][b.id]++;
96 }
97 else
98 {
99 ss c = que.top();
100 que.pop();
101 if(a.cost>0)
102 {
103 flag[a.cost]--;
104 if(flag[a.cost]==0)cn--;
105 if(flag[a.cost-1]==0)cn++;
106 a.cost--;
107 flag[a.cost]++;
108 }
109 if(b.cost>0)
110 {
111 flag[b.cost]--;
112 if(flag[b.cost]==0)cn--;
113 if(flag[b.cost-1]==0)cn++;
114 b.cost--;
115 flag[b.cost]++;
116 }
117 if(c.cost>0)
118 {
119 flag[c.cost]--;
120 if(flag[c.cost]==0)cn--;
121 if(flag[c.cost-1]==0)cn++;
122 c.cost--;
123 flag[c.cost]++;
124 }ab[cnt][c.id]++;
125 ab[cnt][a.id]++;
126 ab[cnt][b.id]++;
127 que.push(c);
128 }
129 cnt++;
130 que.push(a);
131 que.push(b);
132 }
133 int x = que.top().cost;
134 printf("%d\n",x);
135 printf("%d\n",cnt);
136 for(i = 0;i < cnt;i++)
137 {
138 for(j = 0;j < n;j++)
139 {
140 if(j == 0)
141 printf("%d",ab[i][j]);
142 else printf("%d",ab[i][j]);
143 }
144 printf("\n");
145 }
146 return 0;
147 }

代码库

A. Toda 2的更多相关文章

  1. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest A. Toda 2 贪心 + 暴力

    A. Toda 2 time limit per test 2 seconds memory limit per test 512 megabytes input standard input out ...

  2. CodeForces 730A Toda 2 (模拟)

    题意:给定一个序列,现在你每次至多给5个人的权值减小1,最少2个人,最小是0,使得剩下的所有权值都相等且尽量大. 析:用multiset来模拟,每次取权值最大的三个或者两个,直到最后相等.我开始没有这 ...

  3. Codeforces 730A:Toda 2(multiset模拟)

    http://codeforces.com/problemset/problem/730/A 题意:有n个人打天梯,想让这n个人的分数相同,每场比赛必须有2-5个人参赛,参赛的人会降低一分,问一个合理 ...

  4. entrar en su zapatilla de deporte en este lugar

    Mientras que yo apareció su campo usando nuestro Nike Glide Wildhorse sólo dos ($ 110) zapatillas de ...

  5. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest

    A. Toda 2 按题意模拟即可. #include <bits/stdc++.h> using namespace std ; typedef pair < int , int ...

  6. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror) in codeforces(codeforces730)

    A.Toda 2 思路:可以有二分来得到最后的数值,然后每次排序去掉最大的两个,或者3个(奇数时). /************************************************ ...

  7. POJ - 2339 Rock, Scissors, Paper

    初看题目时就发了个错误,我因为没有耐心看题而不了解题目本身的意思,找不到做题的突破口,即使看了一些题解,还是没有想到方法. 后来在去问安叔,安叔一语道破天机,问我有没有搞清题目的意思,我才恍然大悟,做 ...

  8. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 几道简单题的题解

    A. Toda 2 题意:给你n个人,每个人的分数是a[i],每次可以从两个人到五个人的使得分数减一,使得最终的分数相等: 思路:假设答案为m:每个人的分数与答案m的差值为d[i],sum为d[i]的 ...

  9. 有关ListBox

    如何拿到Source:从SQL,从XML file SQL:一个是ObjectDataProvider //用linq方法拿到SQL data,wrap到一个IEnumerable<Custom ...

随机推荐

  1. js变量作为数组对象的键值方法

    js变量作为数组对象的键值方法,变量键值获取数组值 js也可以像php的数组一样用下标获取数组的值,方法是: var arr = {'key':'abc'}; var key = 'key'; con ...

  2. php代码审计入门前必看

    首先先介绍什么是代码审计? 代码审计:是指针对源代码进行检查,寻找代码中的bug,这是一项需要多方面技能的技术 包括:对编程的掌握,漏洞形成原理的理解,系统和中间件等的熟悉 2.为什么要进行代码审计, ...

  3. 【Python机器学习实战】聚类算法(1)——K-Means聚类

    实战部分主要针对某一具体算法对其原理进行较为详细的介绍,然后进行简单地实现(可能对算法性能考虑欠缺),这一部分主要介绍一些常见的一些聚类算法. K-means聚类算法 0.聚类算法算法简介 聚类算法算 ...

  4. linux 实用指令文件目录类

    目录 linux实用指令文件目录类 路径 pwd指令 cd指令 操作文件夹/文件 ls指令 mkdir rmdir touch cp(重要) rm mv 操作内容 cat more less > ...

  5. 日常Java(测试 (二柱)修改版)2021/9/22

    题目: 一家软件公司程序员二柱的小孩上了小学二年级,老师让家长每天出30道四则运算题目给小学生做. 二柱一下打印出好多份不同的题目,让孩子做了.老师看了作业之后,对二柱赞许有加.别的老师闻讯, 问二柱 ...

  6. day13 cookie与session和中间件

    day13 cookie与session和中间件 今日内容概要 cookie与session简介 django操作cookie与session django中间件简介 如何自定义中间件 csrf跨站请 ...

  7. 容器的分类与各种测试(二)——vector部分用法

    向量 vector 是一种对象实体, 能够容纳许多其他类型相同的元素, 因此又被称为容器. 与string相同, vector 同属于STL(Standard Template Library, 标准 ...

  8. Linux基础命令---ab测试apache性能

    ab ab指令是apache的性能测试工具,它可以测试当前apache服务器的运行性能,显示每秒中可以处理多少个http请求. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.F ...

  9. 使用 ACE 库框架在 UNIX 中开发高性能并发应用

    使用 ACE 库框架在 UNIX 中开发高性能并发应用来源:developerWorks 中国 作者:Arpan Sen ACE 开放源码工具包可以帮助开发人员创建健壮的可移植多线程应用程序.本文讨论 ...

  10. 【Linux】【Services】【Disks】zfs

    1. 简介: 据说zfs有去除重复数据的功能,无良人士继续要求吧samba共享盘使用的centos7上自带的xfs改成zfs,并且开启去重功能.samba配置见 http://www.cnblogs. ...