File tree Expand file tree Collapse file tree 7 files changed +253
-0
lines changed Expand file tree Collapse file tree 7 files changed +253
-0
lines changed Original file line number Diff line number Diff line change
1
+ # There is a way more simpler solution noticing that boxes of different sizes are really independent.
2
+ from math import *
3
+
4
+ n = input ();
5
+ d = [map (int , raw_input ().split ()) for i in xrange (n )];
6
+
7
+ d .sort (key = lambda x : x [0 ]);
8
+
9
+ for i in xrange (n - 1 ):
10
+ p1 = d [i ]; p2 = d [i + 1 ];
11
+ if log (p1 [1 ] / (float (p2 [1 ])), 4 ) <= p2 [0 ] - p1 [0 ]:
12
+ continue
13
+ else :
14
+ cnt = 4 ** (p2 [0 ] - p1 [0 ]);
15
+ d [i + 1 ][1 ] += ((p1 [1 ] - cnt * p2 [1 ]) + cnt - 1 ) / cnt ;
16
+
17
+ print "%d" % (d [n - 1 ][0 ] + max (1 , ceil (log (d [n - 1 ][1 ], 4 ))));
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
Original file line number Diff line number Diff line change
1
+ n = input ();
2
+ i = n ;
3
+
4
+ while True :
5
+ i += 1 ;
6
+ a = []; j = i ;
7
+ while j != 0 :
8
+ a .append (j % 10 );
9
+ j /= 10 ;
10
+ if len (a ) == len (set (a )):
11
+ print i
12
+ break ;
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < vector>
3
+ #include < queue>
4
+ #include < string>
5
+ #include < list>
6
+ #include < set>
7
+ #include < map>
8
+ #include < sstream>
9
+ #include < cstdio>
10
+ #include < algorithm>
11
+ #include < cstring>
12
+ #include < cmath>
13
+ #include < ctime>
14
+
15
+ using namespace std ;
16
+
17
+ bool isp[110011 ];
18
+ vector<int >p;
19
+ int r[511 ], c[511 ];
20
+ void genPrime () {
21
+ int i, j, k;
22
+ memset (isp, true , sizeof (isp));
23
+ for (i = 2 ; i < 1000 ; ++i) {
24
+ if (isp[i])
25
+ for (j = i * i; j <= 110000 ; j += i)
26
+ isp[j] = false ;
27
+ }
28
+ p.push_back (2 );
29
+ for (i = 3 ; i <= 110000 ; i+=2 )
30
+ if (isp[i]) p.push_back (i);
31
+ }
32
+
33
+ int a[511 ][511 ];
34
+ int main () {
35
+ int i, j, k, m, n;
36
+ genPrime ();
37
+ scanf (" %d%d" , &m, &n);
38
+ for (i = 1 ; i <= m; ++i)
39
+ for (j = 1 ; j <= n; ++j) {
40
+ scanf (" %d" , &a[i][j]);
41
+ a[i][j] = *lower_bound (p.begin (), p.end (), a[i][j]) - a[i][j];
42
+ r[i] += a[i][j];
43
+ c[j] += a[i][j];
44
+ }
45
+ int ans = 1000000011 ;
46
+ for (i = 1 ; i <= m; ++i) ans = min (ans, r[i]);
47
+ for (j = 1 ; j <= n; ++j) ans = min (ans, c[j]);
48
+ printf (" %d\n " , ans);
49
+ return 0 ;
50
+
51
+ }
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < vector>
3
+ #include < queue>
4
+ #include < string>
5
+ #include < list>
6
+ #include < set>
7
+ #include < map>
8
+ #include < sstream>
9
+ #include < cstdio>
10
+ #include < algorithm>
11
+ #include < cstring>
12
+ #include < cmath>
13
+ #include < ctime>
14
+
15
+ using namespace std ;
16
+
17
+ int d[2 ][1000011 ];
18
+
19
+ int a[511 ][511 ];
20
+ int main () {
21
+ int i, j, k;
22
+ int n, m;
23
+ scanf (" %d%d" , &n, &m);
24
+ if (3 * m > n) {
25
+ printf (" -1" );
26
+ return 0 ;
27
+ }
28
+
29
+ for (i = 1 ; i <= m; ++i) printf (" %d " , i);
30
+ for (i = 1 ; i <= m; ++i) printf (" %d " , i);
31
+ for (i = 2 ; i <= m; ++i) printf (" %d " , i); printf (" 1 " );
32
+ for (i = 1 ; i <= n - 3 * m; ++i)
33
+ printf (" 1%c" , i == (n-3 *m) ? ' \n ' : ' ' );
34
+ return 0 ;
35
+ }
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < vector>
3
+ #include < queue>
4
+ #include < string>
5
+ #include < list>
6
+ #include < set>
7
+ #include < map>
8
+ #include < sstream>
9
+ #include < cstdio>
10
+ #include < algorithm>
11
+ #include < cstring>
12
+ #include < cmath>
13
+ #include < ctime>
14
+
15
+ using namespace std ;
16
+
17
+ #define CHAR_NUM 26
18
+
19
+ int node_num;
20
+
21
+ struct node
22
+ {
23
+ int p[CHAR_NUM];
24
+ void clear () { memset ( p, -1 , sizeof p ); }
25
+ }dict[4000011 ];
26
+
27
+ // Add a new node in Trie and return the node number
28
+ int new_node () {
29
+ dict[node_num].clear ();
30
+ return node_num++;
31
+ }
32
+
33
+ int f[26 ];
34
+ char s[2011 ];
35
+ int main () {
36
+ int i, j, k, m;
37
+ scanf (" %s" , s); int n = strlen (s);
38
+ int root = new_node ();
39
+ for (i = 0 ; i < 26 ; ++i) scanf (" %1d" , &f[i]);
40
+ scanf (" %d" , &m);
41
+ for (i = 0 ; i < n; ++i) {
42
+ int t = root, cnt = 0 ;
43
+ for (j = i; j < n; ++j) {
44
+ if (!f[s[j] - ' a' ]) ++cnt;
45
+ if (cnt > m) break ;
46
+ if (dict[t].p [s[j] - ' a' ] == -1 ) dict[t].p [s[j] - ' a' ] = new_node ();
47
+ t = dict[t].p [s[j] - ' a' ];
48
+ }
49
+ }
50
+ printf (" %d\n " , node_num - 1 );
51
+ return 0 ;
52
+ }
Original file line number Diff line number Diff line change
1
+ let ( |> ) x f = f x
2
+ let ( <| ) f x = f x
3
+
4
+ let foi = float_of_int
5
+ let iof = int_of_float
6
+
7
+ let next_int () = Scanf. scanf " %d%c" (fun x _ -> x)
8
+ let next_flt () = Scanf. scanf " %f%c" (fun x _ -> x)
9
+
10
+ let seq n =
11
+ let rec aux n acc =
12
+ if n = 0 then acc
13
+ else aux (n-1 ) (n :: acc) in
14
+ aux n []
15
+
16
+ let rec show_flt_list x =
17
+ match x with
18
+ [] -> print_newline ()
19
+ | x ::xs -> print_float x; print_string " " ; show_flt_list xs
20
+
21
+ let rec show_int_list x =
22
+ match x with
23
+ [] -> print_newline ()
24
+ | x ::xs -> print_int x; print_string " " ; show_int_list xs
25
+
26
+ let rec loop n f acc =
27
+ if n = 0 then List. rev acc else loop (n-1 ) f ((f n) :: acc)
28
+
29
+ let rec gcd x y =
30
+ if y = 0 then x else gcd y (x mod y)
31
+ ;;
32
+
33
+ let n = next_int ()
34
+ let m = next_int ()
35
+
36
+
37
+ let a = loop n (fun _ -> (next_int() ) - 1 ) []
38
+ let d = List. fold_left gcd (List. hd a) a
39
+
40
+ let calc x =
41
+ let m = Int64. of_int m in
42
+ let rec aux acc x =
43
+ if x > = m then acc
44
+ else aux (Int64. add acc (Int64. sub m x)) (Int64. add x x) in
45
+ aux (Int64. zero) (Int64. of_int x)
46
+
47
+ let get_dvsr () =
48
+ let up = iof (sqrt (foi d)) in
49
+ let rec aux n acc =
50
+ if n > up then acc
51
+ else
52
+ if d mod n = 0 then
53
+ if n * n <> d then aux (n + 1 ) (n :: (d/ n) :: acc)
54
+ else aux (n + 1 ) (n :: acc)
55
+ else
56
+ aux (n + 1 ) acc
57
+ in
58
+ aux 1 []
59
+
60
+ let () =
61
+ List. filter (fun x -> x mod 2 = 1 ) (get_dvsr () )
62
+ |> List. fold_left (fun acc y -> Int64. add acc (calc y)) Int64. zero
63
+ |> Printf. printf " %Ld"
64
+
65
+
66
+
67
+
Original file line number Diff line number Diff line change
1
+ n = gets . to_i ;
2
+ a = gets . split . map ( & :to_i ) ;
3
+ sum = a . inject ( :+ ) ;
4
+ acc = 0 ;
5
+ d = [ 0 ] . concat ( a . map { |x | acc += x } )
6
+ s , t = gets . split . map ( &:to_i ) ;
7
+ s , t = t , s if t < s
8
+ p ( [ d [ t -1 ] -d [ s -1 ] , sum - d [ t -1 ] + d [ s -1 ] ] . min )
You can’t perform that action at this time.
0 commit comments