算法竞赛 之果园里的树



/*果园里的树*/
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string>
using namespace std;
#define max 1000
int a[max][max];


double useful(double x0, double y0, double x1, double y1, double x2, double y2)
{
 return x0*y1 + x2*y0 + x1*y2 - x2*y1 - x0*y2 - x1*y0;
}
int main()
{
 double x0, y0, x1, y1, x2, y2;
 while (cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2)
 {

  /*x0 = int(x0 * 10);
  y0 = int(x0 * 10);
  x1 = int(x0 * 10);
  y1= int(x0 * 10);
  x2 = int(x0 * 10);
  y2= int(x0 * 10);*/
  double abc;
  abc = useful(x0, y0, x1, y1, x2, y2) / 2.00;
  if (abc < 0) abc = -1 * abc;//至此算出三角形有向面积
  double ymaxone = y0;
  double yminone = y0;
  double xminone = x0;
  double xmaxone = x0;
  if (ymaxone < y1)ymaxone = y1;
  if (ymaxone < y2)ymaxone = y2;
  if (yminone > y1)yminone = y1;
  if (yminone > y1)yminone = y2;
  if (xmaxone < x1)xmaxone = x1;
  if (xmaxone < x2)xmaxone = x2;
  if (xminone > x1)xminone = x1;
  if (xminone > x1)xminone = x2;
 // cout << ymaxone << endl << yminone << endl << xmaxone << endl << xminone << endl;
  int count = 0;
  for (int i = ymaxone; i >= yminone; i--)//相当于y
  {
   for (int j = xmaxone; j >= xminone; j--)//相当于x
   {
    double bc = useful(j, i, x1, y1, x2, y2) / 2.00;
    double ac = useful(x0, y0, j, i, x2, y2) / 2.00;
    double ab = useful(x0, y0, x1, y1, j, i) / 2.00;
    if (bc < 0)bc = -1 * bc;
    if (ac < 0)ac = -1 * ac;
    if (ab < 0)ab = -1 * ab;
    double k1 = abc;
    double k2 = bc + ac + ab;
    if (k2 < 0) k2 = -1 * k2;

    double c = k1 - k2;
    if (c < 0)c = c*(-1);
    //cout << i << "  " << j << "       " << k1 << "      " << k2 << "    " << c << endl;
    if (c <= 0.01) count++;
   }
  }
  cout << count << endl;
 }
 system("pause");
 return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值