• codevs 1199


    倍增做得不多,做起来比较吃力。。。

    各种STL都不会,用到的时候再去学,这次学了set。。(P党哭晕在厕所)

    然后思路就比较清晰了,然而脑子很乱,在写的时候很多细节参考了标程,写长代码就是不顺利啊。。。

    这几天懒了。。要多注意

      1 #include<bits/stdc++.h>
      2 #define inc(i,l,r) for(i=l;i<=r;i++)
      3 #define dec(i,l,r) for(i=l;i>=r;i--)
      4 #define mem(a) memset(a,0,sizeof(a))
      5 #define inf 1e12
      6 #define ll long long
      7 #define succ(x) (1<<x)
      8 #define NM 100000+5
      9 using namespace std;
     10 int read(){
     11     int x=0,f=1;char ch=getchar();
     12     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
     13     while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
     14     return x*f;
     15 }
     16 struct tmp{
     17     ll t;
     18     int num;
     19 }a[NM];
     20 set<tmp>s;
     21 set<tmp>::iterator it;
     22 bool operator<(const tmp&x,const tmp&y){
     23     return x.t<y.t;
     24 }
     25 int n,m,pos[NM][2],i,j,p=20,ans;
     26 ll next[NM][2],xa,xb,_x,f[NM][25],d[NM][25],g[NM][25],ansa,ansb;
     27 void update(tmp t){
     28     if(abs(t.t-a[i].t)<next[i][0]||
     29     (abs(t.t-a[i].t)==next[i][0]&&a[pos[i][0]].t>t.t)){
     30         next[i][1]=next[i][0];
     31         pos[i][1]=pos[i][0];
     32         next[i][0]=abs(a[i].t-t.t);
     33         pos[i][0]=t.num;
     34     }
     35     else
     36     if(abs(t.t-a[i].t)<next[i][1]||
     37     (abs(t.t-a[i].t)==next[i][1]&&a[pos[i][1]].t>t.t)){
     38         next[i][1]=abs(a[i].t-t.t);
     39         pos[i][1]=t.num;
     40     }
     41 }
     42 void work(int x,int _t){
     43     int i;
     44     dec(i,p,0)
     45     if(d[x][i]+f[x][i]<=_t&&g[x][i]){
     46         _t-=d[x][i]+f[x][i];
     47         xa+=f[x][i];xb+=d[x][i];
     48         x=g[x][i];
     49     }
     50     if(next[x][1]<=_t&&pos[x][1])xa+=next[x][1];
     51 }
     52 int main(){
     53     n=read();
     54     inc(i,1,n)a[i].t=read(),a[i].num=i;
     55     dec(i,n,1){
     56         next[i][0]=inf;next[i][1]=inf;
     57         s.insert(a[i]);
     58         it=s.find(a[i]);
     59         if(it!=s.begin()){
     60             it--;
     61             update(*it);
     62             if(it!=s.begin()){
     63                 it--;
     64                 update(*it);
     65                 it++;
     66             }
     67             it++;
     68         }
     69         if((++it)!=s.end()){
     70             update(*it);
     71             if((++it)!=s.end()){
     72                 update(*it);
     73                 it--;
     74             }
     75             it--;
     76         }
     77         if(next[i][0]==inf)next[i][0]=next[i][1]=0;
     78         if(next[i][1]==inf)next[i][1];
     79     }
     80     inc(i,1,n){
     81         g[i][0]=pos[pos[i][1]][0];
     82         f[i][0]=next[i][1];
     83         d[i][0]=next[pos[i][1]][0];
     84     }
     85     inc(j,1,p)
     86     inc(i,1,n)
     87     g[i][j]=g[g[i][j-1]][j-1];
     88     inc(j,1,p)
     89     inc(i,1,n){
     90         d[i][j]=d[i][j-1]+d[g[i][j-1]][j-1];
     91         f[i][j]=f[i][j-1]+f[g[i][j-1]][j-1];
     92     }
     93     _x=read();ansa=inf;ansb=1;
     94     inc(i,1,n){
     95         xa=xb=0;
     96         work(i,_x);
     97         if(xb!=0&&xa*ansb<ansa*xb){
     98             ans=i;ansa=xa;ansb=xb;
     99         }
    100     }
    101     printf("%d
    ",ans);
    102     m=read();
    103     while(m--){
    104         xa=xb=0;
    105         i=read();_x=read();
    106         work(i,_x);
    107         printf("%lld %lld
    ",xa,xb);
    108     }
    109     return 0;
    110 }
    View Code
  • 相关阅读:
    (转)十分钟搞定CSS选择器
    (转)我所理解的OOP——UML六种关系
    闲话:你今天OO了吗?
    oledb方式读取excel文件
    (转)asp.net 高质量缩略图
    (转载)重温SQL——行转列,列转行
    第九讲,资源表解析
    第八讲,TLS表(线程局部存储)
    第七讲,重定位表
    第六讲,导出表
  • 原文地址:https://www.cnblogs.com/onlyRP/p/4895927.html
Copyright © 2020-2023  润新知