传送门:http://codeforces.com/contest/1081/problem/B

B. Farewell Party

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.

Chouti remembered that nn persons took part in that party. To make the party funnier, each person wore one hat among nn kinds of weird hats numbered 1,2,…n1,2,…n. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.

After the party, the ii-th person said that there were aiai persons wearing a hat differing from his own.

It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let bibi be the number of hat type the ii-th person was wearing, Chouti wants you to find any possible b1,b2,…,bnb1,b2,…,bn that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.

Input

The first line contains a single integer nn (1≤n≤1051≤n≤105), the number of persons in the party.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤n−10≤ai≤n−1), the statements of people.

Output

If there is no solution, print a single line "Impossible".

Otherwise, print "Possible" and then nn integers b1,b2,…,bnb1,b2,…,bn (1≤bi≤n1≤bi≤n).

If there are multiple answers, print any of them.

Examples
input

Copy
3
0 0 0
output

Copy
Possible
1 1 1
input

Copy
5
3 3 2 2 2
output

Copy
Possible
1 1 2 2 2
input

Copy
4
0 1 2 3
output

Copy
Impossible
Note

In the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind 11.

In the answer to the second example, the first and the second person wore the hat with type 11 and all other wore a hat of type 22.

So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.

In the third example, it can be shown that no solution exists.

In the first and the second example, other possible configurations are possible.

题意概括:

有 N 个人,每个人都佩戴一顶帽子(帽子种类有 1、2、3 ... N );

接下来 N 个数表示所有人里面 与 第 i 个人佩戴了不同帽子的总数。

解题思路:

ai 代表与自己佩戴了不同帽子的个数,那么反过来意思就是说有 N - ai个人佩戴了与自己相同帽子。

如果能满足 数量为 ai 的 个数 Si == N - ai, 则说明刚好有 N-ai 个人佩戴相同帽子。

如果 Si > N-ai ,则需要判断 这 Si 个人里面能否内部平衡掉, 也就是分成若干块 N-ai,每一块佩戴不同的帽子,但是块内的人佩戴的帽子是相同的,这样也满足条件。

即 Si%(N-ai) ?= 0;

如果 Si % (N-ai) != 0 则说明无法平衡。

最后按块编号,输出答案。

tip:代码实现和细节很重要。

AC code:

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#define INF 0x3f3f3f3f
using namespace std; const int MAXN = 1e5+;
vector<vector<int> >num(MAXN);
int ans[MAXN]; int main()
{
int N, x;
scanf("%d", &N);
for(int i = ; i <= N; i++){
scanf("%d", &x);
num[N-x].push_back(i);
} int tp, no = ;
bool flag = true;
for(int i = ; i <= N; i++){
tp = num[i].size();
if(tp%i != ){
flag = false;
break;
}
for(int j = ; j < tp; j++){
if(j%i == ) ++no;
ans[num[i][j]] = no;
}
} if(flag){
puts("Possible");
for(int i = ; i <= N; i++)
printf("%d ", ans[i]);
}
else{
puts("Impossible");
}
return ;
}

Avito Cool Challenge 2018 B. Farewell Party 【YY】的更多相关文章

  1. Avito Cool Challenge 2018 E. Missing Numbers 【枚举】

    传送门:http://codeforces.com/contest/1081/problem/E E. Missing Numbers time limit per test 2 seconds me ...

  2. Avito Cool Challenge 2018 C. Colorful Bricks 【排列组合】

    传送门:http://codeforces.com/contest/1081/problem/C C. Colorful Bricks time limit per test 2 seconds me ...

  3. Avito Cool Challenge 2018 B - Farewell Party

    题目大意: 有n个人 接下来一行n个数a[i] 表示第i个人描述其他人有a[i]个的帽子跟他不一样 帽子编号为1~n 如果所有的描述都是正确的 输出possible 再输出一行b[i] 表示第i个人的 ...

  4. Codeforces Avito Code Challenge 2018 D. Bookshelves

    Codeforces Avito Code Challenge 2018 D. Bookshelves 题目连接: http://codeforces.com/contest/981/problem/ ...

  5. Avito Cool Challenge 2018

    考挂了.. A - Definite Game 直接看代码吧. #include<cstdio> #include<cstring> #include<algorithm ...

  6. Avito Cool Challenge 2018(div1+2)

    A. Definite Game: 题意:输入N,输出最小的结果N-x,其中x不少N的因子. 思路:N=2时,输出2:其他情况输出1:因为N>2时,N-1不会是N的因子. #include< ...

  7. Avito Cool Challenge 2018 Solution

    A. Definite Game 签. #include <bits/stdc++.h> using namespace std; int main() { int a; while (s ...

  8. Avito Cool Challenge 2018 A. B题解

    A. Definite Game 题目链接:https://codeforces.com/contest/1081/problem/A 题意: 给出一个数v,然后让你可以重复多次减去一个数d,满足v% ...

  9. Avito Code Challenge 2018

    第一次打CF,很菜,A了三道水题,第四题好像是是数位DP,直接放弃了.rateing从初始的1500变成了1499,还是绿名,这就很尴尬.之后觉得后面的题目也没有想象的那么难(看通过人数)过两天吧剩下 ...

随机推荐

  1. 怎样以最快的速度导入mysql

    前一段时间团队举办数据库大赛,和我一组的小伙伴给我发了个链接,我觉得很有意思: https://dbahire.com/testing-the-fastest-way-to-import-a-tabl ...

  2. C#项目””是针对”.NETFramework,Version=v4.5.2”但此计算机没有,需要修改为v4.5.1.

    每次下载别人的代码都会出现这样的问题,以为是没有安装.NETFramework,就下载安装了,但是每次安装都会出现已安装高版本的4.6(Win10自带),无需下次安装,但是每次VS中都会显示有问题,而 ...

  3. 三:SSM框架整合思路

    一:jar包 1.spring(包括springmvc) 2.mybatis 3.mybatis-spring整合包 4.数据库驱动 5.第三方连接池 6.json依赖包jackson 二:整合思路 ...

  4. Java SortedSet为什么可以实现自动排序?

    Set中的SortedSet(SortedSet为TreeSet的实现接口),它们之间的继承关系如下: java.util.Set; java.util.SortedSet; java.util.Tr ...

  5. SPOJ QTREE5

    题意 一棵\(n\)个点的树,点从\(1\)到\(n\)编号.每个点可能有两种颜色:黑或白. 我们定义\(dist(a,b)\)为点\(a\)至点\(b\)路径上的边个数. 一开始所有的点都是黑色的. ...

  6. git管理之源切换

    Git remote 修改源 git commit -m "Change repo." # 先把所有为保存的修改打包为一个commit git remote remove orig ...

  7. flex与相对定位在国内双核浏览器极速模式下的兼容性问题

    在国内的浏览器中,360浏览器,QQ浏览器等绝大部分都是双核浏览器.双核浏览器即拥有IE兼容内核和非IE极速内核两个内核,分别对应兼容模式和极速模式.兼容模式时使用IE内核,极速模式采用webkit内 ...

  8. Spring 框架(二)

    1AOP 1.1 AOP介绍 1.1.1 什么是AOP l 在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功 ...

  9. ASPF(Application Specific Packet Filter)

    ASPF ASPF(Application Specific Packet Filter)是针对应用层的包过滤,其原理是检测通过设备的报文的应用层协议信息,记录临时协商的数据连接,使得某些在安全策略中 ...

  10. 【转】C# GDAL 配置

    共生成9个dll,如下图: 1.在程序中添加*_csharp.dll四个文件的引用: 2.将剩余的五个文件复制到程序的Debug文件夹中:(如果不复制这五个文件就会出现类似“OSGeo.GDAL.Gd ...