Show all threads Hide all threads Show all messages Hide all messages | correct code | Vlad | 1639. Chocolate 2 | 8 Mar 2025 12:26 | 3 | int main(){ int x, y; cin >> x >> y; if ((x*y-1)%2==1) cout << "[:=[first]"; else cout << "[second]=:]"; return 0; } #include <iostream> using namespace std; int main () { int m,n; cin>>m>>n; if((m*n)%2==0)cout<<"[:=[first]"; else cout<<"[second]=:]"; return 0; } | Bu....... | Nargiza Asqarova | 1639. Chocolate 2 | 13 Nov 2020 16:42 | 5 | xatosi qayerda bilasizmi? var m,n:1..50; begin read(m,n); if odd(m*n)then write('[second]:=]') else write('[:=[first]'); end.
var a,n,m:word; begin a:=m*n-1; if a mod 2=0 then writeln('[second]=:]') else writeln('[:=[first]');readln; readln;end. #include <stdio.h> void main() { int n,m; scanf("%d %d",&m,&n); printf("%s",(m*n%2)?"[second]=:]":"[:=[first]" ); } men paskallni yaxshi tushunmiyman C++ da kod quyidagicha yozilgan: #include<iostream> using namespace std; int main() { int n,m,s1=0,s2=0,i=0; cin>>n>>m; while(i==0) { if(n%2==0||m%2==0) { if(n%2==0&&m%2==0) { if(n>m)n=n/2; else m=m/2; } else if(n%2==0)n=n/2; else m=m/2; s1+=n*m; } else { s1+=1; s2+=n*m-1; n=0;m=0;i=1; }
//------------------------------------------------ if(n%2==0||m%2==0) { if(n%2==0&&m%2==0) { if(n>m)n=n/2; else m=m/2; } else if(n%2==0)n=n/2; else m=m/2; s2+=n*m; } else { s2+=1; s1+=n*m-1; n=0;m=0;i=1; }
} if(s1>=s2)cout<<"[:=[first]"; else cout<<"[second]=:]"; return 0; } //javada ,in java import java.util.Scanner; public class ONETHOUSANDTWO { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int s1 = 0, s2 = 0, i = 0; if ((m * n - 1) % 2 == 0) { System.out.println(); } while(i==0) { if(n%2==0||m%2==0) { if(n%2==0&&m%2==0) { if(n>m)n=n/2; else m=m/2; } else if(n%2==0)n=n/2; else m=m/2; s1+=n*m; } else { s1+=1; s2+=n*m-1; n=0;m=0;i=1; } //------------------------------------------------ if(n%2==0||m%2==0) { if(n%2==0&&m%2==0) { if(n>m)n=n/2; else m=m/2; } else if(n%2==0)n=n/2; else m=m/2; s2+=n*m; } else { s2+=1; s1+=n*m-1; n=0;m=0;i=1; } } if (s1>=s2) System.out.println("[:=[first]"); else System.out.println("[second]=:]"); } } men paskallni yaxshi tushunmiyman C++ da kod quyidagicha yozilgan: #include<iostream> using namespace std; int main() { int n,m,s1=0,s2=0,i=0; cin>>n>>m; while(i==0) { if(n%2==0||m%2==0) { if(n%2==0&&m%2==0) { if(n>m)n=n/2; else m=m/2; } else if(n%2==0)n=n/2; else m=m/2; s1+=n*m; } else { s1+=1; s2+=n*m-1; n=0;m=0;i=1; }
//------------------------------------------------ if(n%2==0||m%2==0) { if(n%2==0&&m%2==0) { if(n>m)n=n/2; else m=m/2; } else if(n%2==0)n=n/2; else m=m/2; s2+=n*m; } else { s2+=1; s1+=n*m-1; n=0;m=0;i=1; }
} if(s1>=s2)cout<<"[:=[first]"; else cout<<"[second]=:]"; return 0; } | Python Solution. | Vladislav Ershov | 1639. Chocolate 2 | 21 Jul 2019 14:02 | 1 | m, n = map(int, input().split()) if (m*n) % 2 == 0: print("[:=[first]") else: print("[second]=:]") | Я и Балл | SpamBot | 1639. Chocolate 2 | 28 Jan 2019 02:47 | 1 | Жеванный крот, одна халтура! Мало того что английский перевод кривой как рог барана, так ещё и проверяющая система хромает! Отправляем на проверку: Var s, s1: ansistring; a, b: byte; Begin readln(s, s1); val(s[length(s)], b); End. Получаем вполне обоснованный WA1. Теперь дополним: Var s, s1: ansistring; a, b: byte; Begin readln(s, s1); val(s[length(s)], b); val(s1[length(s1)], a); End. Всё, вселенная дрогнула: "Access violation"... *facepalm* И всё бы ничего, но подобное происходит уже где-то раз пятый (в разных задачах). И да, прочитать string целиком, а затем разрезать - выдаёт ту же ошибку AV: Var s, s1: ansistring; i, a, b: byte; Begin readln(s); for i:=1 to length(s) do if s[i]:=' ' then begin val(s[i-1], b); val(s[length(s)], a); break; end; End. Сделайте уже нормальный ввод!!!!1 | How did you find the alhorithm, AC-guys? | Komarov Dmitry [Pskov SPI] | 1639. Chocolate 2 | 8 Dec 2017 00:33 | 9 | I hate such tasks so much! It's not programming, it's pure math!! So how did you proved the algorithm? I broke my brain truying to solve it!! You must understand that there are needed as mush cuts as there are little squares in the bar (minus 1). Imagine that the bar has the shape 1xnm. How many cuts? (n-1), yeah? Since at the very end all pieces are the little squares, the shape of intermediate cuts doesn't matter, the total cuts count to (n-1). to melkiy Komarov Dmitry [Pskov SPI] 12 Nov 2009 11:17 Thank you very much!) You saved hours of my life! My observation: one cut buys us plus one piece of chocolate, because we can cut only one piece at a time. So, after the first cut we have two pieces, after the second one, we have three pieces, and so on until we have n*m pieces. Now it's easy to see that we only need to check the parity of n*m That's the thought. It is conjectured that however youcut it during the process, the total steps are always the same, but I didn't prove it. Now Iget it. Thank you. There is a winning strategy for the second player is to mirror moves of the first, but if N or M is even, the first player can split it in two halves - the only move cannot be mirrored and wins. my solution: #include <iostream> #include <string> #include <vector> #include <set> #include <queue> #include <map> #include <stack> #include <algorithm> #include <bitset> #include <cstring> #include <cmath> #include <cstdlib> #include <cstdio> #include <iomanip> #define F first #define S second #define ll long long #define len length() #define sqr(x) x*x #define pb push_back #define mp make_pair #define sz(x) ((int) (x).size()) #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define bp(x) __builtin_popcount(x) #define INF numeric_limits<long long int>::max() #define frp freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++) const int maxn = (int)1e6; const int mod = (int)1e9 + 7; using namespace std;
int n,m; main(){ scanf("%d%d",&n,&m); if(n*m%2==0) puts("[:=[first]"); else puts("[second]=:]");
return 0; } mathem much important in programming. U MUST know that, if u dont wants to write indian code | Solved in O(1). | Marginean Ciprian | 1639. Chocolate 2 | 22 Jan 2017 21:09 | 2 | Oh, its realy easy! Just: if ((a*b) % 2 = 0) res = "first" else res = "second"; | Скорость негодует | Aleksandr | 1639. Chocolate 2 | 16 Jan 2017 23:11 | 4 | Народ, кто может указать на часть моего кода которая тормозит алгоритм? Чистил как мог, не смог выйти за 0.125 секунд import java.util.Scanner; public class Timus { public static void main (String[] args) { Scanner in = new Scanner(System.in);
byte m = in.nextByte(), n = in.nextByte();
System.out.println( (m*n-1)%2==0 ? "[second]=:]" : "[:=[first]");
in.close();
} } Всё нормально, просто джава медленная. Вон у вас задача a+b за 0.109. Спасибо за пояснение;) а каким же образом люди в топе выходят за 0.05 секунд? Вон первое место в А+B аж за 0.015 работает! Наверняка люди обходят стороной медленные методы и операции. Может вы знаете ресурс где можно почитать об этом? Поиск в гугле ни привёл ни к чем К сожалению, не могу сказать точно. Тут есть несколько моментов. Во-первых, более ранняя джава была быстрее, что можно увидеть по тому, что в основном большинство сабмитов, где указано java 1.5 / java 1.6, быстрее, чем те, в которых java 1.8. Конечно, этот сабмит а+б за 0.015 как раз на джаве 1.8, для меня это конечно странно. Может в коде в опциях был выставлен какой-то ключ для использования более ранней версии или типа того... Во-вторых, "общий" совет, который я могу дать — используйте BufferedReader (и если надо, StreamTokenizer) вместо Scanner'a, потому что последний в джаве обычно медленнее. (см. также код внизу страницы http://acm.timus.ru/help.aspx?topic=java&locale=ru). Хотя, конечно, для программ с маленьким объёмом входных данных разница не должна быть сильно критичной, но там где надо считывать со входа мегабайты — она очень ощутима. | ac c++ | lhyx1990 | 1639. Chocolate 2 | 26 Jan 2014 15:08 | 1 | ac c++ lhyx1990 26 Jan 2014 15:08 #include <iostream> using namespace std; int main(int argc, const char * argv[]) { int m, n; cin >> m >> n;
int num = m * n - 1;
if (num % 2== 1) { cout << "[:=[first]"; }
else { cout << "[second]=:]"; }
} num is total number of splits | what's wrong with this code.....???? | shailendrasky | 1639. Chocolate 2 | 31 Dec 2013 01:56 | 1 | //1639. Chocolate 2 #include<stdio.h> int main() { int n; printf((scanf("%d",&n)*n*scanf("%d",&n)*n)%2==0?"[:=[first]\n":"[second]=:]\n");
} it works fine in my compiler..but don't know why it shows wrong answer here while submission... Edited by author 31.12.2013 01:59 | error in test#9 | Cawa222 | 1639. Chocolate 2 | 25 Jul 2013 00:45 | 1 | #include <iostream> #include <math.h> using namespace std; void main(void) { int a,b,c; cin>>a>>b; c=0; c=a/2+a%2+b/2+b%2;
if (((a==1)&&(b!=1))||((a!=1)&&(b==1))) { c=c-1; } if (c%2) cout <<"[:=[first]" ; else cout <<"[second]=:]" ;
} whot is wrong? Edited by author 25.07.2013 00:45 | ??????? | BlackShark | 1639. Chocolate 2 | 4 Feb 2013 09:23 | 2 | ??????? BlackShark 6 Mar 2009 20:03 I dont understand why the number of moves is constant. How to prove it?? think in this way, each time a player makes a move, the number of chocolate pieces increases in one (first there is one piece, then two, then three and so on). But the game stop when there are n*m pieces, so there must've been n*m-1 moves. | am solutia | tudorfrent | 1639. Chocolate 2 | 1 Nov 2012 14:37 | 1 | | example | isolver | 1639. Chocolate 2 | 28 Apr 2012 12:30 | 1 | Please explain the sample input output. | where error????? | Kirill | 1639. Chocolate 2 | 20 Apr 2012 18:12 | 3 | #include<iostream> using namespace std; int main() { int a,m,n,; cin>>m>>n; a=(m*n)%2; if (a==0) cout<<"[:=[first]"; else if (a==1) cout<<"[second]=:]"; } | what s wrong here ? WA2 | Tom | 1639. Chocolate 2 | 4 Aug 2011 23:05 | 2 | i dont get it at all...it looks good though. at least to me help pls #include<iostream> using namespace std; int main(){
int m,n,a; cin >> m >> n; a=(m*n)%2; if(a==0) cout << "[:=[first]"; else if(a==1) cout << "[second]:=]"; } ok. = mark in "[second]:=]" is in the wrong place. should be "[second]=:]" . O_O - embarrassed. always something to learn. | why is my code wrong?????????? | milad | 1639. Chocolate 2 | 31 Jul 2011 00:50 | 2 | #include <iostream> using namespace std; int main() { int a,m,n; cin>>n>>m; a=(n*m)&2; if(a!=0) cout<<"[second]=:]"<<endl; else if(a==0) cout<<"[:=[first]"<<endl; return 0; } Edited by author 08.07.2011 21:11 Edited by author 08.07.2011 21:11 The error is in line: > a=(n*m)&2; Replace it with this: > a=(n*m)%2; Or this: > a=(n*m)&1; | It doesn't need "return 0" In the end of the program ? | jacinto | 1639. Chocolate 2 | 9 Jul 2011 21:34 | 2 | when I add the "return 0" in the end the program ,it showed wrong answer,but once removed the "return 0",it's accept!you guys know why? I am a new ACMer! i dunno why adding return 0 takes an error but if in the end of main() compiler doesnt find this operator it adds it automaticly Edited by author 09.07.2011 21:35 | Very easy :D | kutenin | 1639. Chocolate 2 | 2 Jan 2011 12:06 | 1 | Edited by author 19.01.2011 21:01 Edited by author 19.01.2011 21:01 | Answer | Bagdat | 1639. Chocolate 2 | 23 Mar 2009 00:20 | 1 | Answer Bagdat 23 Mar 2009 00:20 int a = (n*m)%2; System.out.println((a!=0)?("[second]=:]"):("[:=[first]")); | No topic | Vedernikoff Sergey (HSE: EconomicsForever!) | 1639. Chocolate 2 | 25 Oct 2008 22:29 | 1 | No topic Vedernikoff Sergey (HSE: EconomicsForever!) 25 Oct 2008 22:29 Edited by author 25.10.2008 22:38 |
|
|