|
|
It's kinda tedious since you need most operations too Please write Input and Output Test3 Edited by author 09.04.2019 23:05 What's answers for this tests? 1) 3 0 1 0 2) 4 0 1 2 0 3) 4 2 0 0 0 My AC program gives 1) 15 2) 204 3) 2 i have problems with test №3 Please help try test: 2000 then 1999 of "0" and 1 of "1" Or just test: 3 0 0 0 (the statement says there is at least 1 caught fish, but most solutions print 0) What is wrong with my code ? Am i using a wrong algo ? /*1818.cpp*/ #include<iostream> #include<string> #include<string.h> #define MAXN 2000 #define MAXNCHAR 4 using namespace std; string sum(const string &a,const string &b) { string res=""; unsigned carry=0, nA=a.size(), nB=b.size(); while(nA>0 && nB>0) { res.insert(res.begin(),(a[nA-1]-'0'+b[nB-1]-'0'+carry)%10+'0'); carry=(a[nA-1]-'0'+b[nB-1]-'0'+carry)/10; nA--; nB--; } while(nA>0) { res.insert(res.begin(),(a[nA-1]-'0'+carry)%10+'0'); carry=(a[nA-1]-'0'+carry)/10; nA--; } while(nB>0) { res.insert(res.begin(),(b[nB-1]-'0'+carry)%10+'0'); carry=(b[nB-1]-'0'+carry)/10; nB--; } if(carry>0) res.insert(res.begin(),carry+'0'); return res; } string mult1(const string &a,char b) { string res=""; unsigned i,nA=a.size(), carry=0; if(b=='0') { res="0"; return res; } for(i=0;i<nA;i++) { res.insert(res.begin(),((a[nA-1-i]-'0')*(b-'0')+carry)%10+'0'); carry=((a[nA-1-i]-'0')*(b-'0')+carry)/10; } while(carry>0) { res.insert(res.begin(),carry%10+'0'); carry/=10; } return res; } string mult(const string &a,const string &b) { unsigned i,j,nB=b.size(); string tmp,res="0"; for(i=0;i<nB;i++) { tmp=mult1(a,b[nB-1-i]); for(j=0;j<i;j++) tmp.insert(tmp.end(),'0'); res=sum(res,tmp); } return res; } string x,arr[MAXN]; char l=1; unsigned n; void read() { unsigned i; char nChar[MAXNCHAR+1]; cin>>n; for(i=0;i<n;i++) { cin>>arr[i]; l=l && arr[i]=="0"; } sprintf(nChar,"%u",n); x.assign(nChar); } string solve() { string res; unsigned i; if(l==0) { res=arr[n-1]; for(i=1;i<n;i++) { res=mult(res,x); res=sum(res,arr[n-1-i]); } return res; } res=x; for(i=1;i<n;i++) res=mult(res,x); return res; } void write() { cout<<solve()<<endl; } int main() { read(); write(); return 0; } Edited by author 08.02.2011 01:51 Edited by author 08.02.2011 01:52 Edited by author 10.02.2011 16:32 Is output for that case : 2000 1999 of '0' and one '1' http://pastebin.com/WfrYZTAg ? Edited by author 01.05.2011 21:02 Edited by author 01.05.2011 21:02the output for 3 0 0 0 is 9 or 0 ? I've got WA on #3 and for 3 0 0 1 is 9 too? I haven't solved it yet. It's WA3 too. But I think the correct answer for 3 0 0 0 is 27. and for 3 0 0 1 is 9. Edited by author 05.05.2011 04:30 Edited by author 05.05.2011 04:30 What the output for 2000 1999 of '0' and one '1' Can u give the answer of this test? I got WA #11 and it turned out that I didn't consider the case when all the fishermen don't throw any fish. Input: 4 0 0 0 0 Output: 256 what is correct answer in case n=3;a1=0;a2=0;a3=0; is it 27 or 0? Известно, что рыбаки поймали хотя бы одну рыбу. Известно, что рыбаки поймали хотя бы одну рыбу. It is known that they caught at least one fish. try it out: N=1000 999 "0"and a single "1" |
|
|