|
|
Lets say there are 5 Steaks and capacity of pan is 4. Step 1: Cook first 4 one side for 1 minute. Step 2: Replace 1 one sided cooked steak with completely uncooked (remaining) one and cook for next 1 minute. Step 3: Now the chef has 3 completely cooked and 2 Half cooked. Cook the remaining 2 half cooked for another one minute. so 1 minute at each step, hence 3 minutes total minimal time. However, story doesn't end here :-). Lets take another example Now, Lets say there are 7 Steaks and capacity of pan is 4. Step 1: Cook first 4 one side for 1 minute. Step 2: Replace 3 one sided cooked steak with completely uncooked (remaining) three and cook for next 1 minute. Step 3: Now the chef has 1 completely cooked and 6 Half cooked. Cook 4 steaks from half cooked six for another one minute. Step 4: Last cook final 2 half cooked one for another one minute So total minimum time take is 4 minute. 1 minute at each step. Please keep in mind the scenarios where 0 steaks or steaks less then cooking capacity of pan. Edited by author 08.06.2017 20:19 Edited by author 08.06.2017 20:20 the scenario with n == 0 or k == 0 won't happen as in the statements it says 1 <= n, k <= 1000 import java.io.*; import java.util.*; public class task { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int k = in.nextInt(); int t; if(n>=1 && k<=1000) { if((int) (n * 2.0 / k) == (n * 2.0 / k)) t = (int) (n * 2.0 / k); else t = 1 + (int) (n * 2.0 / k); out.print(t);
} out.flush(); } } Братан эту задачку на 1 вывод решить можно) зачем тебе эти условия Edited by author 29.10.2015 01:41 Я одного не пойму, как можно обжарить 3 бифа с обеих сторон за 3 минуты, если влазит на сковороду всего 2 шт???))) На первой минуте жаришь первые 2шт с одной стороны, на второй их же со второй. На третей минуте последний биф 1 сторона 4я минута 2я сторона 3го бифа!!. В итоге правильный ответ 4 минуты, а не 3 как написано в примерах. Изи. Смотри 1 и 2 это первые и вторые стороны бифов. B это номер бифа. Разделю их точкой первая минута: 1.1 1.2 вторая минута: 2.1 1.3 третья минута: 2.2 2.3 Я тоже также думал, пока не прочитал в дискуссии: http://acm.timus.ru/forum/thread.aspx?id=36182&upd=636324641214598077 1-я минута - Жарится одна сторона двух стейков.(1-я сторона) 2-я минута - Жарится один из первых стейков(2-я сторона) + третий стейк(1-я сторона) 3-я минута - Жарится второй из первых стейков(2-я сторона) + третий стейк(2-я сторона) i am doing (n%k)+(n/k) after putting restriction on k(k<=1000) and n(n>=1). but my answer is said to be wrong.please help. Edited by author 30.06.2013 01:11 14%4 +14/4=2+3=5 but ans is 4. every pancake has 2 sides so 13 pancake has 26 sides.pan fry can fry 4 pancakes at one minute one side. so, IF(2*13%4>=1) sum=((2*n)/k)+1; else{ sum=(2*n)/k; } calculate it . import java.util.Scanner; public class Zadachi { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int x = 2; if(n<=k){ System.out.print(x); }else{
if (n*2 % k == 0){ System.out.print(n*2/k); }else{ System.out.print(n*2/k+1); } }
} } #include "iostream" using namespace std; int main() { int a, b, rz; cin >> a >> b; if (b == 2 && a != 1 || b == 1 && a != 1) { rz = 2 * a / b; } else { if (a % b != 0) { rz = 2 * (a / b + 1); } else { rz = 2 * a / b; } } cout << rz; return 0; } i tested it a lot, pleas help may be i am so silly.... public class Pan { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int k = scanner.nextInt(); int m = 2*n; if (m%k == 0){ System.out.println(m/k); } else{ System.out.println(m/k+1); } } } why Wrong Answer? import static java.lang.Math.*; import java.util.*; public class UralSteaks { public static void main(String[] args) { Scanner in=new Scanner(System.in); int n,k; n=in.nextInt(); k=in.nextInt(); int t=(int)ceil(2*(float)n / (float)k); System.out.print(t); }
} help plz! New tests have been added to the problem, all accepted solutions have been rejudged. 490 authors have lost their AC. Компилятор вычисляет все верно, но здесь задача не проходит. Подскажите, знатоки, в чем проблема? import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); double n = in.nextDouble(); double k = in.nextDouble(); if(n>=1&&n<=1000&&k>=1&&k<=1000){ double a = ((n/k)*2); int b = (int)Math.round(a); System.out.println(b); } } } import java.io.*; import java.util.*; public class t1820 { public static void main(String[] args){ Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int k = in.nextInt(); int rez = 2; if (n>k){ if (n % k == 0) { rez = 2*n; } else{ if (n % k > k / 2) { rez = (n/k+1)*2; } else { rez = (n/k-1)*2+3; } } } out.println(rez); out.flush(); } } Guys, I have no idea why it doesn't pass this test. Any suggestions? public static int getMinutes(int n, int k) { if (k == 1){ return n * 2; } else if ( k >= n) { return 2; } else if (n > k) { return n - k + 2; } return 0; } [n ,k] = [int(x) for x in input().split()] if n >= k: ans = 2 * n // k if 2*n%k > 0: ans += 1 print(ans) else: print(2) and [n ,k] = [int(x) for x in input().split()] if n >= k: ans = 2 * n // k if 2*n%k > 1: ans += 1 print(ans) else: print(2) Both is accepted. But second is worng. Need test: 5 3 All ok!) Edited by author 03.10.2015 14:49 Edited by author 03.10.2015 14:49 Edited by author 05.10.2015 18:55 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; //URAL STEAKS public class P { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); String line; int ans; line = br.readLine().trim(); String str[]; str = line.split(" "); int N = Integer.parseInt(str[0]); int K = Integer.parseInt(str[1]); if(2*N%K>1){ ans = (2*N/K)+1; }else{ ans = (2*N/K); } out.print(ans); out.flush(); } } При N = 1, K = 2 программа выдаёт 1, а должна 2 по условию задачи. Please give answer in English... if (n<=k) the answer is 2 I understand the problem. There is one frying pan! Edited by author 29.08.2015 13:17 Edited by author 29.08.2015 14:14 Edited by author 29.08.2015 14:15 First code gives wrong answer test #13. In the next code I changed System.out.print(2*n/k+2*n%k); and used Math.ceil() System.out.print((int)Math.ceil(2*(float)n/(float)k)); The code was accepted. What's wrong? Edited by author 03.08.2015 07:16 Edited by author 03.08.2015 07:17 Edited by author 03.08.2015 07:17 Edited by author 03.08.2015 07:17 Edited by author 03.08.2015 07:18 Edited by author 03.08.2015 07:18 Edited by author 03.08.2015 07:22 var n,k,l:real; begin read(n,k); l:=(n*2/k); if trunc(l)=0 then write(2) else if frac(l)=0 then write(l) else write(trunc(l)+1); end. |
|
|