poj1279.Inlay Cutters(模拟 + 枚举)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 2367 | Accepted: 995 |
Description

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
Output
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(模拟 + 枚举)的更多相关文章
- PHP用Array模拟枚举
C#中枚举Enum的写法: /// <summary> /// 公开类型 2-好友可见 1-公开 0-不公开 /// </summary> public enum OpenSt ...
- Luogu P1039 侦探推理(模拟+枚举)
P1039 侦探推理 题意 题目描述 明明同学最近迷上了侦探漫画<柯南>并沉醉于推理游戏之中,于是他召集了一群同学玩推理游戏.游戏的内容是这样的,明明的同学们先商量好由其中的一个人充当罪犯 ...
- BZOJ 1088: [SCOI2005]扫雷Mine【思维题,神奇的模拟+枚举】
1088: [SCOI2005]扫雷Mine Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3791 Solved: 2234[Submit][St ...
- UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- USACO 1.3.4 Prime Cryptarithm 牛式(模拟枚举)
Description 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. * * * x * * ------- * * * * * * ------ ...
- 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 ...
- ACM-ICPC北京赛区(2017)网络赛1【模拟+枚举+数组操作】
题目1 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for n ...
- zoj 3627#模拟#枚举
Treasure Hunt II Time Limit: 2 Seconds Memory Limit: 65536 KB ...
- P1203 [USACO1.1]Broken Necklace(模拟-枚举)
P1203 [USACO1.1]坏掉的项链Broken Necklace 题目描述 你有一条由N个红色的,白色的,或蓝色的珠子组成的项链(3<=N<=350),珠子是随意安排的. 这里是 ...
随机推荐
- 编写高质量代码改善C#程序的157个建议[4-9]
前言 本文首先亦同步到http://www.cnblogs.com/aehyok/p/3624579.html.本文主要来学习记录一下内容: 建议4.TryParse比Parse好 建议5.使用int ...
- window下为apache配置ssl证书
转载自 子非鱼 的博客稍作修改 第一步:依赖 配置Apache服务器支持https协议和SSL证书,最基本的要求是Apache包含openssl模块.还好apache/bin目录下有libeay32. ...
- oracle-1
使用sqlplus 进入oracle (1)服务的启动终止 oracle 服务的关闭: SQL> shutdown immediate; oracle服务的启动: SQL> startup ...
- Html-Css-iframe的自适应高度方案
先看一个示例,有两个页面,1.html通过iframe嵌入2.html,两个页面都是同域的 a.html <!DOCTYPE html> <html> <head> ...
- note.js之 Mongodb在Nodejs上的配置及session会话机制的实现
上篇我们使用nodejs实现了一个express4的网站构建配置,但一个有面的网站怎么可以缺少一个数据库呢.现在较为流行的就是使用MONGODB来作为nodejs网站引用的数据库,可能它与nodejs ...
- SQL Network Interfaces, error: 50 - 发生了 Local Database Runtime 错误。无法创建自动实例。
今天在用VS2013自带的LocalDB调整数据库时出错,在网上也搜到许多方案,如卸载SQLServer LocalDB的程序.重新创建实例等都没有解决我的问题,也重新修改以及修复Vs,问题依旧存在, ...
- BZOJ-1876 SuperGCD Python(欧几里德算法)
第一次感觉Python艹题的快感 1876: [SDOI2009]SuperGCD Time Limit: 4 Sec Memory Limit: 64 MB Submit: 2461 Solved: ...
- [NOIP2009] 普及组
多项式输出 模拟 /*by SilverN*/ #include<algorithm> #include<iostream> #include<cstring> # ...
- POJ2253 Frogger
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34865 Accepted: 11192 Descrip ...
- java获取每个月的最后一天
package timeUtil; import java.text.SimpleDateFormat; import java.util.Calendar; public class LastDay ...