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

WA?对所有的sample都通过了;对单行的也试过了。难道是输入输出格式有问题?

Posted by yndx2001 at 2007-07-10 21:50:13 on Problem 1009
#include <iostream>
#include <fstream>
#include <list>
#include <utility>
#include <cmath>
using namespace std;


int EDGE_POS[8][2] = {{-1, -1}, {0, -1}, {1, -1},
						{-1, 0}, {1, 0},
						{-1, 1}, {0, 1}, {1, 1}};
struct Picture
{
	int width;
	int height;
	int nPixes;
	list<pair<int, int> > pixes;
	list<pair<int, int> > edges;
};
typedef list<pair<int, int> >::iterator Itr;

bool getData(istream& in, Picture & pic)
{
	char wait= 111;
	pic.nPixes = 0;
	pic.width = 0;
	pic.height = 0;
	pic.edges.clear();
	pic.pixes.clear();


	int pix, pixNum;
	in >> pic.width;
	if (!pic.width)
		return false;
	for (;;)
	{
		in >> pix >> pixNum;
		if (pix == 0 && pixNum ==0)
			break;
		pic.pixes.push_back(pair<int, int> (pix, pixNum));
		pic.nPixes += pixNum;
	}
	pic.height = pic.nPixes / pic.width;
	return true;
}

int invalidatePos(int pos, int xoffset, int yoffset, int width, int height)
{
	int x = pos % width;
	int y = pos / width;
	x += xoffset;
	y += yoffset;
	if ( 0 <= x && x < width && 0 <= y && y < height)
		return y * width + x;
	else
		return -1;
}

void edgeDetect(Picture & pic)
{
	int blockCounter = 0;
	Itr itAround;
	Itr it = pic.pixes.begin();
	bool inManyRows = false;
	int numRows = it->second / pic.width;
	if (numRows > 3)
		inManyRows = true;
	if (pic.pixes.size() == 1)
	{
		pic.edges.push_back(pair<int, int> (0, pic.width));
		return;
	}
	for(int i = 0; i < pic.nPixes; ++i)
	{
		int maxEdge = 0;
		if ( inManyRows && blockCounter == pic.width + 1)
		{
			int num2Skip =  (it->second - (2 * pic.width + 2) - 1);
			i += num2Skip;
			blockCounter += num2Skip;
			inManyRows = false;
			if (pic.edges.empty())
				pic.edges.push_back(pair<int, int> (0, num2Skip+1));
			else
				if (pic.edges.back().first  == 0)
					pic.edges.back().second += num2Skip+1;
				else
					pic.edges.push_back(pair<int, int> (0, num2Skip+1));
		}
		else
		{
			for (int j = 0; j < 8 ; ++j)
			{
				int pos = invalidatePos(i, EDGE_POS[j][0], EDGE_POS[j][1], pic.width, pic.height);
				if ( pos > 0)
				{
					int diff = pos - i;
					int relativePos = diff + blockCounter;
					itAround = it;
					int ob = itAround->second;
					if (relativePos >=0 && relativePos < itAround->second)
						;
					else if (relativePos < 0)
						while(relativePos < 0)
						{
							--itAround;
							relativePos += itAround->second;
						}
					else if (relativePos >= it->second)
						while(relativePos >= itAround->second)
						{
							relativePos -= itAround->second;
							++itAround;
						}
					int newEdge = abs(itAround->first - it->first);
					if (maxEdge < newEdge)
						maxEdge = newEdge;
				}
			}
			if (pic.edges.empty())
				pic.edges.push_back(pair<int, int> (maxEdge, 1));
			else
				if (pic.edges.back().first  == maxEdge)
					pic.edges.back().second ++;
				else
					pic.edges.push_back(pair<int, int> (maxEdge, 1));
		}
		blockCounter++;
		if (blockCounter == it->second)
		{
			blockCounter = 0;
			++it;
			int numRows = it->second / pic.width;
			if (numRows > 3)
				inManyRows = true;
		}
	}
		
}


int main(int argc, char* argv[])
{
//	ifstream input("data4.txt", ios::in);
	Picture picture;
//	while (getData(input, picture))
	while (getData(cin, picture))
	{
		edgeDetect(picture);
		Itr it;
		cout << picture.width << "\n";
		for (it = picture.edges.begin(); it != picture.edges.end(); ++it)
			cout << it->first << " " << it->second << "\n";
		cout << "0 0" <<endl;
	}
	cout << "0" << endl;
	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