Avito Cool Challenge 2018-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.
题解:看分了几组,假如说有很多人说了有a个人和自己不同,那么就有n-a个人和自己是一组。
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
struct node
{
int id,val;
}p[100005];
bool cmp(node x,node y)
{
return x.val<y.val;
}
int ans[100005];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
p[i].id=i;
scanf("%d",&p[i].val);
}
sort(p+1,p+n+1,cmp);
//for(int t=1;t<=n;t++)
//{
//cout<<p[t].val<<" "<<p[t].id<<endl;
//}
int last = 1;
long long int sum=0;
int cnt=0;
while(1)
{
int t=last+(n-p[last].val)-1;
if(p[t].val==p[last].val)
{
cnt++;
for(int j=last;j<=t;j++)
{
ans[p[j].id]=cnt;
}
sum+=(n-p[last].val);
last=t+1;
if(t==n)break;
}
else{
printf("Impossible\n");
return 0;
}
}
if(sum!=n)
{
printf("Impossible\n");
}
else
{
printf("Possible\n");
for(int i=1;i<=n;i++)
{
printf("%d ",ans[i]);
}
}
return 0;
}
Avito Cool Challenge 2018-B. Farewell Party(思维)的更多相关文章
- Avito Cool Challenge 2018 B. Farewell Party 【YY】
传送门:http://codeforces.com/contest/1081/problem/B B. Farewell Party time limit per test 1 second memo ...
- Avito Cool Challenge 2018 B - Farewell Party
题目大意: 有n个人 接下来一行n个数a[i] 表示第i个人描述其他人有a[i]个的帽子跟他不一样 帽子编号为1~n 如果所有的描述都是正确的 输出possible 再输出一行b[i] 表示第i个人的 ...
- Codeforces Avito Code Challenge 2018 D. Bookshelves
Codeforces Avito Code Challenge 2018 D. Bookshelves 题目连接: http://codeforces.com/contest/981/problem/ ...
- Avito Cool Challenge 2018
考挂了.. A - Definite Game 直接看代码吧. #include<cstdio> #include<cstring> #include<algorithm ...
- Avito Cool Challenge 2018(div1+2)
A. Definite Game: 题意:输入N,输出最小的结果N-x,其中x不少N的因子. 思路:N=2时,输出2:其他情况输出1:因为N>2时,N-1不会是N的因子. #include< ...
- Avito Cool Challenge 2018 Solution
A. Definite Game 签. #include <bits/stdc++.h> using namespace std; int main() { int a; while (s ...
- Avito Cool Challenge 2018 A. B题解
A. Definite Game 题目链接:https://codeforces.com/contest/1081/problem/A 题意: 给出一个数v,然后让你可以重复多次减去一个数d,满足v% ...
- Avito Code Challenge 2018
第一次打CF,很菜,A了三道水题,第四题好像是是数位DP,直接放弃了.rateing从初始的1500变成了1499,还是绿名,这就很尴尬.之后觉得后面的题目也没有想象的那么难(看通过人数)过两天吧剩下 ...
- Avito Cool Challenge 2018 自闭记
A:n==2?2:1. #include<iostream> #include<cstdio> #include<cmath> #include<cstdli ...
- Avito Cool Challenge 2018 E. Missing Numbers 【枚举】
传送门:http://codeforces.com/contest/1081/problem/E E. Missing Numbers time limit per test 2 seconds me ...
随机推荐
- Java接口 详解(一)
一.基本概念 接口(Interface),在JAVA编程语言中是一个抽象类型,是抽象方法的集合.接口通常以interface来声明.一个类通过继承接口的方式,从而来继承接口的抽象方法. 如果一个类只由 ...
- MAC OS Sierra 10.12.6 下对固态硬盘SSD 开启TRIM功能
这个是对于不是mac原装SSD的情况下才做的操作... 大家都知道,苹果店卖的SSD硬盘那怕就是一个256G的也要1000多人民币,而市场上的也就400-500左右人民币,整整少了一半还要多,可见JS ...
- 51 nod 1522 上下序列——序列dp
题目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1522 很好的思想.考虑从小到大一对一对填数,这样也能对它的大小限制 ...
- JAVA 编程思想二
1: java 单根继承的优点? 方便垃圾回收: 垃圾回收的设计会方便实现. 多重继承的函数重名的问题. 2: 向下转型和向上转型? 向下转型不安全,向上转型安全. 3: system.g ...
- stm32之通信
本文提到的内容有以下几个方面: 通信概述 串口通信 I2C通信 CAN通信 SPI通信 I2S通信 USB通信 其他通信 一.通信概述 按照数据传送方式分: 串行通信(一条数据线.适合远距离传输.控制 ...
- oracle针对中文排序
在oracle 9i之前,对中文的排序,是默认按2进制编码来进行排序的. 9i时增加了几种新的选择: 按中文拼音进行排序:SCHINESE_PINYIN_M 按中文部首进行排序:SCHINESE_RA ...
- FASTX-Toolkit组件用法
FASTX-Toolkit组件用法 Command Line Arguments FASTQ-to-FASTA FASTQ/A Quality Statistics FASTQ Quality cha ...
- IIS7启用GZip压缩
本文转载自 http://www.cnblogs.com/kissdodog/p/6252129.html GZip压缩通常会达到70%以上的压缩率,如果是手机Web这无疑会使网站的访问速度大大增加, ...
- 数据库路由中间件MyCat - 使用篇(2)
此文已由作者张镐薪授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 基本概念 3. 分片 3.1 分片节点(dataNode) 表被水平切分后,每个分片表所在的数据库就是一个分 ...
- css样式也技巧
目录 关于iPhone的点击事件绑定无效的处理方法 https://blog.csdn.net/u014477038/article/details/52527194 去掉a.button.input ...