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. #Linux学习笔记# Linux文件的所有者、群组和其他人

    1.关于所有者.群组和其他人 在Linux系统中,每个文件都具有User.Group和Others三种身份的权限配置.那这三种身份分别表示什么意思呢?配置这三种身份的权限有啥意义呢? (1)文件所有者 ...

  2. Bootstrap系列 -- 32. 按钮垂直分组

    实际运用当中,总会碰到垂直显示的效果.在Bootstrap框架中也提供了这样的风格.我们只需要把水平分组的“btn-group”类名换成“btn-group-vertical”即可. <div ...

  3. [整理] ES5 词法约定文档树状图

    将ES5 词法说明整理为了树状图,方便查阅,请自行点开小图看大图:

  4. javascript继承(四)—prototype属性介绍

    js里每一个function都有一个prototype属性,而每一个实例都有constructor属性,并且每一个function的prototype都有一个constructor属性,这个属性会指向 ...

  5. iOS 使用AFNetworking遇到异常 Request failed: unacceptable content-type: text/html

    错误日志是: Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unac ...

  6. 使用background和background-image对CSS优先级造成影响

    在写一个关于背景图的CSS时候发现一个奇怪的现象, 原图: 如下代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitiona ...

  7. poj3522 kruskal+枚举

    题目的意思是求构成生成树的边的最大边和最小边的差最小.枚举即可 #include<stdio.h> #include<string.h> #include<algorit ...

  8. 使用X-UA-Compatible来设置IE浏览器兼容模式

    文件兼容性用于定义让IE如何编译你的网页.此文件解释文件兼容性,如何指定你网站的文件兼容性模式以及如何判断一个网页该使用的文件模式. 前言 为了帮助确保你的网页在所有未来的IE版本都有一致的外观,IE ...

  9. iOS-编译简单静态库初探

    首先声明,我写的这些网上都有更详细的内容,在这里只是写下我自己总结的一些重要内容,具体步骤如下: 事先准备:新建工程-Framework & Library - Cocoa Touch Sta ...

  10. 【SDOI2009】解题汇总

    又开了波专题,感觉就和炉石开冒险一样...(说的好像我有金币开冒险似的) /---------------------------------------------/ BZOJ-1226 [SDOI ...