Common Boardwho can tell me why it is 670 when the number is 4? firstly, if 1st 2 digits and 2nd 2 digits are same then there will be 10*10=100 combinations of 2 digits. for every number there will be 2 combination.(example:1212 and 1221) so,combinations will be 2*100=200. But there are such 10 numbers for which 2 combinations are not available.(ex: 0000 , 1111 , 5555) COMBINATIONS = 200-10 = 190. now, we have to check from highest 9+9=18 to lowest 0+0=0 that how much sets have same sum. 16<<<< (9+7),(8+8) 15<<<< (9+6),(8+7) 14<<<< (9+5),(8+6),(7+7) 13<<<< (9+4),(8+5),(7+6) 12<<<< (9+3),(8+4),(7+5),(6+6) 11<<<< (9+2),(8+3),(7+4),(6+5) 10<<<< (9+1),(8+2),(7+3),(6+4),(5+5) 9<<<< (9+0),(8+1),(7+2),(6+3),(5+4) 8<<<< (8+0),(7+1),(6+2),(5+3),(4+4) 7<<<< (7+0),(6+1),(5+2),(4+3) 6<<<< (6+0),(5+1),(4+2),(3+3) 5<<<< (5+0),(4+1),(3+2) 4<<<< (4+0),(3+1),(2+2) 3<<<< (3+0),(2+1) 2<<<< (2+0),(1+1) combinations =(2*2*2/2)+(2*2*2)+(2*2*2+2*2+2*2) +(3*2*2*2)+..................................+(2*2*2)+(2*2) =480 SO, total combinations = 190+480 =670 firstly, if 1st 2 digits and 2nd 2 digits are same then there will be 10*10=100 combinations of 2 digits. for every number there will be 2 combination.(example:1212 and 1221) so,combinations will be 2*100=200. But there are such 10 numbers for which 2 combinations are not available.(ex: 0000 , 1111 , 5555) COMBINATIONS = 200-10 = 190. now, we have to check from highest 9+9=18 to lowest 0+0=0 that how much sets have same sum. 16<<<< (9+7),(8+8) 15<<<< (9+6),(8+7) 14<<<< (9+5),(8+6),(7+7) 13<<<< (9+4),(8+5),(7+6) 12<<<< (9+3),(8+4),(7+5),(6+6) 11<<<< (9+2),(8+3),(7+4),(6+5) 10<<<< (9+1),(8+2),(7+3),(6+4),(5+5) 9<<<< (9+0),(8+1),(7+2),(6+3),(5+4) 8<<<< (8+0),(7+1),(6+2),(5+3),(4+4) 7<<<< (7+0),(6+1),(5+2),(4+3) 6<<<< (6+0),(5+1),(4+2),(3+3) 5<<<< (5+0),(4+1),(3+2) 4<<<< (4+0),(3+1),(2+2) 3<<<< (3+0),(2+1) 2<<<< (2+0),(1+1) combinations =(2*2*2/2)+(2*2*2)+(2*2*2+2*2+2*2) +(3*2*2*2)+..................................+(2*2*2)+(2*2) =480 SO, total combinations = 190+480 =670 if (nuts / 2 % 2 == 0) { daenerys_wins = !daenerys_wins; } print "IMPOSSIBLE" instead of "Impossible" Thank you so much! I've made the stupid mistake too XD in the question , author said 0 is replaced by 1. but they replace 1 by zero in the 3rd test of sample. now, i am very much confused. gimme test, please) 4 4 ** 4 4 1 2 ** 1 4 1 3 ** 2 3 2 3 ** 2 4 3 4 ** 3 4 1 **** 1 4 **** 4 maybe it can help Edited by author 22.01.2009 16:27 it's 2 1 ,my code work ok ,but wrong #5 ,where? Edited by author 20.01.2013 09:13 Try this test case: 4 5 1 2 2 3 3 4 4 2 1 3 5 1 2 3 4 5 The answer is: 1 1 2 3 4 my code do that is right ,but... Try this test: 4 4 1 2 1 2 2 3 3 4 3 1 2 3 Answer: 1 2 3 my program run all the test and they are all corret var n:integer; s:real; begin read(n); s:=(n+2)*((n+1)*n)/2; write(s); end. Use "longint" and not "integer" or "real". Edited by author 23.06.2019 11:35 #include<iostream> using namespace std; void sin (int n,int i) { if(i==n+1) return ; else { if(i==1) { cout<<"sin("<<i; sin(n,i+1); } else if(i%2==1) { cout<<"+sin("<<i; sin(n,i+1); } else { cout<<"-sin("<<i; sin(n,i+1); } cout<<")"; } } void sol( int n,int i) { if(i==n) return; if(i==1) for(int i=1;i<n;i++) cout<<'('; sin(i,1); cout<<'+'<<n-i+1<<')'; sol(n,i+1); if(i==1) { sin(n,1); cout<<"+1"; } } int main () { int n; cin>>n; sol(n,1); } Can somebody tell me how solve this problem? what is test19? maybe some wrong in test19 It can be solved using backtracking :) can anyone tell me what algo for this problem > can anyone tell me what algo for this problem I can, though my approach wasn't so easy. I used precalculations. My way is to generate all pairs (N, P), where P = 1, 2, ... - complexity of number and N - such minimal number, that has exactly P divisors. How to do this with such large inputs? Solve another problem: recover N, if you know P. I used backtrack there, but still I'm wondering whether there is a more beautiful way. First I wrote a recursive function that tries all v=2^a * 3^b * 5^c * 7^d * 11^e * ... with a>=b>=c>=... It generates +- a million possibilities and takes around 300 ms for each case. So I got TLE with 100 cases. Then I wrote code that reads all the n values and sort them. Then I call the recursive function with 10^18. I added a binary search to it that finds the smallest n greater or equal to v and update the best result for it. When the recursive function returns, I update the results for the larger values of n with the smaller results. And then I output the results in the same order as the input. All in less that 50 lines of C++. I think u can safely assume that that there is no number with power>10 so 10>=a>=b>=c>=d... and now I think u will get AC without doing anything else. Plus small small optimisation.. like breaking at a point if current no. > query(which is obvious to do so) and other such small small optimisation will do. Other thing is to check if ur current no. doesnt exceed the long long range (u can only check by using log()...) Баур, эта задача решатся "в лоб" It may be caused by conflicts... (Sorry for my poor English what is test 4. plz help me. my code is below #include<bits/stdc++.h> using namespace std; int main() { long n=1000,i,k; long long a[100000]; a[0]=0,a[1]=1; for(i=2;i<n;i=i+2){ k=i/2; a[i]=a[k],a[i+1]=a[k]+a[k+1]; } cin>>n; while(n){ cout<<*max_element(a,a+n+1)<<endl; cin>>n; } } Edited by author 22.06.2019 13:46 #include <iostream> int n,x; int a[10]; int i,t; int _max(int s1,int s2,int x) { if (x==n) return s1+s2; else { int t1,t2; if (x*2-1<=n) t1 = _max(s1,s2+s1,x*2-1); else t1 = 0; if (x*2+1<=n) t2 = _max(s1+s2,s2,x*2+1); else t2 = 0; if ((t1==t2)&&(t2==0)) return s1+s2; else return t1>t2?t1:t2; } } int main() { std::cin >> n; i = 0; while (n){ if (n==2) a[i] = 1; else if (n==1) a[i] = 1; else if (n==0) a[i] = 0; else a[i] = _max(1,1,3); std::cin >> n; i++; } for (n = 0;n<i;n++) std::cout << a[n] << "\n";
return 0; } #include <iostream> #include <algorithm> using namespace std; int main() { unsigned int i, v[100000]; v[0] = 0; v[1] = 1; for(i=2;i<100000;i++){ if(i%2==0) v[i] = v[i/2]; else v[i] = v[(i-1)/2] + v[(i-1)/2+1]; } unsigned int n; while(cin >> n){ if(n!=0) cout << *max_element(v, v+n+1) << endl; } return 0; } /* its not accepted. whats wrong with it?? WA on test 4 */ #include<bits/stdc++.h> using namespace std; int main() { long n=1000,i,k; long long a[100000]; a[0]=0,a[1]=1; for(i=2;i<n;i=i+2){ k=i/2; a[i]=a[k],a[i+1]=a[k]+a[k+1]; } cin>>n; while(n){ cout<<*max_element(a,a+n+1)<<endl; cin>>n; } } Edited by author 22.06.2019 13:37 Edited by author 22.06.2019 13:37 Edited by author 22.06.2019 13:39 Since my solution got AC, there IS a limit on k... or the tests are too weak. If the pairs are all different, there will be at most M*N different pairs.(but it doesn't say it...) Hi! I'm just amazed about this algorithm! My previous O(N^3) implementation take 0.624 and 508 KB with my best efforts to reduce runtime. When I submitted the Manacher's one, the runtime dropped down to 0.015 and 2376 KB!! Just google it. It's a very easy and efficient O(N) algorithm. That's all you need to solve this problem. No more than 30 lines of code. Do u give me your implemented solution? Can anyone please tell me in tabular form what is are the values of answers for the above values. My algorithm is almost right and it is calculating accurately as far as I know but it is always responding No on test # 2. Please help!!! I am stuck and dissappointed.... :( 1 10 -> 9 2 10 -> 90 3 10 -> 891 4 10 -> 8829 5 10 -> 87480 6 10 -> 866781 7 10 -> 8588349 8 10 -> 85096170 ... 88 10 -> 4073204239463162109734811048211023806979858806092557057802513502380259034152215057201989 how for k=3 it should be 90 input 3 5 output : 96 input 10 2 output: 89 Edited by author 14.04.2019 17:30 Edited by author 14.04.2019 17:36 What is the test 18? I really don't understand it... I wrote solution with ternary search, and I think that there is problem with accuracy of calculations. Have anybody this problem? P.S. Sorry for my bad english :) You should find number extremum of function. Spoiler: It isn't true, that there is only one. Edited by author 20.06.2019 16:21 The following code is failing the test case 3, I have used linked-list to store the data in as a stack. Below is the code for reference, can you tell me where I am going wrong. Thank you. #include<stdio.h> #include<stdlib.h> #include<stdbool.h> #include<math.h> #include<assert.h> typedef unsigned long long _ull; typedef unsigned int _uint; typedef struct _link_list { _ull _number; struct _link_list*_next; } _list; void _makenode(_list**,_ull); void _insertnode(_list**,_list*); int main(int argc,const char*argv[]) { _ull _val; _list *_head,*_temp; _head = _temp = NULL; while(true) { fscanf(stdin,"%lld",&_val); assert(_val>=0); if(feof(stdin)) break; _makenode(&_head,_val); } while(_head) { _temp = _head; fprintf(stdout,"%0.4lf\n",sqrt(_head->_number)); _head = (_head->_next); free(_temp); } return 0; } void _makenode(_list**_ptr,_ull _data) { _list*_node = malloc(sizeof(_list)); (_node->_number) = _data; (_node->_next) = NULL; _insertnode(_ptr,_node); } void _insertnode(_list**_ptr,_list*_node) { if(!(*_ptr)) (*_ptr) = _node; else { (_node->_next) = (*_ptr); (*_ptr) = _node; } } Try testcases 12 11 1 12 10 2 100 7 7 20 7 2 1000 1 26 10000 1 37 10000 13 25 100 25 8 |
|