Editorial for Lập lịch sửa chữa ô tô


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này

Code mẫu của flashmt

const maxn=10001;
var n:longint;
    re:qword;
    a,b,c:array[1..maxn] of longint;

procedure rf;
var i:longint;
begin
     readln(n);
     for i:=1 to n do read(a[i]);
     for i:=1 to n do read(b[i]);
     for i:=1 to n do c[i]:=i;
end;

procedure sort(l,r:longint);
var i,x,j,y,u:longint;
begin
     i:=l; j:=r; x:=a[(i+j) shr 1]; y:=b[(i+j) shr 1];
     repeat
           while a[i]*y>b[i]*x do i:=i+1;
           while a[j]*y<b[j]*x do j:=j-1;
           if i<=j then
           begin
                u:=a[i]; a[i]:=a[j]; a[j]:=u;
                u:=b[i]; b[i]:=b[j]; b[j]:=u;
                u:=c[i]; c[i]:=c[j]; c[j]:=u;
                i:=i+1; j:=j-1;
           end;
     until i>j;
     if i<r then sort(i,r);
     if l<j then sort(l,j);
end;

procedure pr;
var i,t:longint; u:qword;
begin
     sort(1,n);
     re:=0; t:=0;
     for i:=1 to n do
     begin
          t:=t+b[i];
          u:=a[i]; u:=u*t;
          re:=re+u;
     end;
end;

procedure wf;
var i:longint;
begin
     writeln(re);
     for i:=1 to n do write(c[i],' ');
end;

begin
     rf;
     pr;
     wf;
end.

Code mẫu của happyboy99x

#include <cstdio>
#include <algorithm>
using namespace std;

#define MAX 10000+5

typedef struct {
    int a, b, i; float x; 
} car;

bool cmp( const car & a, const car & b ) {
    return a.x < b.x;
}

car v[MAX];
int n;

int main() {
    int n; scanf( "%d", &n );
    for( int i = 0; i < n; ++i ) scanf( "%d", &v[i].a );
    for( int i = 0; i < n; ++i ) {
        scanf( "%d", &v[i].b );
        v[i].x = (float) v[i].a / v[i].b;
        v[i].i = i+1;
    }
    sort(v, v+n, cmp);
    long long money = 0, d = 0;
    for( int i = n-1; i >= 0; --i ) {
        d += v[i].b;
        money += d * v[i].a;
    }
    printf( "%lld\n", money );
    for( int i = n-1; i >= 0; --i ) printf( "%d ", v[i].i );
    putchar('\n');
    return 0;
}

Code mẫu của RR

import java.io.*;
import java.util.*;

class Car {
    int a, b, index;
    double c;
    Car() {
    }
}

class CarComparator implements Comparator<Car> {
    public static final double EPS = 1e-9;
    public int compare(Car X, Car Y) {
        if (Math.abs(X.c - Y.c) < EPS) return 0;
        else if (X.c < Y.c) return -1;
        else return 1;
    }
}

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner( System.in );
        PrintWriter pw = new PrintWriter( System.out );
        int n = sc.nextInt();
        Car[] a = new Car[n];

        for(int i = 0; i < n; i++)
            a[i] = new Car();

        for(int i = 0; i < n; i++) a[i].a = sc.nextInt();
        for(int i = 0; i < n; i++) a[i].b = sc.nextInt();
        for(int i = 0; i < n; i++) a[i].index = i+1;
        for(int i = 0; i < n; i++) a[i].c = (double)a[i].b / a[i].a;

        Comparator<Car> cc = new CarComparator();
        Arrays.sort(a, cc);

        long res = 0, time = 0;
        for(int i = 0; i < n; i++) {
            time += a[i].b;
            res += time * a[i].a;
        }
        pw.println(res);

        for(int i = 0; i < n; i++)
            pw.print( a[i].index + " ");

        pw.close();
    }
}

Code mẫu của hieult

#include <stdio.h>
//#include <conio.h>

void Quick_Sort(double A[],int d[], int lower,int upper)
{
        double x = A[(lower + upper) / 2];
        int i = lower;
        int j = upper;
        do{
                while(A[i] < x)
                        i ++;
                while (A[j] > x)
                        j --;
                if (i <= j)
                {
                     double tg=A[i];
                     A[i]=A[j];
                     A[j]=tg;
                     int tgd=d[i];
                     d[i]=d[j];
                     d[j]=tgd;   
                        i ++;
                        j --;
                }
        }while(i <= j);
        if (j > lower)
                Quick_Sort(A,d, lower, j);
        if (i < upper)
                Quick_Sort(A,d, i, upper);
}

int main()
{
  // freopen("SCHEDULE.in0","r",stdin);
    int n,a[10001],b[10001],so[10001];
    double c[10001];
    scanf("%d",&n);
    for(int i = 1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        so[i] = i;        
    }
    for(int i = 1;i<=n;i++)
    {
        scanf("%d",&b[i]);
        c[i] = b[i]*1./a[i];      
    }
    Quick_Sort(c,so,1,n);
    long long KQ = 0, t = 0;
    for(int i = 1;i<=n;i++)
    {
        t = t+b[so[i]];
        KQ = KQ+t*a[so[i]];
    }
    printf("%lld\n",KQ);
    for(int i = 1;i<=n;i++) printf("%d ",so[i]);
    //getch();
}

Code mẫu của ll931110

{$MODE DELPHI}
const
  InputFile  = '';
  OutputFile = '';
  max = 10000;
var
  a, b, Index: array[1..max] of Integer;
  n: Integer;
  Res: Comp;

procedure Enter;
var
  f: Text;
  i: Integer;
begin
  Assign(f, InputFile); Reset(f);
  Readln(f, n);
  for i := 1 to n do Read(f, a[i]);
  Readln(f);
  for i := 1 to n do Read(f, b[i]);
  Close(f);
end;

procedure Init;
var
  i: Integer;
begin
  for i := 1 to n do Index[i] := i;
end;

function Lower(i, j: Integer): Boolean; {= a[i]/b[i] > a[j]/b[j]}
begin
  Lower := LongInt(a[i]) * b[j] > LongInt(a[j]) * b[i];
end;

procedure QSort(L, H: Integer);
var
  k, i, j, t: Integer;
begin
  if L >= H then Exit;
  k := Index[Random(H - L + 1) + L];
  i := L; j := H;
  repeat
    while Lower(Index[i], k) do Inc(i);
    while Lower(k, Index[j]) do Dec(j);
    if i <= j then
      begin
        t := Index[i]; Index[i] := Index[j]; Index[j] := t;
        Inc(i); Dec(j);
      end;
  until i > j;
  QSort(L, j); QSort(i, H);
end;

procedure Solve;
var
  t: LongInt;
  i, j: Integer;
begin
  t := 0; Res := 0;
  for i := 1 to n do
    begin
      j := Index[i];
      t := t + b[j];
      Res := Res + a[j] * (t + 0.0);
    end;
end;

procedure Result;
var
  f: Text;
  i: Integer;
begin
  Assign(f, OutputFile); Rewrite(f);
  Writeln(f, Res:0:0);
  for i := 1 to n do  Write(f, Index[i], ' ');
  Close(f);
end;

begin
  Enter;
  Init;
  QSort(1, n);
  Solve;
  Result;
end.
2
1 1
1 2

Code mẫu của khuc_tuan

import java.io.*;
import java.util.*;
import static java.lang.Integer.parseInt;
public class Main{
    static class Element implements Comparable<Element>{
        public int a,b,i;
        public int compareTo(Element x) {
            return -a*x.b+b*x.a;
        }
    }
    public static void main(String[]Args) throws Exception {
        BufferedReader kb=new BufferedReader(new InputStreamReader(System.in));
        int n=parseInt(kb.readLine());
        Element[] a=new Element[n];
        for(int i=0;i<n;++i) a[i]=new Element();
        StringTokenizer st=new StringTokenizer(kb.readLine());
        for(int i=0;i<n;++i) {
            a[i].a = parseInt(st.nextToken());
            a[i].i = i+1;
        }
        st=new StringTokenizer(kb.readLine());
        for(int i=0;i<n;++i) a[i].b=parseInt(st.nextToken());
        Arrays.sort(a);
        long s=0,r=0;
        for(Element x:a) {
            s+=x.b;
            r+=s*x.a;
        }
        System.out.println(r);
        for(Element x:a) System.out.print(x.i+" ");
    }
}

Comments

Please read the guidelines before commenting.


There are no comments at the moment.