Inlay Cutters
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2367   Accepted: 995

Description

The factory cuts rectangular M × N granite plates into pieces using a special machine that is able to perform cuts in 4 different directions: vertically, horizontally, and diagonally at the angle of 45 degrees to the sides of the plate. Every cut is a straight line that starts and ends on the side of the plate. 
The factory has been ordered to produce tiles for the inlay, each tile of which is a 45 degrees right triangle. To reduce the time to deliver the tiles it was decided to take all triangles from the already cut plates. Information about all performed cuts is available and your task is to compute the number of triangles of any size that were produced. 

Input

The input describes the cuts that were performed on a single rectangular plate. The first line of the input file contains three integer numbers M, N, and K, separated by spaces. M and N (1 ≤ M, N ≤ 50) are the dimensions of the plate, and K (0 ≤ K ≤ 296) is the number of cuts. Next K lines describe the cuts. ith cut is described by four integer numbers Xi,1, Yi,1, Xi,2, and Yi,2, separated by spaces, that represent the starting and ending point of the cut. Both starting (Xi,1, Yi,1) and ending (Xi,2, Yi,2) points of the cut are situated on the plate's border. Both points of the cut are different and the cut goes through the plate. Here, the coordinates by the X axis run from 0 to M, and the coordinates by the Y axis run from 0 to N. All cuts are different.

Output

Write to the output a single integer number - the number of triangles that were produced by the cuts.

Sample Input

7 4 6
6 0 7 1
1 4 1 0
0 4 4 0
0 0 4 4
0 2 7 2
7 0 3 4

Sample Output

8

Source

 #include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
int a[ * ][ * ] ;
bool map[ * ][ * ] ;
int col , row , cut ;
int x1 , y1 , x2 , y2 ;
int sum = ;
int move[][] = {{-,,,},{-,,,},{,,,},{,,,-},{,,,-},{,-,-,-},{,-,-,},{-,-,-,}}; void hua1 ()
{
for (int i = y1 ; i <= y2 ; i++) {
a[x1][i] += ;
}
} void hua2 ()
{
for (int i = x1 ; i <= x2 ; i++) {
a[i][y1] += ;
}
} void hua3 ()
{
int cnt = y2 - y1 + ;
int x = x1 , y = y1 ;
while (cnt--) {
a[x][y] += ;
x ++ , y ++ ;
}
} void hua4 ()
{
int cnt = x2 - x1 + ;
int x = x1 , y = y1 ;
while (cnt--) {
a[x][y] += ;
x ++ , y-- ;
}
} bool judge1 (int x1 ,int y1 ,int x2 ,int y2)
{
int cnt = x2 - x1 - ;
int x = x1 + , y = y1 + ;
while (cnt --) {
if (a[x][y] != ) {
return false ;
}
x ++ , y ++ ;
}
return true ;
} bool judge2 (int x1 , int y1 , int x2 , int y2)
{
int cnt = x2 - x1 - ;
int x = x1 + , y = y1 - ;
while (cnt--) {
if (a[x][y] != ) {
return false ;
}
x++ , y-- ;
}
return true ;
} bool judge3 (int x1 , int y1 , int x2 , int y2)
{
int cnt = x2 - x1 - ;
int x = x1 + ;
while (cnt--) {
if (a[x][y1] != ) {
return false ;
}
x ++ ;
}
return true ;
} bool judge4 (int x1 , int y1 , int x2 , int y2)
{
int cnt = y2 - y1 - ;
int y = y1 + ;
while (cnt --) {
if (a[x1][y] != ) {
return false ;
}
y ++ ;
}
return true ;
} void bfs (int sx , int sy)
{
// printf ("sx = %d , sy = %d\n" , sx , sy) ;
for (int i = ; i < ; i++) {
int x1 = sx + move[i][] , y1 = sy + move[i][] ;
int x2 = sx + move[i][] , y2 = sy + move[i][] ;
if (x1 < || y1 < || x1 > row || y1 > col ) {
continue ;
}
if (x2 < || y2 < || x2 > row || y2 > col ) {
continue ;
}
if (a[x1][y1] * a[x2][y2] == ) {
continue ;
}
while(a[x1][y1] * a[x2][y2] == ) {
x1 += move[i][] ;
y1 += move[i][] ;
x2 += move[i][] ;
y2 += move[i][] ;
}
if (a[x1][y1] * a[x2][y2] == ) {
continue ;
}
if (a[x1][y1] == || a[x2][y2] == ) {
continue ;
}
if (x1 != x2) {
int k = (y2 - y1) / (x2 - x1) ;
if (k == ) {
if (x1 > x2) {
x1 ^= x2 ^= x1 ^= x2 ;
y1 ^= y2 ^= y1 ^= y2 ;
}
if (judge1 (x1 , y1 , x2 , y2) ) {
sum ++ ;
}
}
else if (k == -) {
if (x1 > x2) {
x1 ^= x2 ^= x1 ^= x2 ;
y1 ^= y2 ^= y1 ^= y2 ;
}
if ( judge2 (x1 , y1 , x2 , y2) ) {
sum ++ ;
}
}
else {
if (x1 > x2) {
x1 ^= x2 ^= x1 ^= x2 ;
}
if ( judge3 (x1 , y1 , x2 , y2) ) {
sum ++ ;
}
}
}
else {
if (y1 > y2) {
y1 ^= y2 ^= y1 ^= y2 ;
}
if ( judge4 (x1 , y1 , x2 , y2) ) {
sum ++ ;
}
}
}
} int main ()
{
// freopen ("a.txt" , "r" , stdin ) ;
scanf ("%d%d%d" , &col , &row , &cut ) ;
col *= , row *= ;
for (int i = ; i <= row ; i++) {
a[i][col] += ;
a[i][] += ;
}
for (int i = ; i <= col ; i++) {
a[row][i] += ;
a[][i] += ;
}
while (cut--) {
scanf ("%d%d%d%d" , &y1 , &x1 , &y2 , &x2 ) ;
x1 *= , y1 *= , x2 *= , y2 *= ;
if (x1 == x2) {
if (y1 > y2) {
y1 ^= y2 ^= y1^= y2 ;
}
hua1 () ;
}
else if (y1 == y2) {
if (x1 > x2) {
x1 ^= x2 ^= x1 ^= x2 ;
}
hua2 () ;
}
else if ( (y2 - y1) / (x2 - x1) == ) {
if (y1 > y2) {
y1 ^= y2 ^= y1^= y2 ;
x1 ^= x2 ^= x1 ^= x2 ;
}
hua3 () ;
}
else if ( (y2 - y1) / (x2 - x1) == - ) {
if (x1 > x2) {
y1 ^= y2 ^= y1^= y2 ;
x1 ^= x2 ^= x1 ^= x2 ;
}
hua4 () ;
}
} /* for (int i = 0 ; i <= row ; i++) {
for (int j = 0 ; j<= col ; j++) {
printf ("%d " , a[i][j]) ;
}
puts ("") ;
}*/ for (int i = ; i <= row ; i++) {
for (int j = ; j <= col ; j++) {
if (a[i][j] > ) {
bfs (i , j) ;
}
}
}
printf ("%d\n" , sum ) ; }

poj1279.Inlay Cutters(模拟 + 枚举)的更多相关文章

  1. PHP用Array模拟枚举

    C#中枚举Enum的写法: /// <summary> /// 公开类型 2-好友可见 1-公开 0-不公开 /// </summary> public enum OpenSt ...

  2. Luogu P1039 侦探推理(模拟+枚举)

    P1039 侦探推理 题意 题目描述 明明同学最近迷上了侦探漫画<柯南>并沉醉于推理游戏之中,于是他召集了一群同学玩推理游戏.游戏的内容是这样的,明明的同学们先商量好由其中的一个人充当罪犯 ...

  3. BZOJ 1088: [SCOI2005]扫雷Mine【思维题,神奇的模拟+枚举】

    1088: [SCOI2005]扫雷Mine Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3791  Solved: 2234[Submit][St ...

  4. UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  5. USACO 1.3.4 Prime Cryptarithm 牛式(模拟枚举)

    Description 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. * * * x * * ------- * * * * * * ------ ...

  6. Codeforces Round #417 (Div. 2)A B C E 模拟 枚举 二分 阶梯博弈

    A. Sagheer and Crossroads time limit per test 1 second memory limit per test 256 megabytes input sta ...

  7. ACM-ICPC北京赛区(2017)网络赛1【模拟+枚举+数组操作】

    题目1 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for n ...

  8. zoj 3627#模拟#枚举

    Treasure Hunt II Time Limit: 2 Seconds                                     Memory Limit: 65536 KB    ...

  9. P1203 [USACO1.1]Broken Necklace(模拟-枚举)

    P1203 [USACO1.1]坏掉的项链Broken Necklace 题目描述 你有一条由N个红色的,白色的,或蓝色的珠子组成的项链(3<=N<=350),珠子是随意安排的. 这里是 ...

随机推荐

  1. [转]Extundelete--数据恢复软件

    前言 作为一名运维人员,保证数据的安全是根本职责,所以在维护系统的时候,要慎之又慎,但是有时难免会出现数据被误删除的情况,在这个时候该如何快速.有效地恢复数据显得至关重要,extundelete就是其 ...

  2. [Json.net]快速入门

    引言 有个朋友问了一个如何更方便的解析json格式字符串,之前也没怎么研究过json.net,就上网帮他查了一下,现学现卖的给他整了一个demo,这才发现json.net的强大,用着很方便. Json ...

  3. C# 使用XML序列化对象(二)

    在C# 使用XML序列化对象(一)中描述了使用XML序列化对象的最简单的实现. 现在我们来看看稍微复杂一点的情况: 现有两个类:A和B,B是A的派生类,如下所示: public class A { p ...

  4. WordPress Option API(数据库储存 API)

    WordPress Option API 是提供给开发者的数据库存储机制,通过调用函数,可以快速.安全的把数据存储到数据库里(都在 wp_options 表). 每个设置的模式是 key – valu ...

  5. SQL Network Interfaces, error: 50 - 发生了 Local Database Runtime 错误。无法创建自动实例。

    今天在用VS2013自带的LocalDB调整数据库时出错,在网上也搜到许多方案,如卸载SQLServer LocalDB的程序.重新创建实例等都没有解决我的问题,也重新修改以及修复Vs,问题依旧存在, ...

  6. codevs3243 区间翻转

    题目描述 Description 给出N个数,要求做M次区间翻转(如1 2 3 4变成4 3 2 1),求出最后的序列 输入描述 Input Description 第一行一个数N,下一行N个数表示原 ...

  7. .net 时间戳互相转换(精确到毫秒)

    这里记录一个时间戳的互相转换方法,网上都找了,基本都没有精确到毫秒,我的这个基本可以满足精确到毫秒的级别,代码如下: /// <summary> /// Unix时间戳转换为DateTim ...

  8. POJ3259Wormholes(判断是否存在负回路)

    Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 38300   Accepted: 14095 Descr ...

  9. Jquery easyui datagrid 删除多行问题

    http://www.cnblogs.com/Dtscal/archive/2012/07/04/2576639.html 最近模仿了刘冬大哥的<开源框架完美组合之Spring.NET + NH ...

  10. python学习笔记之module && package

    个人总结: import module,module就是文件名,导入那个python文件 import package,package就是一个文件夹,导入的文件夹下有一个__init__.py的文件, ...