Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with test cases. [Pascal]
Index -> General Programming
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
HeavenAgain




PostPosted: Sat Dec 08, 2007 10:38 pm   Post subject: RE:Help with test cases. [Pascal]

UHHH no ideaaaaa what the heck is 216 (thank god java have this short note on the error for easy debug), but just a tip when doing that question, the 2 number x and y which are being inputed, x and be bigger than y and y can be bigger than x, that should not affect your answer tho
Sponsor
Sponsor
Sponsor
sponsor
CodeMonkey2000




PostPosted: Sat Dec 08, 2007 10:46 pm   Post subject: RE:Help with test cases. [Pascal]

Apparently there are two cases that give you an infinite loop, they are 113383 and 134379.
HeavenAgain




PostPosted: Sat Dec 08, 2007 10:48 pm   Post subject: RE:Help with test cases. [Pascal]

hey codemonkey i just found this :p check it out
http://acm.uva.es/problemset/pascalgpc.html

and no they dont give you infinte loop, if they do, you'll be rich! it is been proven that any sets of number under 1 million are possibile
and result for 113383 and 134379 should give you 349

Ps. if you use brute force for this question (3n+1), IT may require some bitwise operator, just to speed up the calculation, or else you might exceed the time limit, altho pascal and c/c++ are quite fast at these, so it shouldnt be a big problem
CodeMonkey2000




PostPosted: Sat Dec 15, 2007 2:24 pm   Post subject: Re: Help with test cases. [Pascal]

I finally got AC for the 3n+1 problem. I just had to rewrite the code in c++ Razz But the minesweeper problem is still giving me WA. I really don't know what's wrong. Did you get AC?
Cplusplus:
#include<iostream>

bool inBounds(long x,long y, long highX,long highY)
{
        return ((x>0)&&(x<=highX)&&(y>0)&&(y<=highY));
}

int main()
{
        long n,m,mines,field;
        char input[1001][101],tmp;
        field=1;
        while ((std::cin>>n>>m)&&((n!=0)||(m!=0)))
        {
                for (int x=1; x<=n; x++)
                        for (int y=1; y<=m; y++)
                        {
                                std::cin>>tmp;
                                while(tmp=='\n')
                                        std::cin>>tmp;
                                input[x][y]=tmp;
                        }
                std::cout<<std::endl<<std::endl;
                std::cout<<"Field #"<<field<<":"<<std::endl;
                field++;
                for (int x=1; x<=n; x++)
                {
                        for (int y=1; y<=m; y++)
                        {
                                if (input[x][y]=='.')
                                {
                                        mines=0;
                                        if ((inBounds(x+1,y,n,m))&&(input[x+1][y]=='*'))
                                                mines++;
                                        if ((inBounds(x-1,y,n,m))&&(input[x-1][y]=='*'))
                                                mines++;
                                        if ((inBounds(x,y+1,n,m))&&(input[x][y+1]=='*'))
                                                mines++;
                                        if ((inBounds(x,y-1,n,m))&&(input[x][y-1]=='*'))
                                                mines++;
                                        if ((inBounds(x+1,y+1,n,m))&&(input[x+1][y+1]=='*'))
                                                mines++;
                                        if ((inBounds(x+1,y-1,n,m))&&(input[x+1][y-1]=='*'))
                                                mines++;
                                        if ((inBounds(x-1,y-1,n,m))&&(input[x-1][y-1]=='*'))
                                                mines++;
                                        if ((inBounds(x-1,y+1,n,m))&&(input[x-1][y+1]=='*'))
                                                mines++;
                                       
                                        std::cout<<mines;
                                }
                                else
                                        std::cout<<"*";
                        }
                        std::cout<<std::endl;
                }                     
        }
}



EDIT: never mind, it works now. Just a formating problem Very Happy
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 19 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: