BZOJ3190: [JLOI2013]赛车

什么东西。。
各种奇奇怪怪的错误然后乱改过得(不要拿我的程序对拍
具体思想是先按v排序

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;

char c;
inline void read(int &a)
{
    a=0;do c=getchar();while(c<'0'||c>'9');
    while(c<='9'&&c>='0')a=(a<<3)+(a<<1)+c-'0',c=getchar();
}

struct CCar
{
    int v,g,no;
    double time;
    inline friend bool operator <(CCar a,CCar b){return a.v^b.v?a.v<b.v:a.g<b.g;}
}Car[100001];
int stack[10001];
int tot;
int n;
int L[100001];
inline bool cmp(int a,int b)
{
    return Car[a].no<Car[b].no;
}
int main()
{
    read(n);
    if(n==1)
    {
        ed:puts("1");putchar('1');return 0;
    }
    int i,j,k;
    double t;
    for(i=1;i<=n;i++)
       read(Car[i].g);
    for(i=1;i<=n;i++)
       read(Car[i].v),Car[i].no=i;
    sort(Car+1,Car+1+n);
    Car[1].time=0;
    stack[tot=1]=1;

    for(i=2;i<=n;i++)
    {
        if(Car[i].no==2373)
          i++,i--;
        while(tot>1)
         {
            t=(Car[stack[tot]].g-Car[i].g)/(0.0+Car[i].v-Car[stack[tot]].v);
            if(Car[stack[tot]].g==Car[i].g&&Car[i].v==Car[stack[tot]].v)
                break;
            else if(Car[i].v==Car[stack[tot]].v)
               t=Car[stack[tot]].time-1e-8;
            if
             ((Car[stack[tot]].time>t))//||(t<=0&&t>Car[stack[tot]].time))
             Car[i].time=t,tot--; 
            else break;
         }
         if(tot==1&&Car[i].g>Car[stack[tot]].g)
              Car[i].time=0,stack[tot]=i;
         else
          {
            t=(Car[stack[tot]].g-Car[i].g)/(0.0+Car[i].v-Car[stack[tot]].v);
            if(Car[stack[tot]].g==Car[i].g&&Car[i].v==Car[stack[tot]].v)
             t=Car[stack[tot]].time;
            else if(Car[i].v==Car[stack[tot]].v)
               t=Car[stack[tot]].time+1e-8;
            stack[++tot]=i;
            Car[i].time=t;
          }
    }
    int start;
    if(Car[stack[2]].time<=-(1<<29)||Car[stack[2]].time>=0||tot==1)start=1;
    else start=2;
    printf("%d\n",tot-start+1);
    for(i=1;i<=tot;i++)L[i]=stack[i];
    sort(L+start,L+tot+1,cmp);
    for(i=start;i<tot;i++)
      printf("%d ",Car[L[i]].no);
    printf("%d",Car[L[tot]].no);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值