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. 编写高质量代码改善C#程序的157个建议[4-9]

    前言 本文首先亦同步到http://www.cnblogs.com/aehyok/p/3624579.html.本文主要来学习记录一下内容: 建议4.TryParse比Parse好 建议5.使用int ...

  2. window下为apache配置ssl证书

    转载自 子非鱼 的博客稍作修改 第一步:依赖 配置Apache服务器支持https协议和SSL证书,最基本的要求是Apache包含openssl模块.还好apache/bin目录下有libeay32. ...

  3. oracle-1

    使用sqlplus 进入oracle (1)服务的启动终止 oracle 服务的关闭: SQL> shutdown immediate; oracle服务的启动: SQL> startup ...

  4. Html-Css-iframe的自适应高度方案

    先看一个示例,有两个页面,1.html通过iframe嵌入2.html,两个页面都是同域的 a.html <!DOCTYPE html> <html> <head> ...

  5. note.js之 Mongodb在Nodejs上的配置及session会话机制的实现

    上篇我们使用nodejs实现了一个express4的网站构建配置,但一个有面的网站怎么可以缺少一个数据库呢.现在较为流行的就是使用MONGODB来作为nodejs网站引用的数据库,可能它与nodejs ...

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

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

  7. BZOJ-1876 SuperGCD Python(欧几里德算法)

    第一次感觉Python艹题的快感 1876: [SDOI2009]SuperGCD Time Limit: 4 Sec Memory Limit: 64 MB Submit: 2461 Solved: ...

  8. [NOIP2009] 普及组

    多项式输出 模拟 /*by SilverN*/ #include<algorithm> #include<iostream> #include<cstring> # ...

  9. POJ2253 Frogger

    Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34865   Accepted: 11192 Descrip ...

  10. java获取每个月的最后一天

    package timeUtil; import java.text.SimpleDateFormat; import java.util.Calendar; public class LastDay ...