10334 - Ray Through Glasses

All about problems in Volume 103. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

dispanser
New poster
Posts: 18
Joined: Wed May 01, 2002 4:12 pm
Location: Jena/Germany
Contact:

Post by dispanser » Tue Jul 22, 2003 6:06 pm

Accepted

:lol:

ankur_vjy
New poster
Posts: 2
Joined: Thu Jan 24, 2008 8:51 pm

Re: 10334 - Ray Through Glasses

Post by ankur_vjy » Sat May 31, 2008 6:22 pm

i cross checked some of the input cases and they seem to work.
I m implementing a Big Integer and producing fibonacci numbers
But i keep getting WA . please help

Code: Select all

#define pb push_back
#define vi vector<int>

void init (vi &num, string s) {
 if(s.size()%3==1)
    s = "00" + s;
  else if (s.size()%3 == 2)
    s = "0" + s;		
  for(int i=0;i<s.size();i+=3) {
    num.pb((s[i]-'0')*100 + (s[i+1]-'0')*10 + (s[i+2]-'0'));	
  }
  reverse(num.begin(),num.end());
  
}

void add(vi num1,vi num2, vi &sum) {
  int carry=0;
  for(int i=0;i<num1.size() || i<num2.size();i++) {
    if(i<num1.size()&&i<num2.size())
      sum.pb(num1[i]+num2[i]+carry);
    else if(i<num1.size())
      sum.pb(num1[i]+carry);
    else
      sum.pb(num2[i]+carry);
    carry=0;
    if(sum.back()>=1000) {
      sum.back()-=1000;
      carry=1;
    }
  }
  if(carry)
    sum.pb(1);
 
}

void display(vi num) {
  for(int i=num.size()-1;i>=0;i--)
    cout<<num[i];
}

int main() {
  int n;
  while(scanf("%d",&n)!=EOF) {
    vi f1,f2;
    init(f1,"1");
    init(f2,"1");
    for(int i=0;i<n;i++){
      vi temp;
      add(f1,f2,temp);
      f1=f2;
      f2=temp;
    }
    display(f2);
    cout<<"\n";
  }
  return 0;
}

ExUCI
New poster
Posts: 14
Joined: Sat Aug 12, 2006 3:31 am
Location: USA

Re: 10334 - Ray Through Glasses

Post by ExUCI » Mon Jan 05, 2009 7:55 am

The output for the input 1000 has 210 digits and yours only has 199, it's just missing some zeroes :D
Remove your code after AC :)

xrenon
New poster
Posts: 10
Joined: Tue Sep 23, 2014 4:11 am

Re: 10334 - Ray Through Glasses

Post by xrenon » Fri Nov 07, 2014 11:59 am

Thank You
Deleted
Last edited by xrenon on Fri Nov 07, 2014 2:01 pm, edited 1 time in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10334 - Ray Through Glasses

Post by lighted » Fri Nov 07, 2014 1:42 pm

Why runtime error ???
Why don't you put your code into code blocks?

Change reading to

Code: Select all

StringBuilder sb = new StringBuilder();
		
while ( (s = br.readLine() ) != null ) {

	StringBuilder append = sb.append(bi[Integer.parseInt(s)]).append("\n");
}
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Post Reply

Return to “Volume 103 (10300-10399)”