|
|
вернуться в форумHelp me please! Why Compilation Error? #include <iostream> #include <fstream> #include <string> #include <vector> #include <math.h> using namespace std; class Summator { private: vector<bool> l; vector<int> b; int size; int b_size,b_count; public: void init (int _size) { size=_size; b_size=(int)pow(size,0.5); b_count=size/b_size+1; l.resize(size); b.resize(b_count); } void reset() { for(int i=0;i<size;i++) l[i]=false; for(int i=0;i<b_count;i++) b[i]=0; } int findsum(int a) { int p=a/b_size; if (a%b_size!=0) p++; int res=0; for(int i=p+1;i<b_count;i++) res+=b[i]; a-=(--p)*b_size; for(int i=a;i<=b_size;i++) if ((p*b_size+i<size)&&(l[p*b_size+i])) res++; return res; } void add(int pos) { l[pos]=true; int p=pos/b_size; if (pos%b_size!=0) p++; b[p]++; } }; int main () { #ifndef ONLINE_JUDGE ifstream cin("input.txt"); #endif int n,k,res,max=0; cin>>n>>k; Summator s; s.init(n+1); for(int t=0;t<k;t++){ int rs=0,p; s.reset(); for(int i=0;i<n;i++) { cin>>p; rs+=s.findsum(p+1); s.add(p); } if (rs>max) { max=rs; res=t+1; } } cout<<res<<endl; return 0; } Edited by author 16.04.2007 21:18 Re: Help me please! Why Compilation Error? use b_size=(int)pow((double)size,0.5); also ifdef - not ifndef Kirill Edited by author 16.04.2007 21:33 |
|
|