P1586 魔法照片

题目描述

佳佳在n个人中把照片给k个人,关系好坏的程度为W[i]。按照从大到小的序号对10取模的值将这些人分为10类。求出加上额外权值以后,最终的权值最大的k个人,并输出他们的编号。如果两人的W[i]相同,编号小的优先。

样例输入

10 10
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20

样例输出

10 9 8 7 6 5 4 3 2 1

思路

O(n log n)
模拟,排序;

var
  n,k,i:longint;
  a,b,c:array[0..30000] of longint;
procedure qsort(l,r:longint);
var
  p,t,m,j:longint;
begin
  i:=l;j:=r;
  p:=a[(l+r) div 2];
  m:=c[(l+r) div 2];
  repeat
    while (a[i]>p)or((a[i]=p)and(c[i]<m)) do inc(i);
    while (a[j]<p)or((a[j]=p)and(c[j]>m)) do dec(j);
    if i<=j then
      begin
        t:=a[i];a[i]:=a[j];a[j]:=t;
        t:=c[i];c[i]:=c[j];c[j]:=t;
        inc(i);
        dec(j);
      end;
  until i>j;
  if i<r then qsort(i,r);
  if l<j then qsort(l,j);
end;
procedure init;
begin
  readln(n,k);
  for i:=1 to 10 do read(b[i]);
  for i:=1 to n do read(a[i]);
end;
begin
  init;
  for i:=1 to n do c[i]:=i;
  qsort(1,n);
  for i:=1 to n do
    a[i]:=a[i]+b[(i-1) mod 10+1];
  qsort(1,n);
  for i:=1 to k do
    write(c[i],' ');
end.
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值