E - Exam Redistribution

NWERC 2016 Problem E Exam Redistribution Picture from US Navy, public domain Linda is giving an exam. When the exam is over, Linda will redistribute the exams among the students for a peer review, so they may grade each other’s answers and assign preliminary scores. The students are split up in several rooms of varying sizes. Linda has devised the following scheme for redistributing the exams: 1. Linda visits the first room, picks up all exams written there, and places them in a pile. 2. In each subsequent room Linda takes exams from the top of her pile and randomly distributes them to the students in the room. She then picks up all exams written in that room and adds them to the bottom of her pile. 3. After having visited each room exactly once, Linda returns to the first room, and distributes the remaining exams from her pile there. Naturally, it is imperative that no student receives their own exam to review, and that Linda does not run out of exams in her pile while doing the redistribution (i.e., that when entering a room after the first one, Linda’s pile contains at least as many exams as there are students in the room). Whether or not this is the case depends on the order in which the rooms are visited. We say that an ordering of the rooms is safe if Linda will not run out of exams in her pile when visiting rooms in that order, and that there is no chance that any student receives their own exam to review. Can you find a safe order in which to visit the rooms (or determine that no safe order exists)? Input The input consists of: • one line containing an integer n (2 ≤ n ≤ 30), the number of rooms. • one line containing n integers s1, . . . , sn (1 ≤ si ≤ 100 for each i), where si is the number of students in room i. Output If it is impossible to redistribute the exams safely, output “impossible”. Otherwise, output a safe order in which to visit the rooms. If there are multiple safe orders, you may give any of them. NWERC 2016 Problem E: Exam Redistribution

NWERC 2016 Sample Input 1 Sample

Output 1 4 2 3 3 1 2 3 4 1

Sample Input 2 Sample

Output 2 2 10 20 impossible

#include <iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct st
{
    int data,mun;
} a[35];
bool cmp(st a,st b)
{
    return a.data>b.data;
}
int main()
{
    int n,i;
    int sum=0;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i].data);
        a[i].mun=i+1;
        sum+=a[i].data;
    }
    sort(a,a+n,cmp);
    sum-=a[0].data;
    if(sum<a[0].data)printf("impossible\n");
    else
    {
        for(i=0; i<n; i++)
        {
            if(i!=n-1)printf("%d ",a[i].mun);
            else printf("%d\n",a[i].mun);
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值