i have written algorithm that uses log2() which is in c++(<cmath> library) and when i used it copmpilation error occured "error C3861: 'log2': identifier not found" when i compile it in devc++ it works perfectly.. can everyone helm me? :( Timus use the compiler visual c++ compiler not gcc. hint: log2(n) = log(n)/log(2) (but this sum at the complexity) Edited by author 21.01.2011 22:32 Edited by author 21.01.2011 22:32 Timus use the compiler visual c++ compiler not gcc. hint: log2(n) = log(n)/log(2), (but this sum at the complexity) I have submitted solution and have got AC (ID 3108352) but it doesn't pass some tests. For example, for input 146 0 its output is 21, not 23. And there are a lot of other cases with wrong output. I think, something should be changed in test data. New tests were added. 208 authors lost AC after rejudge. Wow, that was your gift for Christmas?? I'm kidding of course; it takes no more than 5-6 mins to write a new correct solution:) Happy holidays! 5 - оутпут 3 10 - оутпут 4 0 (return) Got to do only one thing find the maximum in this array If the array size is 5 then maximum = 3 and if 10 then 4 is max so, I solved the problem in the givven way and in given way the max of 5(sized array) isn't 3 here is the input and output cin>> 5 0 1 1 2 1 max = 2 _____________________________ cin >> 10 0 1 1 2 1 3 2 3 1 4 max = 4 _______________________________________ input>>6 0 1 1 2 1 3 max = 3 ______________________________________ please help the Solution of Problem is Actually thiS, In c++ But dOesn't work maybe you can notice something?? for(int i = 0; i < a; i++){ if(2*i < a){ arr[2*i] = arr[i]; } if(2*i+1 < a){ arr[2*i+1] = arr[i] + arr[i+1]; } } i think it will work out fine. But just got WA1. Can you help me ? thx! #include <cstdlib> #include <iostream> using namespace std;
int shu(int); int main(int argc, char *argv[]) { int a[10],b=0,max=0,d=0; while (cin>>a[b]) {if (a[b]==0) break; b++;} while (1) {if (a[d]==0) break; while (a[d]>=0) {if (shu(a[d])>max) max=shu(a[d]); a[d]--;} cout<<max<<endl; d++;}
system("PAUSE"); return EXIT_SUCCESS; }
int shu(int n) {int c; if (n==0) c=0; else if (n==1) c=1; else if (n%2==0) c=shu(n/2); else c=shu((n-1)/2)+shu((n-1)/2+1);} I have the same trouble whit you,WA1!!! But I test it myself whit my computer but find nothing wrong! #include<iostream> using namespace std; void K(int); void main() { int b[10],j=0,k=0; for(;j<10;j++) { cin>>b[j]; if(b[j]==0) break; } for(;k<j;k++) K(b[k]); }
void K(int n) { if(n!=1) { n++; int *a = new int [n]; a[0]=0; a[1]=1; int i=2; for(;i<n;i++) { if(i%2==0){a[i]=a[i/2];} else {a[i]=a[(i-1)/2]+a[(i-1)/2+1];} } if(n%2==0){cout<<a[n-1];} else {cout<<a[n-2];} cout<<endl; } else { cout<<0<<endl; } } my code: #include "stdio.h" #include "iostream.h" #include "math.h" int main() { long a[100001],i; a[0]=0; a[1]=1; for(i=2;i<100001;i++) { if(i%2==0) { a[i]=a[i/2]; } else { a[i]=a[i/2]+a[i/2+1]; } } int t[10]; i=0; while(true) { cin>>t[i]; if(t[i]==0) break; i++; } i=0; long max; while(t[i]!=0) { for(int j=0;j<t[i]+1;j++) { if(a[j]>max) { max=a[j]; } } cout<<max<<"\n"; max=-1; i++; } return 0; } What for N=10 answer 4??? a1 = 1 a2 = 1 a3 = 2 a4 = 1 a5 = 3 a6 = 2 a7 = 3 a8 = 1 a9 = 4 a10 = 3 Maximal numbler among a1,...,a10 is a9, which is equal to 4. I understand!Thank you!=) What will be the output for N=10? For N=10 output is 4. For N=100000 output is 2584. For N=77777 output is 2207. For N=12345 output is 610. For N=5000 output is 322. For N=99999 output is 2584. For N=100 output is 21. For N=50 output is 13. #include <stdio.h> 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() { scanf("%d",&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); scanf("%d",&n); i++; } for (n = 0;n<i;n++) printf("%d\n",a[n]); return 0; } Worked without homesave for me. Just bruteforce is enough #include<iostream.h> void main() { int a[10000],max[10]; int i,j,num,n; for(i=0;i<10;i++) { cin>>n; if(n==0) break; max[i]=0; for(j=0;j<=n;j++) { if(j==0) a[j]=0; else if(j==1) a[j]=1; else if(j%2==0) a[j]=a[j/2]; else a[j]=a[(j-1)/2]+a[(j-1)/2+1]; if(a[j]>max[i]) max[i]=a[j]; } } num=i; for(i=0;i<num;i++) cout<<max[i]<<endl; } N goes up to 100000, not merely 10000. #include <stdio.h> #include <stdlib.h> int a[100]; int in[10]; int i,j,k; int N; int main() { int res1; int res2; i=0; while (scanf("%d",&in[i])) { if (in[i]==0) break; i++; } //cout<<"dshfhfhdf"<<endl; j=0; while(in[j]!=0) { N=in[j]; //if (N==0) return 0; a[0]=0; a[1]=1; for (i=2;i<=N/2+1;i++) { if (i%2==0) a[i]=a[i/2]; else a[i]=a[i/2]+a[i/2+1];
} i-=2; if (N%2==0) printf("%d\n",(a[i-1]+a[i]));
else printf("%d\n",(a[i]+a[i+1])); j++; } return 0; } Anupam Ghosh,Bengal Engg and Science University,Shibpur,India i got AC [1] // Problem 1079. Maximum 26 Feb 2008 14:43 just use recursion along with array. And now try to solve 1396. Maximum. Version 2 Here is my AC program: var a: array[0..100000]of integer; v: array[1..10]of integer; n,i,k,j: longint; begin a[0]:=0; a[1]:=1; for i:=2 to 100000 do begin if i mod 2=0 then a[i]:=a[i shr 1] else a[i]:=a[i shr 1]+a[i shr 1+1]; end; k:=0; readln(n); while n>0 do begin inc(k); j:=1; for i:=2 to n do if a[i]>j then j:=a[i]; v[k]:=j; readln(n); end; for i:=1 to k do writeln(v[i]); end. Thanx!! Thank you.Because I used your program.Thank. thanks alot, because i find my mistake with your code PLEASE GIVE ME SOME TEXTS. i KNOW THAT MY PROGRAM WORKS CORRECTLY BUT IT GIVES WRONG ANSWER mende olum, mende. xiyarsan! I am a beginner in C++, but I made it in Pascal for AC. Please help me to find the mistake! #include<iostream.h> int huge c[100001]; void main() {long a[15],n=0,m=0,mm,i,j; do{n++;cin>>a[n];if(a[n]>m)m=a[n];}while(a[n]); n--; c[0]=0; c[1]=1; for(i=2;i<=m;i++){if(i%2==0)c[i]=c[i/2]; else c[i]=c[i/2]+c[i/2+1];} for(i=1;i<=n;i++){mm=0;for(j=1;j<=a[i];j++)if(mm<c[j])mm=c[j];cout<<mm<<endl;} } Just erase "huge" in follow line: int huge c[100001]; There is no such type on C++. Who can better? My solution has O(logn*logn). Fairly it wasn't my solution. I read about one property of that function. And I know that exist more efficient solution. 764867 17:11:45 21 фев 2005 TECTOBOP 1079 Pascal Accepted 0.015 959 КБ 764865 17:10:33 21 фев 2005 TECTOBOP 1079 Pascal Accepted 959 КБ I think you have lowered your complexity ! You can check your algorithm ! Is it exactly O(LogN*LogN) ? See: 866045 Hard (DHSP) 1079 Pascal Accepted 0.001 505 KB Edited by author 22.06.2005 21:33 Edited by author 22.06.2005 21:33 If your solution is O(logN*logN) than why it works slower than O(N)? Are you sure that accuracy of time measuring is higher than centisecond? try to solve 1396 it is the same problem, but 0 < N < 10^18 I jave O(log n) solution! 0.015s 331k! Assume g(n,i,j)=i*f(n)+j*f(n+1). Then g(2n,i,j)=g(n,i+j,j) g(2n+1,i,j)=g(n,i,i+j) We must find f(n)=g(n,1,0), so... the same program written in c++ is right ,but in c is Compilation error. why?? c++: #include<iostream> using namespace std; int a[100000]; int main(){ a[0]=0; a[1]=1; for(int i=2;i<100000;i++) if(i%2) a[i]=a[i/2]+a[i/2+1]; else a[i]=a[i/2]; int n; while(cin>>n&&n){ int max=0; for(int j=0;j<=n;j++) if(a[j]>max) max=a[j]; cout<<max<<endl; } return 0; } c: #include<stdio.h> int main(){ int a[100000]; a[0]=0; a[1]=1; for(long i=2;i<100000;i++) if(i%2) a[i]=a[i/2]+a[i/2+1]; else a[i]=a[i/2]; int n; while(scanf("%d",&n)&&n){ int max=0; for(int j=0;j<=n;j++) if(a[j]>max) max=a[j]; printf("%d\n",max); } return 0; } thank you! Edited by author 26.04.2007 20:24 Here is my program, you can test it and see. =( Code (java): [code deleted] Edited by moderator 27.03.2007 09:45 |
|