Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
Страница 4 |
Hint to this question | guilty spark | 1023. Пуговицы | 29 авг 2020 11:09 | 1 |
If you pick n-1 as l then the second player will always win, so answer can never be 0 0 means picked up the first player and 1 means picked up the second; Case 1: 3 buttons for i = 1 //doesn't make sense to solve for 1 since its asked to choose >=2 1 2 3 0 1 0 //first player won for i = 2 1 2 3 0 0 1 0 1 1 // first play wins in each case Case 2: 4 buttons for i = 2 1 2 3 4 0 1 1 0 0 1 0 0 //first player wins in both these cases for i = 3: 1 2 3 4 0 0 0 1 0 1 1 1 0 0 1 1 //second player wins in each case case 3: 6 buttons (5 and 6 are similar) 1 2 3 4 5 6 for i = 2 0 1 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 1 //second player is winning It's clearly seen that the minimal choice to win is k such that n %(k+1) == 0 since n%((n-1)+1) is always 0, n-1 is always an answer in case no smaller answer exists. |
explain the logic behind this problem | Unsocial_A | 1023. Пуговицы | 7 июн 2022 10:19 | 3 |
I have seen many people solve this problem using divisor of given number(k).But i cannot understand how it works.Can anyone explain me how this logic works?? sorry for bad english you need to be in control. you are in control when you keep the first player in "loop". if you take number of buttons is 6, say, then the "loop" length is 3, i.e. if you take max number of buttons as 3 - 1 = 2, then whatever amount the first player takes you can keep them in loop. if they take first time 1, you take 2 - in sum 3, 3 - remaining, you are a winner. if they take 2 - you take 1, 3 remaining again - you are a winner. so, idea is to find the smallest divisor of a number > 2 & answer will be that - 1. hope that makes sense. Edited by author 18.01.2019 19:50 WLOG, let's break `k` elements of heap into block of length `d`. The numbers below are listed from 1, ..., k in their congruent modulo of `d`. [1, 2, ...., (d - 1), d], [1, 2, ...., (d - 1), d], ......(k / d) blocks. Here [..] is a block notation. B = #blocks of length `d` = (k / d) Basis: If B = 1, it's always true, as `first player` can pick whatever from 1, ..., (d - 1), `second player` always left with atleast 1 element by less then d to be picked. So `second player` player will greedily pick all remaining element in the block as an optimal move for his/her winning. Hypothesis: Let say it's true upto (B - 1) blocks that `second player` has taken the last element. Proof: If we have B block then since it is true for (B - 1) blocks we left with 1 block of element to pick and since `first player` is the who pick first in the last 1 block by using the `basis` we know that `second player` is always the winner. Hence, if we take the divisor of number of elements in the heap (k) we always end of with `second player` being the winner. Edited by author 07.06.2022 10:23 Edited by author 07.06.2022 10:23 |
WA #13? | Ionkin M [Samara SAU #617] | 1023. Пуговицы | 31 мар 2017 13:30 | 1 |
WA #13? Ionkin M [Samara SAU #617] 31 мар 2017 13:30 Check your program for very big K. It helped me. Edited by author 31.03.2017 14:38 |
I have AC with such idea but I don't understand how to get a formula or faster solution | IlushaMax | 1023. Пуговицы | 18 янв 2019 12:11 | 3 |
var i,n,l,j:longword; found:boolean; begin readln(n); repeat found:=False; for j:=3 to n div 2 do begin if n mod j=0 then begin found:=True; break; end; end; if found then n:=j; until not found; writeln(n-1); readln; end. Please help me to optimize my code. It's 0.405 sec for j := 3 to sqrt(n) do will help you :) > for j := 3 to sqrt(n) do will help you :) will it? for sqrt(8) = 2.8, but answer should be 4 - 1 = 3 |
k=7 | Temur | 1023. Пуговицы | 17 апр 2016 15:16 | 2 |
k=7 Temur 25 ноя 2015 16:33 Re: k=7 IlushaMax 17 апр 2016 15:16 No. Because we know that if k=3 then answer 2. So we can remove 3 buttons from bunch. And find answer for k=4, but answer for this input will be 3. So 2!=3 and such answer is wrong. So answer will be 6 (cause we can't divide it on groups answer for those we know). |
What is 0.001 solution? | OZone | 1023. Пуговицы | 31 окт 2013 11:40 | 2 |
How it is posible to get AC in 0.001 s? What time do such ACs take to get L for K= 99999989? Could anyone give a hint to make it faster than O(sqrt(K))? I think one can get AC in 0.001 by giving solutions that have precalculated values for K = 3...10^8. |
What is 0.015 solution? | PrankMaN | 1023. Пуговицы | 30 мар 2013 01:26 | 2 |
It's not a hard problem, if you use Sprague–Grundy theorem. But this solution is about 0.5 in best case. I saw some people getting AC in 0.015. What's the idea of their solution? |
wa#7 help pleaaaaaaaaaaaaaaaaaaaaase!!! | BOyKA | 1023. Пуговицы | 18 авг 2012 04:43 | 1 |
what is the test #7 Edited by author 18.08.2012 04:46 |
JAVA - What's wrong with my solution (Crashed) | JOLO_ | 1023. Пуговицы | 16 авг 2012 02:27 | 2 |
public class Buttons { public static void main(String[] args) { //convert parameter into int int N = 0; try { N = Integer.parseInt(args[0]); } catch(NumberFormatException ignore) {} //find L for(int i = 3; i < Math.sqrt(N); i++) { if(N%i == 0) { System.out.println(i-1); System.exit(1); } } System.out.println(N-1); } } P.S. On my computer it works perfectly Numbers are read from stdin |
Be careful that L>=2 | teoy | 1023. Пуговицы | 14 май 2016 04:40 | 3 |
I got a WA because I think L can be 1 thnx man .. that should help 5 years later, same trap grabbing me :( |
WA3 | alexProgrammer | 1023. Пуговицы | 24 сен 2011 10:27 | 1 |
WA3 alexProgrammer 24 сен 2011 10:27 |
hhh | gaoshangbo | 1023. Пуговицы | 20 июл 2011 09:30 | 1 |
hhh gaoshangbo 20 июл 2011 09:30 Bash Game Edited by author 20.07.2011 09:30 Edited by author 20.07.2011 09:31 |
why time timit 10 test? version 2 :) | Александр | 1023. Пуговицы | 19 сен 2011 16:44 | 2 |
var i,j:integer; l,k,p,m:int64; begin read(k); p:=0; l:=2; while l<100000000 do begin if k mod (l+1)=0 then begin write(L); halt; end else inc(l); end; write(0); end. Edited by author 05.05.2011 20:04 Edited by author 05.05.2011 20:04 "l<100000000" Indeed, why? |
Страница 3 |
why time timit 10 test? | Александр | 1023. Пуговицы | 5 май 2011 18:00 | 1 |
var i,j:integer; l,k,p,m:int64; begin read(k); p:=0; l:=2; while p<>1 do begin m:=l+1; i:=0; while i<k do begin i:=i+m; p:=i; end; if p=k then begin write(L); halt; end else begin p:=0; inc(l); end; end; end. |
Can anybody explain the solution? | Yegor Stepanov | 1023. Пуговицы | 2 апр 2011 20:23 | 1 |
I really don't understand why is the answer is least divisor - 1. Can anybody help? |
No 0 EXI | yangdong | 1023. Пуговицы | 21 окт 2010 09:38 | 1 |
In my pgm there's no '0'... At least we can print(n-1) :) |
time | abc | 1023. Пуговицы | 30 сен 2010 20:10 | 1 |
time abc 30 сен 2010 20:10 with TL < 0.25 it's more interesting, and that's enough even for Java && C# |
VERY easy :) | RezistaL | 1023. Пуговицы | 27 ноя 2011 17:42 | 4 |
A - first divider of K, which is more or equal than 3 (A>=3) We need write A-1. AC - 0.578 and 134 KB Edited by author 27.03.2010 14:34 I made the same, but WA on test 11. What's the matter? I see a solution in another topic, there used I64. Oh, don't tell me to use I64. 10^8 is involved to int. Why does not it work? <code> #include <stdio.h> int K; int L; int main() { scanf("%d", &K); L = 2; while (K%(L+1) != 0) { if ((L+1)*(L+1) > K) { printf("%d\n", K-1); return 0; } L++; } printf("%d\n", L); return 0; } </code> Edited by author 18.08.2011 03:22 At last. I undestood. Expression "if ((L+1)*(L+1) > K)" not correct, because we skip 2. Since for K=8, we return 7, when the correct answer is 3. Edited by author 18.08.2011 03:56 > I made the same No I see u didn't :) The actual solution is 5 lines, 4 of which are declarations and i/o Edited by author 27.11.2011 17:43 |
WA#6 | VorobeY1326 | 1023. Пуговицы | 10 ноя 2009 19:51 | 1 |
WA#6 VorobeY1326 10 ноя 2009 19:51 Help somebody!! Why my code has WA6..or GIVE SOME TESTS, please)) #include<iostream> #include<vector> #include<cmath> using namespace std; vector<int>easy_numbers(0); int next_number(int numb_of_numb) { int step=easy_numbers.size()-1; int curr_number=easy_numbers[step]; while(step+1<numb_of_numb) { while(1) { curr_number++; int sq_root=sqrt(static_cast<double>(curr_number))+1; int buf_step; buf_step=0; while(easy_numbers[buf_step]<sq_root) if (curr_number%easy_numbers[buf_step++]!=0) continue; else goto g1; break; g1: } easy_numbers.push_back(curr_number); step++; } return curr_number; } int main() { int K; int L=-1; cin >> K; if (K==4) {cout << 3; exit(0);} easy_numbers.push_back(3); int buf=0; while((easy_numbers[buf]*easy_numbers[buf])<=K) next_number(++buf); for (int i=0;i<easy_numbers.size();i++) { if (K%easy_numbers[i]==0) {L=easy_numbers[i]-1; break;}
} if (L==-1 && K%2==0) {L=K/2-1; cout << L; exit(0);} if (L==-1) {L=K-1; cout << L; exit(0);} cout << L; return 0; } |
Something strange... | Vukasin | 1023. Пуговицы | 31 мар 2017 14:16 | 3 |
When i write my program like: #include<cstdio> long long int i,k; int main(){ scanf("%lld",&k); i=k / 3; while(k % i!=0){ i=k /(k / i +1); } i got AC,but when i change it to: #include<cstdio> int main(){ long long int i,k; scanf("%lld",&k); i=k / 3; while(k % i!=0){ i=k /(k / i +1); } printf("%lld",(k / i-1)); } printf("%lld",(k / i-1)); } i got WA5...does anyoe know how is that possible? wtf i=k / 3; ?? If k%(l+1)==0 then 2nd have a chance to win. And 1st wins if k%(l+1)!=0 try it: for (l=3;k%l!=0;l++);; Edited by author 31.03.2017 14:34 |