pnsrp's blog

By pnsrp, 9 years ago, In English

Hi, everyone. In the contest, the judge said i got wrong answer in test case 6. I waited for the contest to be over and I checked the test case, then, i tried to run it with that test case i failed, i got the correct answer in my computer. Why is my solution is wrong for the judge? My code is here. http://pastebin.com/GJWP7a5t

Read more »

 
 
 
 
  • Vote: I like it
  • -5
  • Vote: I do not like it

By pnsrp, 9 years ago, In English

hi anybody can help me, in the second iteration, i'm getting this value, -2.77556e-17 instead of zero, sorry for disturbing you guys, i'm really lost. Pls help me. My code is like this. I'm coding an neutron which learns and  gate.
#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    int i, j;
    double dataIn[4][3];
    freopen( "input.txt", "r", stdin);
    for( i=0; i<4; i++ ){
        for( j=0; j<3; j++ ){
            cin >> dataIn[i][j];
        }
    }
    double weight[2] = { 0.3, -0.1 };
    double error[4];
    double threshold = 0.2;
    int output;
    double alpha = 0.1;
    int epoch = 0;
    int t = 2; //debugging: trying running just two iterations
    while(t--){
        for( i=0; i<4; i++ ){
            double sum = (dataIn[i][0] * weight[0]) + (dataIn[i][1] * weight[1]) - threshold;
            cout << dataIn[i][0] * weight[0] << " " << dataIn[i][1] * weight[1] << " " << threshold << endl;
            cout << sum << endl;
            sum >= 0 ? output = 1 : output = 0;
            cout << output << endl;
            if( output != dataIn[i][2] ){
                error[i] = dataIn[i][2] - output;
                weight[0] = weight[0] + (alpha*error[i]*dataIn[i][0]);
                weight[1] = weight[1] + (alpha*error[i]*dataIn[i][1]);
            }
            else error[i] = 0;
        //    cout << weight[0] << " " << weight[1] << endl;

        }
        cout << endl;
        epoch++;
        if( error[0] == 0 && error[1] == 0 && error[2] == 0 && error[3] == 0 ) break;
        else continue;
    }
    cout << epoch << endl;
    return 0;
}

Read more »

 
 
 
 
  • Vote: I like it
  • +8
  • Vote: I do not like it

By pnsrp, 10 years ago, In English
Anybody can help me, I got runtime error for the this problem, 1B - spread sheet, it works fine in my computer.

#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<stack>

using namespace std;

char convert(int cno){
     return cno - 1 + 'A';
     }
    
int convert2n (char ch){
    return ch - 'A' + 1;
    }

int main()
{
    int n, index, cno, total=0, multiplicand=1;
    string input, row, col;
    stack<char>ch_stack;
    cin >> n;
    while(n--){
               cin >> input;
               if(input[0]=='R' && (input[1]>=48 && input[1]<=57)){
                                for(int i=2; i<input.size(); i++){
                                        if(input[i]=='C') {index=i; break;}
                                        }
                                row = input.substr(1,index-1);
                                col = input.substr(index+1);
                                cno = atoi(col.c_str());
                                if(cno<=26){
                                            cout << convert(cno) << row << endl;
                                            }
                                else {
                                     while(cno>26){
                                                   ch_stack.push(convert(cno%26));
                                                   cno /= 26;
                                                   }
                                     ch_stack.push(convert(cno));
                                     while (!ch_stack.empty()){
                                           cout << ch_stack.top();
                                           ch_stack.pop();
                                           }
                                     cout << row << endl;
                                     }
                                }
               else {
                    for(int i=1; i<input.size(); i++){
                            if(input[i]>=48 && input[i]<=57) {index=i; break;}
                            }
                    row = input.substr(index);
                    col = input.substr(0, index);
                    for(int i=col.size()-1; i>=0; i--){
                            char ch = col[i];
                            total += convert2n(ch)*multiplicand;
                            multiplicand *= 26;
                            }
                    cout << "R" << row << "C" << total << endl;
                    multiplicand = 1;
                    total = 0;
                    }
             
               }
    //system("pause");
    return 0;
}
I did it in a stupid way, but i wanted to know why i got that runtime error, Please help me.
Thank you.

Read more »

 
 
 
 
  • Vote: I like it
  • -26
  • Vote: I do not like it