题目链接:https://www.spoj.com/problems/AMR11B/en/

题目大意就是要你求图形覆盖的格点数,标记每个图形里的未标记格点(包括边界),总标记数就是覆盖的总格点数。

 #include<iostream>
#include<algorithm>
using namespace std;
struct node{
int x;
int y;
};
int t,n,visit[][];
void ri(node &a)//将每个点的横纵坐标加100
{
a.x+=;
a.y+=;
}
int po(node a,node b)//计算向量的点乘
{
return a.x*b.x+a.y*b.y;
}
int main()
{
cin>>t;
while(t--)
{
cin>>n;
getchar();
for(int i=;i<;i++)
for(int j=;j<;j++)
visit[i][j]=;
while(n--)
{
char op[];
cin>>op;
if(op[]=='S')
{
node a;
int l;
cin>>a.x>>a.y>>l;
ri(a);
for(int i=a.x;i<=a.x+l;i++)
for(int j=a.y;j<=a.y+l;j++)
if(!visit[i][j])
visit[i][j]=;
}
else if(op[]=='C')
{
node a;
int r;
cin>>a.x>>a.y>>r;
ri(a);
for(int i=a.x-r;i<=a.x+r;i++)
for(int j=a.y-r;j<=a.y+r;j++)
if(!visit[i][j]&&(abs(a.x-i)*abs(a.x-i)+abs(a.y-j)*abs(a.y-j)<=r*r))
visit[i][j]=;
}
else
{//判断点是否在三角形内用到了斜面坐标系法,参考链接我会发到下面
node A,B,C,AC,AB;
cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y;
ri(A);ri(B);ri(C);
int x1,x2,y1,y2;
x1=min(A.x,min(B.x,C.x));x2=max(A.x,max(B.x,C.x));//锁定判断范围
y1=min(A.y,min(B.y,C.y));y2=max(A.y,max(B.y,C.y));
AC.x=C.x-A.x;AC.y=C.y-A.y;AB.x=B.x-A.x;AB.y=B.y-A.y;
for(int i=x1;i<=x2;i++)
for(int j=y1;j<=y2;j++)
if(!visit[i][j])
{
node P,AP;
P.x=i;P.y=j;
AP.x=P.x-A.x;AP.y=P.y-A.y;
int a=po(AP,AC),b=po(AB,AB),c=po(AP,AB),d=po(AC,AB),e=po(AC,AC),ans;
ans=(a*b-c*d)+(c*e-a*d)-(e*b-d*d);
if((a*b-c*d)>=&&(c*e-a*d)>=)
if(ans<=)
{
visit[i][j]=;
}
}
}
}
int ans=;
for(int i=;i<;i++)
for(int j=;j<;j++)
if(visit[i][j])
ans++;
cout<<ans<<endl;
}
return ;
}

判断点是否在三角形内:https://www.cnblogs.com/kyokuhuang/p/4314173.html

SPOJ - AMR11B的更多相关文章

  1. Spring-2-B Save the Students(SPOJ AMR11B)解题报告及测试数据

    Save the Students Time Limit:134MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Descri ...

  2. SPOJ - AMR11B 判断是否在三角形 正方形 圆形内

    Hogwarts is under attack by the Dark Lord, He-Who-Must-Not-Be-Named. To protect the students, Harry ...

  3. BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]

    2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 5217  Solved: 1233 ...

  4. SPOJ DQUERY D-query(主席树)

    题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...

  5. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  6. 【填坑向】spoj COT/bzoj2588 Count on a tree

    这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...

  7. SPOJ bsubstr

    题目大意:给你一个长度为n的字符串,求出所有不同长度的字符串出现的最大次数. n<=250000 如:abaaa 输出: 4 2 1 1 1 spoj上的时限卡的太严,必须使用O(N)的算法那才 ...

  8. 【SPOJ 7258】Lexicographical Substring Search

    http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和 ...

  9. 【SPOJ 1812】Longest Common Substring II

    http://www.spoj.com/problems/LCS2/ 这道题想了好久. 做法是对第一个串建后缀自动机,然后用后面的串去匹配它,并在走过的状态上记录走到这个状态时的最长距离.每匹配完一个 ...

随机推荐

  1. Numpy学习笔记(一)

    (1)NumPy的核心对象 ndarray  用于表示N 维数组类型.它描述相同类型的元素集合. 可以使用基于零的索引访问集合中的项目. (2)Ndarray的创建 可以使用numpy.array() ...

  2. bzoj2141排队

    /* 动态求逆序对,可以树套树来写, 将交换操作理解成插入和删除比较好理解, 里层是个区间求和的线段树就好了 或者叫 带修主席树? */ #include<cstdio> #include ...

  3. QTP 学习 - 参数化

  4. lambda表达式,filter,map,reduce,curry,打包与解包和

    当然是函数式那一套黑魔法啦,且听我细细道来. lambda表达式 也就是匿名函数. 用法:lambda 参数列表 : 返回值 例: +1函数 f=lambda x:x+1 max函数(条件语句的写法如 ...

  5. tp5文件上传展示

    //接收文件 $file = request()->file('image'); //将文件移动到框架应用根目录/public/uploads/ 目录下 $info = $file->mo ...

  6. oracle数据链接

    using System; using System.Collections.Generic; using System.Data; using System.Data.OracleClient; u ...

  7. Week__8

    Monday_ 今晚补了扔鸡蛋问题的动态规划问题,补了这道题,感觉视野又开阔了些. 写了一道思维题cf 1066A 数字逻辑后半节听得打脑壳,现在很晚了,明天再看叭. Tuesday_ 今晚补了 ad ...

  8. git push以后GitHub上文件夹灰色 不可点击

    1.删除本地文件夹里的 .git .gitignore文件 2.如果没成功,就把文件名改下,应该是有缓存,改完名后再add/commit/push

  9. 吴裕雄 python深度学习与实践(16)

    import struct import numpy as np import matplotlib.pyplot as plt dateMat = np.ones((7,7)) kernel = n ...

  10. azkaban 配置邮件

    1.配置邮件请在azkaban-web-server中进行配置:如下图:      /opt/azkaban/azkaban/azkaban-web-server/build/install/azka ...