File tree 8 files changed +398
-0
lines changed
8 files changed +398
-0
lines changed Original file line number Diff line number Diff line change @@ -8,3 +8,4 @@ My sport programming adventures.
8
8
* [ interviewbit.com] ( https://www.interviewbit.com/profile/ivan_samsonov )
9
9
* [ acmp.ru] ( http://acmp.ru/index.asp?main=user&id=560 )
10
10
* [ csacademy.com] ( https://csacademy.com/user/kronos )
11
+ * [ russiancodecup.ru] ( https://russiancodecup.ru )
Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+ import java .util .*;
3
+
4
+ public class Main {
5
+ private final Scanner in ;
6
+ private final PrintWriter out ;
7
+
8
+ public Main () {
9
+ in = new Scanner (System .in );
10
+ out = new PrintWriter (new OutputStreamWriter (System .out ));
11
+ }
12
+
13
+ public static void main (String [] args ) throws IOException {
14
+ new Main ().run ();
15
+ }
16
+
17
+ void run () throws IOException {
18
+ solve ();
19
+ out .flush ();
20
+ }
21
+
22
+ void solve () throws IOException {
23
+ int t = in .nextInt ();
24
+ int k ,a ,b ,ans ,p ;
25
+ for (;t >0 ;t --) {
26
+ k = in .nextInt ();
27
+ a = in .nextInt ();
28
+ b = in .nextInt ();
29
+ if (a < b ) {
30
+ p = a ;
31
+ a = b ;
32
+ b = p ;
33
+ }
34
+ if (a >= k ) {
35
+ if (a -b > 1 ) {
36
+ ans = 0 ;
37
+ } else if (a == b ) {
38
+ ans = 2 ;
39
+ } else {
40
+ ans = 1 ;
41
+ }
42
+ } else {
43
+ ans = k - a ;
44
+ if (ans + a - b == 1 ) {
45
+ ans ++;
46
+ } else if (ans + a - b == 0 ) {
47
+ ans += 2 ;
48
+ }
49
+ }
50
+ out .println (ans );
51
+ }
52
+ }
53
+ }
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < string>
3
+ #include < vector>
4
+ #include < map>
5
+ #include < set>
6
+ #include < algorithm>
7
+
8
+ using namespace std ;
9
+
10
+ int t, n, m;
11
+
12
+ int a[20 ][20 ];
13
+ int main () {
14
+ ios::sync_with_stdio (false );
15
+ cin.tie (0 );
16
+ cin >> t;
17
+ int cnt = 0 ;
18
+ int line = n-1 ;
19
+ int column = 0 ;
20
+ int p, cline, ccolumn;
21
+
22
+ while (t--) {
23
+ cin >> n >> m;
24
+ line = 0 ;
25
+ column = 0 ;
26
+ ccolumn = 0 ;
27
+ cline = 0 ;
28
+ p = n*m;
29
+ while (p > 0 ) {
30
+ a[cline][ccolumn] = p;
31
+ p--;
32
+ ccolumn++;
33
+ cline--;
34
+ if (cline < 0 ) {
35
+ line++;
36
+ if (line > n-1 ) {
37
+ line = n-1 ;
38
+ column++;
39
+ }
40
+ ccolumn = column;
41
+ cline = line;
42
+ }
43
+
44
+ if (ccolumn > m-1 ) {
45
+ line++;
46
+ if (line > n-1 ) {
47
+ line = n-1 ;
48
+ column++;
49
+ }
50
+ ccolumn = column;
51
+ cline = line;
52
+ }
53
+ }
54
+
55
+ for (int i = 0 ; i < n; i++) {
56
+ for (int j = 0 ; j < m; j++) {
57
+ cout << a[i][j] << " " ;
58
+ }
59
+ cout << " \n " ;
60
+ }
61
+ }
62
+ return 0 ;
63
+ }
Original file line number Diff line number Diff line change
1
+ t = gets . to_i
2
+ t . times do
3
+ a , b , c , d = gets . split ( /\s +/ ) . map ( &:to_i )
4
+ if b != d
5
+ e = d *a
6
+ bottom = d *b
7
+ f = b *c
8
+ else
9
+ e = a
10
+ f = c
11
+ bottom = d
12
+ end
13
+ top = e . lcm ( f )
14
+ p = top . gcd ( bottom )
15
+ puts "#{ top /p } #{ bottom /p } "
16
+ end
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < stack>
3
+ #include < queue>
4
+ #include < string>
5
+ #include < algorithm>
6
+ #include < map>
7
+
8
+ using namespace std ;
9
+
10
+ int main () {
11
+ int n;
12
+ unsigned k, m;
13
+ string s;
14
+
15
+ cin >> n;
16
+ for (int i = 0 ; i < n; i++) {
17
+ cin >> k;
18
+ s = " " ;
19
+ while (k > 0 ) {
20
+ m = (k-1 ) % 26 ;
21
+ s += ' A' + m;
22
+ k = (k-m) / 26 ;
23
+ }
24
+
25
+ for (int j = 0 ; j < s.length () / 2 ; j++) {
26
+ swap (s[j], s[s.length ()-1 -j]);
27
+ }
28
+
29
+ cout << s << " \n " ;
30
+ }
31
+ return 0 ;
32
+ }
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < stack>
3
+ #include < queue>
4
+ #include < string>
5
+ #include < algorithm>
6
+ #include < map>
7
+
8
+ using namespace std ;
9
+
10
+ struct character {
11
+ int h, a;
12
+ };
13
+
14
+ character chars[100000 ];
15
+
16
+ bool comparator (const character& left, const character& right) {
17
+ return left.a > right.a ;
18
+ }
19
+
20
+ int main () {
21
+ int n, H, A, a, t, ans;
22
+ unsigned long long int sum;
23
+
24
+ cin.tie (0 );
25
+ ios_base::sync_with_stdio (false );
26
+
27
+ cin >> t;
28
+ while (t--) {
29
+ cin >> n >> H >> A;
30
+ sum = 0 ;
31
+ for (int j = 0 ; j < n; j++) {
32
+ cin >> chars[j].h >> a;
33
+ chars[j].a = (chars[j].h / A) * a;
34
+ if ((chars[j].h % A) != 0 ) {
35
+ chars[j].a += a;
36
+ }
37
+ sum += chars[j].a ;
38
+ }
39
+
40
+ if (sum < H) {
41
+ cout << -1 << " \n " ;
42
+ } else {
43
+ sort (chars, chars + n, comparator);
44
+ ans = -1 ;
45
+ while (H > 0 ) {
46
+ ans++;
47
+ H -= chars[ans].a ;
48
+ }
49
+ cout << ans << " \n " ;
50
+ }
51
+ }
52
+
53
+ return 0 ;
54
+ }
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < stack>
3
+ #include < queue>
4
+ #include < string>
5
+ #include < algorithm>
6
+ #include < map>
7
+
8
+ using namespace std ;
9
+ int n;
10
+ unsigned digits (unsigned long long int n) {
11
+ unsigned digits = 0 ;
12
+ while (n) {
13
+ n /= 10 ;
14
+ digits++;
15
+ }
16
+ return digits;
17
+ }
18
+
19
+ unsigned long long int S (unsigned long long int n) {
20
+ if (n == 0 ) {
21
+ return 0 ;
22
+ }
23
+
24
+ unsigned long long int ans = 0 , t = 1 ;
25
+ unsigned l = digits (n);
26
+
27
+ if (l > 1 ) {
28
+ ans = 9 ;
29
+ for (int i = 2 ; i < l; i++) {
30
+ ans += 9 *t;
31
+ t *= 10 ;
32
+ }
33
+ t *= 10 ;
34
+ int first = n / t;
35
+ int last = n % 10 ;
36
+ ans += (first-1 )*(t/10 );
37
+
38
+ if (first <= last) {
39
+ ans += (n % t) / 10 + 1 ;
40
+ } else {
41
+ ans += (n % t) / 10 ;
42
+ }
43
+ } else {
44
+ ans = n;
45
+ }
46
+
47
+ return ans;
48
+ }
49
+
50
+ int main () {
51
+ unsigned long long int l,r;
52
+ int t;
53
+ cin.tie (0 );
54
+ ios_base::sync_with_stdio (false );
55
+ cin >> t;
56
+ while (t--) {
57
+ cin >> l >> r;
58
+ cout << S (r) - S (l-1 ) << " \n " ;
59
+ }
60
+ return 0 ;
61
+ }
You can’t perform that action at this time.
0 commit comments