there are number 1,2,3....2013 on a blackboard,erase any two number a,b of them and input 2(a+b) in it.
assume the last number is c, find the biggest value of c%1000;
at first, i thought if 2013+2012, 2011+2(2012+2013)...so on is the biggest operation.
my code :
#include <cstdlib>
#include <iostream>
#include <stack>
usingnamespace std;
int main(int argc, char **argv[])
{
stack<int>istack;
int i,a,b,r;
for(i=1;i<=2013;i++)//default stack;
{
istack.push(i);
}
if(istack.size()>1)
{ a=istack.top();
istack.pop();
b=istack.top();
istack.pop();
istack.push(2*(a+b)); //execute the process,erase two element and then push one element in to the stack;
}
r=istack.top()%1000;
cout<<istack.top()<<endl;//the last one is on the top;
cout<<"the mode value is equal to "<<r<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
//output is 50;
but i think this is wrong. 50 is too small.
what kind of code should I build?
The biggest possible value of c%1000 is 999, but since c is an even number, the correct answer should be 998.
I don't understand the question: "there are number 1,2,3....2013 on a blackboard,erase any two number a,b of them and input 2(a+b) in it.", is that just a single operation, or is that to be repeated?
My interpretation is it is just a single operation - in which case nested for-loops for a and b should do.