CCF2015-12-3 Paint

The first line contains three integers mn- and Q . m and n respectively represent the width and height of the canvas, in units of characters. q represents the number of drawing operations.
  2, line through Q  +. 1 lines, each one of two forms:
  ?? 0  X . 1  Y . 1  X 2  Y 2 : Videos showing the operation of the line segment, ( X . 1Y . 1 ) and ( X 2Y 2 ) are the two ends of the segment, satisfies either X . 1  =  X 2  and Y . 1  ≠ Y 2 , or  Y . 1  =  Y 2 And  X . 1  ≠  X 2 .
  . 1 ??  X  Y  C : represents the filling operation, ( XY ) is the starting position, guaranteed not to fall on any existing segments; C  to fill characters, it is sensitive.
  It is the lower left corner of the canvas coordinates (0, 0) position, to the right x -coordinate direction to increase up to y coordinate increasing direction. This q operations are sequentially performed in the order presented data. All positions are initially canvas characters. (Decimal point).

The title itself logic is not difficult, after the write analog changes, the two small problems, one 80, one 90, but not the first time to find the problem, change many times before passing, it is worth vigilant.

The first bug, wrong answer, 80 points, then it is going wrong, the basic right in front of the sample and by 80 points to start the sample error, which must not take into account the special circumstances, this time to check the code is not found after the issue, the best re-read the title, a sentence is likely to be misunderstood. After perusing found that the phrase "If a horizontal line and a vertical line intersecting at a certain position, the intersection with the character + in place." Among the understanding before I add the + sign in - to determine when you add it up and down whether |, + there is, if any -, | no empathy.

This understanding is wrong, that Italy is in a position to say if the intersection, the + sign appears, then if | just add to the number - the upper number, but do not intersect, according to my original code number is to appear + naturally wrong.

The second bug, timeout, 90 points, to be honest this is the first time I encountered a problem in the ccf, ccf most of the time only 1s, long enough to come up with common algorithm, after this problem occurs, I have repeatedly changes even modify the initialization container and strings, ideal for effective results did not show, it made me realize what can not bring optimized initialization, then my letter alphabet function to determine it, I would define myself judge added a function reference, but also invalid, the system comes with a function to determine the letter will not be a good point effect? Facts have proved futile. So the question should appear on the optimized algorithm. Draw the line itself is simple logic, the problem is not here, in the process of filling in with the team, I used to write their own vector team, are placed after each iteration j ++, and to meet the conditions the tail, at first glance no great hinder, so how can check it out, try to read out the code to see the results of their logic, in which over Cheng Zhongfu to mind, I think the situation if the queue is the first line of the second row AA AB, from B start filling the upper left corner of the a judge turned many times into the team, is a waste of time, useless consumption exponentially judge, so here also optimizes the time, the priority determination V [y] [x] whether c, if so, j ++ directly continue, then visited here before, into the next cycle to the next. If not, only to change it to c, and into the team qualified to judge. At this point, the code is submitted after 100 minutes, longer time-out. Another interesting detail is that my references were used to determine the function of letters, and the letters of standard library functions, I own is actually 900ms, the standard library 984ms, then this extra 84ms where the problem is it ? Preliminary understood as isalpha (int c), with an assignment, useless references. Perhaps it does not need to refer to the beginning of design assignment for a character?

Go defined as follows:

 template<typename _CharT>
    inline bool
    isalpha(_CharT __c, const locale& __loc)
    { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); }

I'm afraid I'm going to explore in depth after the template part to another conclusion.

Overall code is as follows:

#include <iostream>
#include <vector>
#include <string>
using namespace std;
bool isalp(char &c)
{
    if(c-'a'>=0 && c-'a'<26)
    return true;
    if(c-'A'>=0 && c-'A'<26)
    return true;
    return to false ; 
} 
int main () 
{ 
//     first line contains three integers m, n and q. m and n represent the width and height of the canvas, in units of characters. q represents the number of drawing operations.
//   2nd row to row q + 1, each row is one of two forms:
 //   0 X1 X2 Y1 Y2:? Videos showing the operation of the line, (x1, y1) and (x2, y2) respectively, both ends of the line segment, and x1 = x2 satisfies either y1 ≠ y2, and y1 = y2 or x1 ≠ x2.
//   ? XYC 1: representing fill operations, (x, y) is the starting position, guaranteed not to fall on any existing line; c filled character is uppercase and lowercase letters.
//   canvas coordinates of the lower left corner is (0, 0) position, to the right of the direction of increasing x-coordinate, y-coordinate is increased upward direction. This q operations sequentially performed in the order presented data. All positions are initially canvas characters. (Decimal point). 
    int m, n-, Q; 
    CIN >> >> m >> n- Q;
     String T (m, ' . ' ); 
    Vector < String > V (n-, T);
    for(int i=0;i<q;i++)
    {
        int mod;
        cin>>mod;
        if(mod==0)
        {

            int x1,y1,x2,y2;
            cin>>x1>>y1>>x2>>y2;
            if(y1==y2)
            {
            int y=y1;
            int minx=min(x1,x2);
            int maxx=max(x1,x2);
            for(int x=minx;x<=maxx;x++)
            {
                if(v[y][x]=='|')
                v[y][x]='+';
                else if(v[y][x]!='+')
                v[y][x]='-';
            }
            }
            else if(x1==x2)
            {
                int x=x1;
                int miny=min(y1,y2);
                int maxy=max(y1,y2);
                for(intY = minY; Y <= Maxy; Y ++ ) 
                { 
                    IF (V [Y] [X] == ' - ' ) 
                    V [Y] [X] = ' + ' ;
                     the else  IF (V [Y] [X]! = ' + ' ) 
                    V [Y] [X] = ' | ' ; 
                } 
            } 
        } 
        the else {
             // fill function, whether to use the queue 
             int X3, Y3;
              char C; 
             CIN >> >> X3  Y3;
             CIN>> C;
              // Create a queue fill-up C 
             Vector <Vector < int >> Q; 
             Vector < int > TEMP; 
             temp.push_back (X3); 
             temp.push_back (Y3); 
             q.push_back (TEMP); 
             temp.clear (); 
             int J = 0 ;
              the while (! J = q.size ()) 
             { 
                 int X = Q [J] [ 0 ];
                  int Y = Q [J] [ . 1 ];
                  IF (V [Y ] [X]! =  C)
                 V [Y] [X]=c;
                 else{
                     j++;
                     continue;
                 }
                 if(y+1<n && v[y+1][x]!=c && (v[y+1][x]=='.' ||  isalpha(v[y+1][x])))
                 {
                     temp.push_back(x);
                     temp.push_back(y+1);
                     q.push_back(temp);
                     temp.clear();
                 }
                 if(y-1>=0 && v[y-1][x]!=c && (v[y-1][x]=='.' || isalpha(v[y-1][x])))
                 {
                     temp.push_back(x);
                     temp.push_back(y-1);
                     q.push_back(temp);
                     temp.clear();
                 }
                if(x-1>=0 && v[y][x-1]!=c && (v[y][x-1]=='.' || isalpha(v[y][x-1])))
                 {
                     temp.push_back(x-1);
                     temp.push_back(y);
                     q.push_back(temp);
                     temp.clear();
                 }
                 if(x+1<m && v[y][x+1]!=c && (v[y][x+1]=='.' || isalpha(v[y][x+1])))
                 {
                     temp.push_back(x+1);
                     temp.push_back(y);
                     q.push_back(temp);
                     temp.clear();
                 }
                 j++;
             }
            q.clear();
        }
    }
//    for(int i=0;i<n;i++)
//    {
//        v2.push_back(v[i]);
//    }
    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<v[i]<<endl;
    }
    
    return 0;
}

 

  

Guess you like

Origin www.cnblogs.com/awangkuo/p/12640963.html