Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

终于AC了~~不过代码写得很长

Posted by frankLEE at 2015-04-19 14:03:34 on Problem 1021
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

struct node
{
    int x;
    int y;
};

vector<int> v_left;
vector<int> v_right;  //存储左右两边点向四个方向能走的距离
bool graph_left[105][105];
bool graph_right[105][105];

int main()
{
    int t = 0;
    cin >> t;
    while (t--)
    {
        int width = 0, height = 0, n = 0;
        cin >> width >> height >> n;
        node *point_left = new node[n];  //存储点的个数
        node *point_right = new node[n];
        memset(graph_left, 0, sizeof(graph_left));
        memset(graph_right,0, sizeof(graph_right));

        for (int i=0; i<n; i++)
        {
            cin >> point_left[i].x >> point_left[i].y;
            graph_left[point_left[i].x][point_left[i].y] = true;
        }

        for (int i=0; i<n; i++)
        {
            cin >> point_right[i].x >> point_right[i].y;
            graph_right[point_right[i].x][point_right[i].y] = true;
        }
        
        for (int i=0; i<n; i++)
        {
            int count = 0;
            for (int j=point_left[i].x-1; j>=0; j--)
            {
                if (graph_left[j][point_left[i].y])  count++;
                else  break;
            }
            for (int j=point_left[i].x+1; j<width; j++)
            {
                if (graph_left[j][point_left[i].y])  count++;
                else  break;
            }
            for (int j=point_left[i].y+1; j<height; j++)
            {
                if (graph_left[point_left[i].x][j])  count++;
                else  break;
            }
            for (int j=point_left[i].y-1; j>=0; j--)
            {
                if (graph_left[point_left[i].x][j])  count++;
                else  break;
            }
            v_left.push_back(count);
        }
        
        for (int i=0; i<n; i++)
        {
            int count = 0;
            for (int j=point_right[i].x-1; j>=0; j--)
            {
                if (graph_right[j][point_right[i].y])  count++;
                else  break;
            }
            for (int j=point_right[i].x+1; j<width; j++)
            {
                if (graph_right[j][point_right[i].y])  count++;
                else  break;
            }
            for (int j=point_right[i].y+1; j<height; j++)
            {
                if (graph_right[point_right[i].x][j])  count++;
                else  break;
            }
            for (int j=point_right[i].y-1; j>=0; j--)
            {
                if (graph_right[point_right[i].x][j])  count++;
                else  break;
            }
            v_right.push_back(count);
        }

        sort(v_left.begin(), v_left.end());
        sort(v_right.begin(), v_right.end());

        if (v_left == v_right)  cout << "YES" << endl;
        else cout << "NO" << endl;

        v_left.clear();
        v_right.clear();
        delete []point_left;
        delete []point_right;
   }

    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator