zoukankan      html  css  js  c++  java
  • 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
    ",s[i].dis,s[i].m,s[i].r,s[i].p);
    49 //    printf("finished
    ");
    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
    ",cnt);
    71     return 0;
    72 }
  • 相关阅读:
    ASP.NET 高级编程基础第十一篇—WebForm和Page类成员
    ASP.NET 高级编程基础第十三篇—验证控件
    C#委托和事件详解第二篇
    C#委托事件详解第三篇
    点击一个Button,来看Duwamish7的总体层次
    ELMAHError Logging Modules And Handlers
    [实例研究Duwamish]SystemFramework和Common命名空间
    关于Blog的一些周边资源
    .NET框架程序设计Globally Deployment Assembly全局部署程序集
    合并2个DataSet
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/5929674.html
Copyright © 2011-2022 走看看