Contest Hunter #46 T1 磁力块 [花式暴力]

将所有石头按距离远近排序,将所有取到的时候扔进堆里维护最大磁力强度。

贪心,每次用强度最强的磁石尝试吸引地上的石头,扫完区间以后,这块石头就再也不会用到了。

在此基础上可以做些小优化,比如说优化未取石头区间的起始点,比如说如果强度更小的石头范围也更小就不用它,等等。

 

比标解分块跑得还要快2333333

分块解法链接:http://www.cnblogs.com/SilverNebula/p/5929668.html

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cmath>
 5 #include<queue>
 6 #define LL long long
 7 using namespace std;
 8 const int mxn=250010;
 9 int read(){
10     int x=0,f=1;char ch=getchar();
11     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
12     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
13     return x*f;
14 }
15 struct stone{
16     double dis;
17     int m,p,r;
18     bool got;
19 }s[mxn];
20 bool operator < (stone a,stone b){
21     return a.dis<b.dis;
22 }
23 struct tool{
24     int r,p;
25 }t[mxn];int cnt=0;
26 bool operator < (tool a,tool b){
27     return a.p<b.p;
28 }
29 priority_queue<tool>tp;
30 
31 double dist(double x1,double y1,double x2,double y2){
32     return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
33 }
34 int n;
35 int x,y;
36 int main(){
37 
38     int x0,y0;
39     scanf("%d%d%d%d%d",&x0,&y0,&t[0].p,&t[0].r,&n);
40     int i,j;
41     for(i=1;i<=n;i++){
42 //        scanf("%d%d%d%d%d",&x,&y,&s[i].m,&s[i].p,&s[i].r);
43         x=read();y=read();s[i].m=read();s[i].p=read();s[i].r=read();
44         s[i].dis=dist(x0,y0,x,y);
45         s[i].got=0;
46     }
47     sort(s+1,s+n+1);
48 //    for(i=1;i<=n;i++)printf("dis:%.3f  m:%d  r:%d p:%d\n",s[i].dis,s[i].m,s[i].r,s[i].p);
49 //    printf("finished\n");
50     tp.push(t[0]);
51     int hd=1;
52     int last=0;
53     int lastp=0;
54     while(!tp.empty()){
55         tool now=tp.top();tp.pop();
56         if(last>=now.r && lastp>=now.p)continue;
57         for(register int i=hd;i<=n && s[i].dis<=(double)now.r;i++){
58             if(!s[i].got && now.p>=s[i].m){
59                 cnt++;
60                 t[cnt].p=s[i].p;
61                 t[cnt].r=s[i].r;
62                 tp.push(t[cnt]);
63                 s[i].got=1;
64             }
65         }
66         while(s[hd].got)hd++;
67         last=now.r;
68         lastp=now.p;
69     }
70     printf("%d\n",cnt);
71     return 0;
72 }

 

转载于:https://www.cnblogs.com/SilverNebula/p/5929674.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值