POJ 1231 The Alphabet Game

【题意简述】:输入的k和p,k表示有几个字母,也就是输入有几行,p表示每个字母有几个,是以坐标的形式出现的(x,y).现在让我们将相同的字母划分在一个矩形块中,问能否实现。

【分析】:唉,低级失误!!!记住!积累!

/*
	Date:  2014/11/04
	Time:  21:38
	By	:  VID

	Attention:
		坐标的建立是理解这个问题,梳理思路的关键。
		我的坐标系是x轴指向右,y轴指向下,就像题中的图一样!
*/
// 228K 0ms

#include<iostream>
using namespace std;

#define Max(x,y) ((x)>(y)?(x):(y))
#define Min(x,y) ((x)<(y)?(x):(y))
#define Inf 1000000000

int lef[27],righ[27],up[27],under[27];

bool check(int n)
{
	for(int i = 0;i<n;i++)
	{
		for(int j = 0;j<n;j++)
		{
			if(i == j) continue;
			if(((lef[j]>=lef[i]&&lef[j]<=righ[i]) || (righ[j]<=righ[i]&&righ[j]>=lef[i]))
			&&((up[j]>=up[i]&&up[j]<=under[i]) || (under[j]<=under[i]&&under[j]>=up[i])))

			return 0;
		}
	}
	return 1;
}

int main()
{
	int t,k,p;
	int x,y;
	cin>>t;
	while(t--)
	{
		cin>>k>>p;
		for(int i = 0;i<k;i++)
		{
			int ll = Inf,rr = 0,uup = Inf,un = 0;
			for(int j = 0;j<p;j++)
			{
				cin>>x>>y;
				ll = Min(ll,x),rr = Max(rr,x),uup = Min(uup,y),un = Max(un,y);
			}
			lef[i] = ll,righ[i] = rr,up[i] = uup,under[i] = un;
		}

		for(int i = 0;i<k;i++)
		{
			for(int j =0 ;j<k;j++)
			{
				if(i == j) continue;
				if(lef[i] > lef[j] && lef[i]<righ[j]) lef[i] = lef[j];
				if(righ[i] < righ[j] && righ[i]>lef[j]) righ[i] = righ[j];
				if(up[i] > up[j] && up[i] < under[j])  up[i] = up[j];
				if(under[i] < under[j]&& under[i]>up[j]) under[i] = under[j];
			}
		}
		if(check(k)) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;;
	}
	return 0;
}
时间: 2024-10-23 07:29:57

POJ 1231 The Alphabet Game的相关文章

poj 2530 Tetris Alphabet 拓扑排序

题意: 给一个俄罗斯方块的游戏截图,其中每个输入块都用字母A-Z标志出,求输入块的字典序最小的输入顺序. 分析: 即求字典序最小的拓扑序. 代码: //poj 2530 //sep9 #include <iostream> using namespace std; char map[54][32]; int g[32][32]; int d[32]; int vis[32]; int main() { int n; scanf("%d",&n); memset(g,

POJ 1231(简单搜索)

没什么意思,注意下细节//#include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<cstring> #define inf (0x3f3f3f3f) using namespace std; const int maxn = 16; char Grape[maxn][maxn]; bool vis[maxn]; int n,k,ans; void dfs(int row,int

POJ1231

这道题其实类似暴力...但是编了两次码都没过样例之后发现自己都想错了. 实际上只需要找出所有可能线段,然后对于每一个网格判断一下就可以了. 另外还有一种贪心地方法: 1. 对于同一种字母,求出它出现位置的最左边.最右边.最上边.最下边.这就构成了一个矩形.2. 对于在x轴上投影重合的一系列矩形,他们必定处在同一个方格内.给这些方格编号.3. 对于在y轴上投影重合的一系列矩形,如果其中两个编号相同,就不符合条件了. 1 /************************** 2 POJ 1231

POJ 3461 Oulipo

E - Oulipo Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3461 Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e'. He was a member

poj 3259 Wormholes (负权最短路,SPAF)

Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 36641   Accepted: 13405 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way p

POJ 2704 Pascal&#39;s Travels (基础记忆化搜索)

Pascal's Travels Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5328   Accepted: 2396 Description An n x n game board is populated with integers, one nonnegative integer per square. The goal is to travel along any legitimate path from t

Poj 3259 Wormholes

1.Link: http://poj.org/problem?id=3259 2.Content: Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 32078   Accepted: 11651 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A w

POJ 2488 A Knight&#39;s Journey

A Knight's Journey Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 248864-bit integer IO format: %lld      Java class name: Main Background  The knight is getting bored of seeing the same black and white squa

POJ 3356 AGTC(最长公共子序列)

AGTC Description Let x and y be two strings over some finite alphabet A. We would like to transform x into y allowing only operations given below: Deletion: a letter in x is missing in y at a corresponding position. Insertion: a letter in y is missin