ZOJ 1041Transmitters

 虽然归属于search problems,但是用简单的方法就可以做了。所有的长度都是double,用int就错了。scanf读取double应该用%lf,用%f g++会读取错误。这种浮点数计算,尽量不要用除法、开方,改成乘法。用atan2不知道算不算错,反正改成了叉乘了。最后输出的时候错误地+1,导致浪费了很多时间。 

 

//ZOJ1041Transmitters
#include <iostream>
#include <stdio.h>
#include <math.h>
//#define DEBUG
using namespace std;

int main(int argc, char *argv[])
{
        double tr[2], radius, pt[155][2], pt_tmp[2], dist_tmp[2];
        int pt_sum, pt_r_sum, same_count[155], max_count;
        double base_angle, angle, angle_diff;
        while (scanf("%lf%lf%lf", &tr[0], &tr[1], &radius) && radius >= 0)
        {
                scanf("%d", &pt_sum);
#ifdef DEBUG
                //cout << tr[0] << " " << tr[1] << " " << radius << " " << pt_sum << endl;
#endif
                if (pt_sum == 0)
                {
                        cout << 0 << endl;
                        continue;
                }
                pt_r_sum = 0;
                for (int i = 0; i < pt_sum; i ++)
                {
                        cin >> pt_tmp[0] >> pt_tmp[1];
                        dist_tmp[0] = (pt_tmp[0] - tr[0]);
                        dist_tmp[1] = (pt_tmp[1] - tr[1]);
                        if (dist_tmp[0] * dist_tmp[0] + dist_tmp[1] * dist_tmp[1]
                                <= radius * radius)
                        {
                                same_count[pt_r_sum] = 0;
                                pt[pt_r_sum][0] = pt_tmp[0];
                                pt[pt_r_sum][1] = pt_tmp[1];
                                pt_r_sum ++;
                        }
                }
                for (int i = 0; i < pt_r_sum; i ++)
                {
                        //base_angle = atan2(pt[i][1] - tr[1], pt[i][0] - tr[0]);
#ifdef DEBUG
                        cout << "pt " << i << " baseangle " << base_angle << endl;
#endif
                        for (int j = 0; j < pt_r_sum; j ++)
                        {
                                //if (j == i)
                                //      continue;
                                //angle = atan2(pt[j][1] - tr[1], pt[j][0] - tr[0]);
                                //angle_diff = angle - base_angle;
                                //if (angle_diff <= -M_PI)
                                //      angle_diff += 2.0 * M_PI;
                                //else if (angle_diff >= M_PI)
                                //      angle_diff -= 2.0 * M_PI;
#ifdef DEBUG
                                cout << "anglediff " << j << " " << angle_diff << endl;
#endif
                                //if (angle_diff >= 0)
                                if ((pt[i][0] - tr[0]) * (pt[j][1] - tr[1])
                                        - (pt[j][0] - tr[0]) * (pt[i][1] - tr[1]) >= 0)
                                {
                                        same_count[i] ++;
#ifdef DEBUG
                                        cout << "pt " << i << " same "
                                                << pt[j][0] << " " << pt[j][1] << endl;
#endif
                                }
                        }
                }
                max_count = 0;
                for (int i = 0; i < pt_r_sum; i ++)
                {
#ifdef DEBUG
                        cout << "pt " << i << " cnt " << same_count[i] << endl;
#endif
                        if (same_count[i] > max_count)
                                max_count = same_count[i];
                }
                printf("%d\n", max_count);
        }
        return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值