首页 > ACM题库 > HDU-杭电 > hdu 2911 Digits on the Floor[解题报告]hoj
2014
02-21

hdu 2911 Digits on the Floor[解题报告]hoj

Digits on the Floor

问题描述 :

Taro attempts to tell digits to Hanako by putting straight bars on the floor. Taro wants to express each digit by making one of the forms shown in Figure 2.

Since Taro may not have bars of desired lengths, Taro cannot always make forms exactly as shown in Figure 2. Fortunately, Hanako can recognize a form as a digit if the connection relation between bars in the form is kept. Neither the lengths of bars nor the directions of forms affect Hanako� perception as long as the connection relation remains the same. For example, Hanako can recognize all the awkward forms in Figure 3 as digits. On the other hand, Hanako cannot recognize the forms in Figure 4 as digits. For clarity, touching bars are slightly separated in Figures 2, 3 and 4. Actually, touching bars overlap exactly at one single point.


In the forms, when a bar touches another, the touching point is an end of at least one of them. That is, bars never cross. In addition, the angle of such two bars is always a right angle.

To enable Taro to represent forms with his limited set of bars, positions and lengths of bars can be changed as far as the connection relations are kept. Also, forms can be rotated. Keeping the connection relations means the following.


?Separated bars are not made to touch.

?Touching bars are not made separate.

?When one end of a bar touches another bar, that end still touches the same bar. When ittouches a midpoint of the other bar, it remains to touch a midpoint of the same bar on the same side.

?The angle of touching two bars is kept to be the same right angle (90 degrees and −90 degrees are considered different, and forms for 2 and 5 are kept distinguished). Your task is to find how many times each digit appears on the floor. The forms of some digits always contain the forms of other digits. For example, a form for 9 always contains four forms for 1, one form for 4, and two overlapping forms for 7. In this problem, ignore the forms contained in another form and count only the digit of the �argest?form composed of all mutually connecting bars. If there is one form for 9, it should be interpreted as one appearance of 9 and no appearance of 1, 4, or 7.

输入:

The input consists of a number of datasets. Each dataset is formatted as follows.

n
x1a y1a x1b y1b

x2a y2a x2b y2b

xna yna xnb xnb

In the first line, n represents the number of bars in the dataset. For the rest of the lines, one line represents one bar. Four integers xa, ya, xb, yb, delimited by single spaces, are given in each line. xa and ya are the x- and y-coordinates of one end of the bar, respectively. xb and yb are those of the other end. The coordinate system is as shown in Figure 5. You can assume 1 ≤ n ≤ 1000 and 0 ≤ xa; ya; xb; yb ≤ 1000. The end of the input is indicated by a line containing one zero.

You can also assume the following conditions.

More than two bars do not overlap at one point.

Every bar is used as a part of a digit. Non-digit forms do not exist on the floor.

A bar that makes up one digit does not touch nor cross any bar that makes up another digit.

There is no bar whose length is zero.

输出:

The input consists of a number of datasets. Each dataset is formatted as follows.

n
x1a y1a x1b y1b

x2a y2a x2b y2b

xna yna xnb xnb

In the first line, n represents the number of bars in the dataset. For the rest of the lines, one line represents one bar. Four integers xa, ya, xb, yb, delimited by single spaces, are given in each line. xa and ya are the x- and y-coordinates of one end of the bar, respectively. xb and yb are those of the other end. The coordinate system is as shown in Figure 5. You can assume 1 ≤ n ≤ 1000 and 0 ≤ xa; ya; xb; yb ≤ 1000. The end of the input is indicated by a line containing one zero.

You can also assume the following conditions.

More than two bars do not overlap at one point.

Every bar is used as a part of a digit. Non-digit forms do not exist on the floor.

A bar that makes up one digit does not touch nor cross any bar that makes up another digit.

There is no bar whose length is zero.

样例输入:

9
60 140 200 300
300 105 330 135
330 135 250 215
240 205 250 215
298 167 285 154
30 40 30 90
30 90 150 90
150 90 150 20
30 40 150 40
8
320 20 300 60
320 20 380 50
380 50 240 330
10 50 40 20
10 50 110 150
110 150 180 80
40 20 37 17
37 17 27 27
20
72 222 132 182
204 154 204 54
510 410 520 370
404 54 204 54
530 450 410 450
204 68 404 68
80 110 120 30
130 160 180 60
520 370 320 320
310 360 320 320
120 30 180 60
60 100 80 110
404 154 204 154
80 60 60 100
430 550 590 550
510 410 310 360
430 450 430 550
404 54 404 154
232 202 142 262
142 262 102 202
0

样例输出:

0 1 0 1 0 0 0 0 0 1
0 0 0 0 0 1 0 1 0 0
1 0 1 0 2 0 0 0 1 0

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <map>
#include <string>
using namespace std;
#define LL long long
#define M 1005

int a[M][M];
int equ, var;

void ini () { memset (a, 0, sizeof(a)); }

int Gauss ()
{
	int i, j, k;
	int col = 0;
	for (k = 0; k < equ && col < var; k++, col++)
	{
		for (i = k+1; i < equ; i++) while (a[i][col])
		{
			LL tp = a[k][col] & a[i][col];
			for (j = col; j <= var; j++)
			{
				a[k][j] = a[k][j] ^ (a[i][j]&tp);
				swap (a[k][j], a[i][j]);
			}
		}
		if (a[k][col] == 0) { k--; continue; };
	}
	for (i = k; i < equ; i++)
		if (a[i][col] != 0)
			return -1;
	return var-k;
}

int p[65] = {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
283, 293};

int main()
{
	int t, cc = 0, n, i, j, k = 62;
	LL x;
	scanf ("%d", &t);
	while (t--)
	{
		scanf ("%d", &n);
		ini ();
		equ = k; var = n;
		for (i = 0; i < n; i++)
		{
			scanf ("%lld", &x);
			for (j = 0; j < k && x >= p[j]; j++)
			{
				while (x % p[j] == 0)
				{
					a[j][i] = !a[j][i];
					x /= p[j];
				}
			}
		}
		int fn = Gauss ();
		LL ans = 1;
		if (fn == -1) ans = 0;
		else
		{
			int mod = 1000000007;
			while (fn--) ans = (ans<<1) % mod;
			ans = (ans-1+mod) % mod;
		}
		printf ("Case %d: %lld\n", ++cc, ans);
	}
	return 0;
}

  1. 学算法中的数据结构学到一定程度会乐此不疲的,比如其中的2-3树,类似的红黑树,我甚至可以自己写个逻辑文件系统结构来。

  2. 我没看懂题目
    2
    5 6 -1 5 4 -7
    7 0 6 -1 1 -6 7 -5
    我觉得第一个应该是5 6 -1 5 4 输出是19 5 4
    第二个是7 0 6 -1 1 -6 7输出是14 7 7
    不知道题目例子是怎么得出来的

  3. Gucci New Fall Arrivals

    This is really nice to know. I hope it will be successful in the future. Good job on this and keep up the good work.

  4. [email protected]