欢迎辞

欢迎来到“笃志以砺,决起而飞”!
如果您是第一次来到本站,建议访问本站导读以便更快地了解本站。
如果您喜欢本站,欢迎订阅

 

2012 年五月
« 四  
 123456
78910111213
14151617181920
21222324252627
28293031 

USACO 1.3 Mixing Milk 程序

Executing…
Test 1: TEST OK [0.000 secs, 244 KB]
Test 2: TEST OK [0.000 secs, 244 KB]
Test 3: TEST OK [0.000 secs, 252 KB]
Test 4: TEST OK [0.000 secs, 248 KB]
Test 5: TEST OK [0.011 secs, 244 KB]
Test 6: TEST OK [0.022 secs, 244 KB]
Test 7: TEST OK [0.000 secs, 248 KB]
Test 8: TEST OK [0.011 secs, 244 KB]

All tests OK.

?View Code PASCAL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{
ID:cxj6661
PROB:milk
LANG:PASCAL
}
//By Ceeji
//Date: 2009-6-1
//Type: Sort
//Resource: USACO 1.3
Program milk;
Const
   fin='milk.in';
   fou='milk.out';
Type nm=record
          p,a:longint;
        end;
Var
   i,n,m,sum:longint;
   info:array[1..5000]of nm;
Procedure qsort(s,t:longint);
var tmp:nm;
    e,i,j:longint;
begin
    i:=s; j:=t; e:=info[random(t-s+1)+s].p;
    repeat
       while (i<t)and(info[i].p<e) do inc(i);
       while (j>s)and(info[j].p>e) do dec(j);
       if i<=j then
       begin
          tmp:=info[i]; info[i]:=info[j]; info[j]:=tmp;
          inc(i); dec(j);
       end;
    until i>j;
    if j>s then qsort(s,j);
    if i<t then qsort(i,t);
end;
begin
   randomize;
   assign(input,fin);  reset(input);
   assign(output,fou); rewrite(output);
   readln(n,m);
   for i:=1 to m do
   begin
     readln(info[i].p,info[i].a);
   end;
   close(input);
   sum:=0;
   qsort(1,m); i:=1;
   while n>0 do
   begin
      if n>info[i].a then
      begin
         inc(sum,info[i].p*info[i].a);
         dec(n,info[i].a);
         inc(i);
      end
      else
      begin
         inc(sum,info[i].p*n); n:=0; break;
      end;
   end;
   writeln(sum);
   close(output);
end.

您也许喜欢

  1. USACO 1.2 Palindromic Squares 程序
  2. USACO 4.2 ditch Drainage Ditches 程序
  3. USACO 1.2 Dual Palindromes 双重回文数 程序
  4. USACO The Perfect Stall (stall4) 程序
  5. USACO 1.2 Milking Cows(milk2) 程序
  6. USACO 1.2 Name That Number(namenum) 程序

4 comments to USACO 1.3 Mixing Milk 程序

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>