Two Triangles FZU - 2270 (暴力+极角排序)

题目链接:

https://cn.vjudge.net/problem/FZU-2270

题目大意:

给你n个点,然后每一次你从中选三个点,另一个人再选三个。在都能构成三角形的条件下,如果这两个三角形能通过平移,旋转和另外一个三角形完全重合,贡献加1,问你最终能有多少贡献?

具体思路:

延亮的思路,学习下

六个for循环枚举。

具体检验的时候,首先判断能不能构成三角形;然后分别对两个 三角形的三个向量进行极角排序,每一次比较的按照顺时针方向比较就好了。

https://www.cnblogs.com/aiguona/p/7248311.html

 

极角排序,给定平面上的一些点,把它们按照一个选定的中心点排成顺(逆)时针。

AC代码:

  1 #include<iostream>
  2 #include<stdio.h>
  3 #include<cmath>
  4 #include<algorithm>
  5 #include<string>
  6 #include<cstring>
  7 # define ll long long
  8 # define inf 0x3f3f3f3f
  9 # define ull unsigned long long
 10 using namespace std;
 11 const int maxn = 2e5+100;
 12 struct node{int x,y;} q[maxn];
 13 struct Edge{
 14 int x,y;
 15 int dis;
 16 Edge(){}
 17 Edge(int xx,int yy,int zz){
 18 x=xx;
 19 y=yy;
 20 dis=zz;
 21 }
 22 };
 23 double sto1[4],sto2[4];
 24 double dis1(int t1,int t2){
 25 return sqrt((q[t1].x-q[t2].x)*(q[t1].x-q[t2].x)*1.0+(q[t1].y-q[t2].y)*(q[t1].y-q[t2].y)*1.0);
 26 }
 27 int dis2(int t1,int t2){
 28 return (q[t1].x-q[t2].x)*(q[t1].x-q[t2].x)+(q[t1].y-q[t2].y)*(q[t1].y-q[t2].y);
 29 }
 30 bool cmp(Edge t1,Edge t2){// 极角排序
 31 return (t1.x*t2.y)-(t1.y*t2.x)>0;
 32 }
 33 bool check(int a,int b,int c,int d,int e,int f){
 34 sto1[1]=dis1(a,b);
 35 sto1[2]=dis1(b,c);
 36 sto1[3]=dis1(c,a);
 37 sto2[1]=dis1(d,e);
 38 sto2[2]=dis1(e,f);
 39 sto2[3]=dis1(f,d);
 40 
 41 sort(sto1+1,sto1+1+3);
 42 sort(sto2+1,sto2+1+3);
 43 
 44 if(sto1[1]+sto1[2]<=sto1[3])return false;
 45 if(sto2[1]+sto2[2]<=sto2[3])return false;/// compose triangle
 46 
 47 Edge tmp1[4],tmp2[4];
 48 
 49 tmp1[1]=Edge(q[a].x-q[b].x,q[a].y-q[b].y,dis2(a,b));
 50 tmp1[2]=Edge(q[b].x-q[c].x,q[b].y-q[c].y,dis2(b,c));
 51 tmp1[3]=Edge(q[c].x-q[a].x,q[c].y-q[a].y,dis2(c,a));
 52 
 53 tmp2[1]=Edge(q[d].x-q[e].x,q[d].y-q[e].y,dis2(d,e));
 54 tmp2[2]=Edge(q[e].x-q[f].x,q[e].y-q[f].y,dis2(e,f));
 55 tmp2[3]=Edge(q[f].x-q[d].x,q[f].y-q[d].y,dis2(f,d));
 56 
 57 sort(tmp1+1,tmp1+1+3,cmp);
 58 sort(tmp2+1,tmp2+1+3,cmp);
 59 
 60 if(tmp1[1].dis==tmp2[1].dis&&tmp1[2].dis==tmp2[2].dis&&tmp1[3].dis==tmp2[3].dis)return true;
 61 if(tmp1[1].dis==tmp2[2].dis&&tmp1[2].dis==tmp2[3].dis&&tmp1[3].dis==tmp2[1].dis)return true;
 62 if(tmp1[1].dis==tmp2[3].dis&&tmp1[2].dis==tmp2[1].dis&&tmp1[3].dis==tmp2[2].dis)return true;
 63 return false;
 64 }
 65 int a[10];
 66 int main()
 67 {
 68     int T,Case=0;
 69     scanf("%d",&T);
 70     while(T--)
 71     {
 72         int n;
 73         int ans=0;
 74         scanf("%d",&n);
 75         for(int i=1; i<=n; i++)
 76         {
 77             scanf("%d %d",&q[i].x,&q[i].y);
 78         }
 79         for(int i=1; i<=n; i++)
 80         {
 81             for(int j=i+1; j<=n; j++)
 82             {
 83                 for(int k=j+1; k<=n; k++)
 84                 {
 85                     for(int w=1; w<=n; w++)
 86                     {
 87                         for(int L=w+1; L<=n; L++)
 88                         {
 89                             for(int J=L+1; J<=n; J++)
 90                             {
 91                                 a[1]=i;
 92                                 a[2]=j;
 93                                 a[3]=k;
 94                                 a[4]=w;
 95                                 a[5]=L;
 96                                 a[6]=J;
 97                                 sort(a+1,a+6+1);
 98                                 int flag=1;
 99                                 for(int q=2; q<=6; q++)
100                                 {
101                                     if(a[q]==a[q-1])
102                                     {
103                                         flag=0;
104                                         break;
105                                     }
106                                 }
107                                 if(!flag)
108                                 continue;
109                                 if(check(i,j,k,w,L,J))
110                                     ans++;
111                             }
112                         }
113                     }
114                 }
115             }
116         }
117         printf("Case %d: %d\n",++Case,ans);
118     }
119     return 0;
120 }

 

 

转载于:https://www.cnblogs.com/letlifestop/p/10994862.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
class CubeModel : IBufferSource { private const float halfLength = 0.5f; private static readonly vec3[] positions = new vec3[] { new vec3(+halfLength, +halfLength, +halfLength), // 0 new vec3(+halfLength, +halfLength, -halfLength), // 1 new vec3(+halfLength, -halfLength, +halfLength), // 2 new vec3(+halfLength, -halfLength, -halfLength), // 3 new vec3(-halfLength, +halfLength, +halfLength), // 4 new vec3(-halfLength, +halfLength, -halfLength), // 5 new vec3(-halfLength, -halfLength, +halfLength), // 6 new vec3(-halfLength, -halfLength, -halfLength), // 7 }; private static readonly uint[] indexes = new uint[] { 0, 2, 1, 1, 2, 3, // +X faces. 0, 1, 5, 0, 5, 4, // +Y faces. 0, 4, 2, 2, 4, 6, // +Z faces. 7, 6, 4, 7, 4, 5, // -X faces. 7, 5, 3, 3, 5, 1, // -Z faces. 7, 3, 2, 7, 2, 6, // -Y faces. }; public const string strPosition = "position"; private VertexBuffer positionBuffer; // array in GPU side. private IDrawCommand drawCommand; #region IBufferSource 成员 public IEnumerable<VertexBuffer> GetVertexAttribute(string bufferName) { if (strPosition == bufferName) // requiring position buffer. { if (this.positionBuffer == null) { // transform managed array to vertex buffer. this.positionBuffer = positions.GenVertexBuffer( VBOConfig.Vec3, // mapping to 'in vec3 someVar;' in vertex shader. BufferUsage.StaticDraw); // GL_STATIC_DRAW. } yield return this.positionBuffer; } else { throw new ArgumentException("bufferName"); } } public IEnumerable<IDrawCommand> GetDrawCommand() { if (this.drawCommand == null) { // indexes in GPU side. IndexBuffer indexBuffer = indexes.GenIndexBuffer(BufferUsage.StaticDraw); this.drawCommand = new DrawElementsCmd(indexBuffer, DrawMode.Triangles); // GL_TRIANGLES. } yield return this.drawCommand; } #endregion }逐行分段解释上述程序
05-10

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值