Common Board| Show all threads Hide all threads Show all messages Hide all messages | | Whats wrong with this code? Please help | Naman Sharma | 1001. Reverse Root | 7 Feb 2020 13:12 | 2 | #include<iostream> using namespace std; float sqrt(long long2 n,int p) { int start = 0; int end = n; float ans; int mid; while(start <= end) { mid = (start+end)/2; if(mid*mid < n) start = mid + 1; else if(mid*mid > n) end = mid - 1; else { ans = mid; break; } } float increment = 0.1; for(int i = 0; i < p;i++) { while(ans * ans <= n) { ans += increment; } ans -= increment; increment /= 10; } return ans; } int main() { long long int n; while(cin >> n) { cout << sqrt(n,4) << endl; } } 1) Please read task, especially "from the last one till the first" carefully. Look at the example. 2) Your sqrt function lies. https://ideone.com/wcJVz0 | | What is the test #46? | ura | 2070. Interesting Numbers | 6 Feb 2020 19:45 | 2 | L=p^(q-1),p and q prima numbers. | | Test #9 | bsu.mmf.team | 1812. The Island of Bad Luck 2 | 5 Feb 2020 22:58 | 7 | Test #9 bsu.mmf.team 4 Feb 2011 02:56 Please, help with this test. I am always getting WA on it. I did 2 assumptions: 1. If after any iteration the radius becomes irrational - then the answer will be irrational too. 2. The numerator and denominator of resulting fraction both don't exceed 2^64. Are these assumptions wrong? If so, please, give me some useful tests. The one interesting test I found is: 1 1 30 34785346 3131185849/1170753394542713625 But it doesn't help me much... Edited by author 04.02.2011 02:56 Re: Test #9 Alipov Vyacheslav [Tomsk PU] 4 Feb 2011 22:50 The 1st assumption is right. The 2nd one seems to be wrong. I can't say exactly if the result always fits in int64, but temporary (or itermediate) calculations exceed 2^64 for sure. Answer to your test is wrong. In this test the denominators of intermediate fractions (before reduction) exceed 2^64. My AC program answer: 1/6265197409 Oh, thanks, now I understood why it gets WA. Now my program gives correct answer to this test (I optimized it a little bit), but I found several tests with the same problem. It is interesting for me to solve it without BigInteger, I guess, there exists such solution for this problem. After a lot of tries I gave up :( AC now, but with big numbers. Edited by author 07.02.2011 23:02 Re: Test #9 Toshpulatov (MSU Tashkent) 5 Feb 2020 22:58 Что бы не было переполнения вы могли сделать следующие : Представить r1 и r2 таким образом r1 = A / B ^ 2 r2 = A / C ^ 2 Где А = r1 * r2 / gcd(r1, r2); Отсюда найдете B и C. Теперь в чем прелесть такого представления: Вы наверное вывели формулу r3 = (r1 * r2 ) / (r1 + r2 + 2 * sqrt(r1, r2) ); Так вот если будете подставлять то получите r3 = A / ( B + C) ^ 2 т.е числитель не меняется а вот знаменатель будет меняться но не быстро ! I got Wa22(ac 1-21) under positions: r1*r2!=k*k-"irrational";(BUT IF i>min and i<MAX ONLY!) else 1/sqrt(r)=a/sqrt(r1)+b/sqrt(r2); a,b- recursion f(n,2i)=f(n-1,i),f(n,2i+1)=f(n-1,i)+f(n-1,i+1) All- __int64 AC now: a,b<=30- by induction. int- is enought, nor __int64, nor BigInteger Edited by author 27.02.2011 12:18 My mistake was: __int64 needed. a+b<=2^30 | | WA 9 | FaddeyKr | 2149. Pigeonhole Principle | 4 Feb 2020 03:10 | 2 | WA 9 FaddeyKr 23 Nov 2019 18:28 I have WA in the 9th test, please tell me this test. We have 4 case of perfect position of birds. I found the amount of flips for all cases. I used min_element() from algorithm.h to find the result, but it gave me WA 9. Then i replaced min_element() and found minimal by myself and my code finally accepted. Hope it will help you, good luck! | | Test cases 6 and 12 | Gilles Deleuze | 2088. Nostalgic Evening | 3 Feb 2020 14:52 | 1 | Test case #6: 9 40 10 10 10 10 10 10 10 10 10 10 0 5 6 1 0 0 0 0 0 0 12 20 Answer: 158882255 Test case #12: 10 20 52 4 2 3 6 7 6 3 6 5 6 6 0 0 0 0 1 0 0 0 0 1 10 50 Answer: 978217740 | | PyCharm execution is much faster than here | roman velichkin | 1698. Square Country 5 | 1 Feb 2020 20:13 | 1 | PyCharm calculates n=2000 in 0.55 sec while here I got exceed time limit with 2.020 sec. I don't get it. | | WA test 3. But it answers correctly on my machine... | jedianmb | 1044. Lucky Tickets. Easy! | 31 Jan 2020 17:11 | 2 | Can't find the error, because it gives the same answers as those stupid precalc solutions: #include <bits/stdc++.h> using namespace std; using ll = long long; int soma[40] = {0}; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, i, lim; ll ans = 0; cin >> n; lim = pow(10, n/2); for(i=0; i<lim; ++i){ soma[i%10 + (i/10)%10 + (i/100)%10 + (i/1000)%10]++; } for(i=0; i<=n*9; ++i){ ans += soma[i]*soma[i]; } cout << ans << '\n'; return 0; } for(i=0; i<=n*9; ++i){ ans += soma[i]*soma[i]; } i is out of soma range. | | Help!WA#11 | miao22 | 1671. Anansi's Cobweb | 30 Jan 2020 18:15 | 3 | #include<bits/stdc++.h> using namespace std; int n,m,q,a[100003],b[100003],c[100003]; vector<pair<int,int> >v; vector<int>g[100003]; bool vis[100003]; int qq[100003]; map<int,int>mp; void dfs(int x,int cc){ vis[x]=1; for(int i=0;i<g[x].size();i++) if(!vis[g[x][i]]) dfs(g[x][i],cc); qq[x]=cc; } int main(){ cin>>n>>m; for(int i=0;i<m;i++) cin>>a[i]>>b[i], a[i]--, b[i]--; cin>>q; for(int i=0;i<q;i++)cin>>c[i],c[i]--,v.push_back(make_pair(a[c[i]],b[c[i]])),a[c[i]]=b[c[i]]=-1; reverse(c,c+n);reverse(v.begin(),v.end()); for(int i=0;i<m;i++) if(a[i]!=-1) g[a[i]].push_back(b[i]), g[b[i]].push_back(a[i]); int cnt=0; for(int i=0;i<n;i++) if(!vis[i]) mp[cnt]=cnt, dfs(i,cnt++); vector<int>ans; for(int i=0;i<q;i++){ ans.push_back(cnt); if(mp[qq[v[i].first]]!=mp[qq[v[i].second]]) mp[qq[v[i].first]]=mp[qq[v[i].second]], qq[v[i].first]=qq[v[i].second], cnt--; } reverse(ans.begin(),ans.end()); for(int i=0;i<ans.size();i++) cout<<ans[i]<<' '; } 5 8 2 3 1 2 2 5 1 4 1 5 3 4 3 4 4 4 8 7 6 8 2 3 4 5 1 | | JavaEntryPointWrapper.java:10: error: cannot access Oppa | Kairat | 1000. A+B Problem | 28 Jan 2020 18:35 | 3 | JavaEntryPointWrapper.java:10: error: cannot access Oppa Oppa.main(args); ^ bad source file: .\Oppa.java file does not contain class Oppa Please remove or make sure it appears in the correct subdirectory of the sourcepath. 1 error Выходит такая ошибка, почему? У меня аналогичная ошибка. В том, что файл содержит один публичный класс, совпадающий с именем файла уверен на 100%. Причем проверил на файлах, которые отправлял ранее и удачно решенные, тоже самое. Даже решение из руководства не проходит... | | WA 22!!! HELP!!! i have already 20 attempt | Lifanov | 1299. Psylonians | 28 Jan 2020 01:41 | 3 | Please give this test! lifanov@mail.ru Oh, I has mixed too, but now it works, thank you :) | | Delete account | lareon | | 27 Jan 2020 11:24 | 1 | Please, delete my account. I don't need it anymore. | | Delete account | OnlyNoiseOnWires | | 27 Jan 2020 11:23 | 1 | Please, delete my account. I don't need it anymore. | | solved! | Shams Ivon | 1404. Easy to Hack! | 27 Jan 2020 01:15 | 1 | solved! Shams Ivon 27 Jan 2020 01:15 but I couldn't find any way to delete the post Edited by author 27.01.2020 01:24 Edited by author 27.01.2020 01:24 Edited by author 27.01.2020 01:24 | | WA #3. I'm out of tests | Timofey | 1750. Pakhom and the Gully | 26 Jan 2020 20:14 | 1 | I've passed all the tests the forum had. Can someone give me more | | For those at whom the wrong answer to the 12th test. | vin | 1021. Sacrament of the Sum | 24 Jan 2020 20:01 | 2 | Try the following 2 tests: 2 0 10000 2 20000 10000 and 2 0 10000 2 0 -10000 What answer is issued by your program? Edited by author 14.02.2013 20:37 YES, YES and look like its right? | | Solution | Roland | 1725. Sold Out! | 23 Jan 2020 16:02 | 13 | Very easy:) *first if k>n/2 make it smaller n/2: k=n-k+1 *then the answer is (n-k-2)
(......[Vasya].......[n-1][n] if [n-1] and [n] sit,then all people between [Vasya] and [n-1] will stumble at Vasya. And this will be the maximal answer ) *special case: n=2 => answer is 0 i dnt understand ur soln. why it be so?? the prog sttmnt says visitor chooses left || right end based on minimal no. of people s/he need to stumble upon. so let be test: 10 3 ur soln gives: 5 let last 2 and 1st 2 beseated. now why rest people should choose left end. prog sttmnt says it shd be right end. because only 2 need to be stumbled upon if right else 3. bt ur soln gives ac. so i thnk the prog sttmnt is all wrong || i am weak in english || the author is!!! Edited by author 29.11.2009 17:00 Roland is right example: 6 (1 Man, 2 Man, 3 empty, 4 empty, 5 empty, 6 You); answer - 3 Can you explain how do you get answer 3 for test 6,1? My solution: Veeeee Veeee1 V2eee1 V2ee31 V24e31 V24531, Where V - Vasya, e - empty place, 1,2,3... - visitors. Numbers 2 and 4 will stumble Vasyas feet, so my answer is 2. Veeeee Veeee1 Veee21 Vee321 Ve4321 V54321 The worst case. Answer - 3. Why 3? i think it have to be 4. Like Veeee1 - 0, Veee21 - 1, Vee321 - 2, Ve4321 - 3, V54321 - 4. The first case has the same problem tho Nvm, i get it. (the last sentence in first paragraph) Edited by author 23.01.2020 16:05 I think is 2 (1 man, 2 man ,3 empty, 4 man,5 man, 6 you) ,the 3man may from left Edited by author 11.09.2016 19:43 Edited by author 11.09.2016 19:43 I don`t understand why it works. Example: 10 4 ###[Vasya]###### At worst viewers with the numbers 1, 2 will come first: [1][2]#[Vasya]###### and viewer 3 stumbles over Vasya`s feets. Next come viewers with the numbers 9 and 10: [1][2][3][Vasya]####[9][10] and viewers 5, 6, 7, 8 stumble over feets. So the answer is 5, but your program (AC program!) gives 4... Edited by author 08.12.2010 14:45 Next come viewers with the numbers 9 and 10: [1][2][3][Vasya]####[9][10] and viewers 5, 6, 7, 8 stumble over feets. You should consider only those viewers who stumble Vasya's feet. Write order for this test. ###[Vasya]###### ###[Vasya]#####[1] ###[Vasya]####[2][1] ###[Vasya]###[3!][2][1] ###[Vasya]##[4!][3!][2][1] ###[Vasya]#[5!][4!][3!][2][1] ###[Vasya][6!][5!][4!][3!][2][1] Edited by author 14.12.2010 09:37 Edited by author 30.08.2011 05:38 | | Test 10 hint | Yan_Olerinskiy | 1131. Copying | 23 Jan 2020 02:30 | 1 | | | W21 - test case | android_ | 1917. Titan Ruins: Deadly Accuracy | 22 Jan 2020 23:16 | 4 | Hello My solution failed on test 21. Passed next cases: 5 5 2 2 2 3 4 0 0 5 4 4 1 4 1 2 3 2 5 4 2 2 1 1 1 5 2 5 7 4 1 4 1 2 3 1 10 18 2 2 2 2 2 2 2 2 2 2 0 0 If you have any idea please let me know. Thank you Edited by author 21.08.2015 10:49 5 8 2 2 2 1 2 5 2 Edited by author 24.08.2019 14:48 I passed all those tests, but have WA2 :D | | WA #4;can anyone help? | jim | 1925. British Scientists Save the World | 21 Jan 2020 23:10 | 2 | #include <iostream> using namespace std; int main() { int n, k; int i; int show, type; int showTotal = 0, typeTotal = 0; int neededType; cin >> n >> k; for ( i = 1; i <= n; i++) { cin >> show >> type; if (show - type == 2) showTotal = typeTotal = 0; else { showTotal += show; typeTotal += type + 2; } } neededType = k + showTotal - typeTotal - 2; if (neededType > 0 && neededType < 101) cout << neededType << endl; else { cout << "Big Bang!" << endl; } return 0; } maybe problem in this neededType > 0 || neededType < 101 UPD: result must be only bigger than zero! i have AC) Edited by author 21.01.2020 23:21 | | Why my code doesn't work?Sequence is wrong,but only'16 3'and'20 3'. Even the '22 4' and '26 4' are right. | jingyi Ma | 1100. Final Standings | 21 Jan 2020 17:21 | 2 | #include <iostream> using namespace std; int main() { int n,a[100],b[100],c,d,i,j; cin>>n; for(i=0;i<n;i++) cin>>a[i]>>b[i]; for(i=0;i<n;i++) for(j=i+1;j<n;j++) if(b[i]<b[j]) { c=b[i]; b[i]=b[j]; b[j]=c; d=a[i]; a[i]=a[j]; a[j]=d; } for(i=0;i<n;i++) cout<<a[i]<<' '<<b[i]<<'\n'; return 0; } Help me! I'm die. Sorrry,my English is poor. I will try my best to understand you. Sort declared in the task is stable. Your sort isn't stable Let we have scores: ("team1", 10), ("team2", 10), ("team3", 15). Your code when i=0, j=2 swaps team1, team3: ("team3", 15). ("team2", 10), ("team1", 10). Note: when you fix your sort you'll face the fact real bubble sort is too slow. |
|
|