Вы находитесь на странице: 1из 50

# :

,
,

1:

,
:

,

2:

3:

,

,
(, , -)

( )

,
,

-
,

()
,

-

,

.bat (.cmd) .sh

.bat-
@echo off
:loop
gen >input.txt
if errorlevel 1 goto exit
del output.txt
sol1
if errorlevel 1 goto exit
move output.txt output.ans
sol2
if errorlevel 1 goto exit
fc output.txt output.ans
if errorlevel 1 goto exit
goto loop
:exit

.sh-
#!/bin/sh
while true; do
./gen >input.txt || break
rm output.txt
./sol1 || break
mv output.{txt,ans}
./sol2 || break
diff output.{txt,ans} || break
done

-?

- ,

-
( runtime error time limit)

4.

Assert

assert

, ,
,
, etc.

{ a[l] <= k < a[r] }
l := 0; r := n + 1;
while r l > 1 do begin
m := (l + r) div 2;
if k < a[m] then r := m else l := m;
end;
,
!
, assert

5:

,

, x y,
dfs,

/
(
)

- .

6:

for i := 1 to n do begin
t := random (i) + 1;
a[i] := a[t];
a[t] := i;
end;
shuffle

## S(n) = {a1 S(n1), a2 S(n2), , ak S(nk)}. , |S(n1)|

= c1, , |S(nk)|= ck, C = c1 + + ck, i-
ci/C:
Procedure rec (n : tstate);
var i, c : integer;
Begin
C := 0;
for i := 1 to k do inc (C, c[i]);
X := random (C);
for i := 1 to k do if x < c[i] then begin
write (a[n, i]);
rec (ni);
end else dec (x, c[i]);
end;

:
P[i] = random (random (random (i + 1))) + 1;

(.
)

: , ,
, ,
: , ,

7:

(rdtsc)
(GetTickCount (), clock
(), gettimeofday)

,

, gcc - gprof

gprof
pg
( )
,

gprof -a

Gprof

## index % time self children called name

0.03 0.13
1/1
main [2]
[1] 100.0 0.03 0.13
1
IsolatedPrimes::findPrime(int, int, int) [1]
0.07 0.03 110/110
NextWindow(int) [3]
0.03 0.00 10813177/10813177 check(char*, int) [4]
0.00 0.00 45605/7858681 set(char*, int) [5]
0.00 0.00 10762428/10762428 advance(int&, int&) [9]
0.00 0.00
1/111
FillWindow(int) [10]
0.00 0.00
1/1
----------------------------------------------<spontaneous>
[2] 100.0 0.00 0.16
main [2]
0.03 0.13
1/1
IsolatedPrimes::findPrime(int, int, int) [1]
0.00 0.00
1/1
logopen() [12]

8:

var a, b : integer;
begin
writeln (a div b);
end.
a b
?

1.
2.
3.
4.

b = 0
b = 0 b
b = 0 (a, b)

: b = 0 (a = -2147483648,
b = -1)

#include <cstdio>
#include <cassert>
int main () {
int s = 0, t;

## scanf ("%d", &t);

assert (! (t & (t - 1)));
while (t) {
t >>= 1;
s += t;
}
printf ("%d\n", s);
return 0;
}

?
1.
2. t
3.
4.

: t = -2^31 (2147483648)
java
(>>>), C .

java
1:
import java.util.*;
public class t1 {
public static void main (String args [])
throws Exception {
Scanner in = new Scanner (System.in);
int a = in.nextInt ();
long b = in.nextLong ();
a = a + b;
System.out.println (a);
}
}

java
2:
import java.util.*;
public class t2 {
public static void main (String args [])
throws Exception {
Scanner in = new Scanner (System.in);
int a = in.nextInt ();
long b = in.nextLong ();
a += b;
System.out.println (a);
}
}

java
?
1.
2.
3. ,
4. ,

java
:
java .

( int long).
!

#include <cstdio>
int main () {
printf ("%d\n", 12345 + 5432l);
return 0;
}

?
1. 66666
2. 1130
3.
4.

17777

#include <cstdio>
#include <cassert>
int nextInt () {
int tmp;
assert (scanf ("%d", &tmp) == 1);
return tmp;
}
void display (int a, int b) {
printf ("%d %d\n", a, b);
}
int main () {
display (nextInt (), nextInt ());
return 0;
}

2 3
1. 2 2
2. 3 2
3. 2 3
4.

!
C/C++

!
:
http://vkontakte.ru/kotehok