codeforces 570b java

Solutions on MaxInterview for codeforces 570b java by the best coders in the world

showing results for - "codeforces 570b java"
Kyla
03 Sep 2020
1sizeOfRange,otherpick=map(int,input().split())
2if(sizeOfRange==1 and otherpick==1):
3    print(sizeOfRange)#1 number cant really fight can you
4else:
5    if(sizeOfRange/2<otherpick):
6        print(otherpick-1)
7    else:
8        print(otherpick+1)
9#so in a show of guessing the price of a object
10#there is only 2 contestent
11#price of the product 100
12#first person says the price is 50 you just say its 50+1 or and you win
13#you can say its 50-1
14#either way its 50/50 chance of wining
Lya
18 Feb 2017
1//package com.company;
2
3import java.io.*;
4import java.util.*;
5
6//public class SimpleGame {
7        public class Main {
8
9    public static void main(String[] args) throws IOException {
10        int a=sc.nextInt(),b=sc.nextInt();
11        int half=a/2;//3 1//2
12        if(half>=b){
13            int ans=b+1;
14            out.println((ans==0?1:ans)+"");
15        }else {
16            int ans=b-1;
17            out.println((ans==0?1:ans)+"");
18        }
19        close.close();
20    }
21
22    static class Sc {
23        final private int BUFFER_SIZE = 1 << 16;
24        private DataInputStream din;
25        private byte[] buffer;
26        private int bufferPointer, bytesRead;
27
28        public Sc() {
29            din = new DataInputStream(System.in);
30            buffer = new byte[BUFFER_SIZE];
31            bufferPointer = bytesRead = 0;
32        }
33
34        public Sc(String file_name) throws IOException {
35            din = new DataInputStream(new FileInputStream(file_name));
36            buffer = new byte[BUFFER_SIZE];
37            bufferPointer = bytesRead = 0;
38        }
39
40        public String readLine() throws IOException {
41            byte[] buf = new byte[64]; // line length
42            int cnt = 0, c;
43            while ((c = read()) != -1) {
44                if (c == '\n')
45                    break;
46                buf[cnt++] = (byte) c;
47            }
48            return new String(buf, 0, cnt);
49        }
50
51        public String nextString() throws IOException {
52            StringBuilder sb = new StringBuilder();
53            int n = read();
54            while (isWhiteSpace(n))
55                n = read();
56            while (!isWhiteSpace(n)) {
57                sb.append((char) n);
58                n = read();
59            }
60            return sb.toString();
61        }
62
63        private boolean isWhiteSpace(int n) {
64            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
65                return true;
66            return false;
67        }
68
69        public int nextInt() throws IOException {
70            int ret = 0;
71            byte c = read();
72            while (c <= ' ')
73                c = read();
74            boolean neg = (c == '-');
75            if (neg)
76                c = read();
77            do {
78                ret = ret * 10 + c - '0';
79            } while ((c = read()) >= '0' && c <= '9');
80
81            if (neg)
82                return -ret;
83            return ret;
84        }
85
86        public long nextLong() throws IOException {
87            long ret = 0;
88            byte c = read();
89            while (c <= ' ')
90                c = read();
91            boolean neg = (c == '-');
92            if (neg)
93                c = read();
94            do {
95                ret = ret * 10 + c - '0';
96            }
97            while ((c = read()) >= '0' && c <= '9');
98            if (neg)
99                return -ret;
100            return ret;
101        }
102
103        public double nextDouble() throws IOException {
104            double ret = 0, div = 1;
105            byte c = read();
106            while (c <= ' ')
107                c = read();
108            boolean neg = (c == '-');
109            if (neg)
110                c = read();
111
112            do {
113                ret = ret * 10 + c - '0';
114            }
115            while ((c = read()) >= '0' && c <= '9');
116
117            if (c == '.') {
118                while ((c = read()) >= '0' && c <= '9') {
119                    ret += (c - '0') / (div *= 10);
120                }
121            }
122
123            if (neg)
124                return -ret;
125            return ret;
126        }
127
128        private void fillBuffer() throws IOException {
129            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
130            if (bytesRead == -1)
131                buffer[0] = -1;
132        }
133
134        private byte read() throws IOException {
135            if (bufferPointer == bytesRead)
136                fillBuffer();
137            return buffer[bufferPointer++];
138        }
139
140        public void close() throws IOException {
141            if (din == null)
142                return;
143            din.close();
144        }
145    }
146
147
148    static class Print {
149        private final OutputStream out;
150
151        public Print() {
152            this.out = System.out;
153        }
154
155        public void print(String str) throws IOException {
156            for (int i = 0; i < str.length(); i++) {
157                out.write(str.charAt(i));
158            }
159        }
160
161        public void println(String str) throws IOException {
162            print(str);
163            out.write('\n');
164        }
165
166        public void close() throws IOException {
167            out.close();
168        }
169    }
170
171    static Sc sc = new Sc();
172    static Print out = new Print();
173    static BufferedWriter close = new BufferedWriter(new OutputStreamWriter(System.out));
174}
similar questions
queries leading to this page
codeforces 570b java