• BZOJ3190 赛车


    BZOJ3190 赛车

    题目传送门

    题解

    这题有点像1007的那道题,我们可以把赛车的速度转化成斜率,把赛车的初始位置转化成与(y)轴的交点,然后就和1007差不多了。不过要注意的是计算两个直线交点的时候,如果交点在(x)轴的负半轴,是不能直接拿来比较的,因为规定了时间为正。

    code

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    bool Finish_read;
    template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
    template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
    template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('
    ');}
    template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
    /*================Header Template==============*/
    #define PAUSE printf("Press Enter key to continue..."); fgetc(stdin);
    int n;
    struct car {
        int v,x,idx;
        double cro;
        bool operator < (const car &rhs) const {
        	return v==rhs.v?x<rhs.x:v<rhs.v;
        }
    }p[10010];
    int st[10010],top,vis[10010];
    /*==================Define Area================*/
    int main() {
        scanf("%d",&n);
        for(int i=1;i<=n;i++) read(p[i].x);
        for(int i=1;i<=n;i++) read(p[i].v),p[i].idx=i;
        sort(p+1,p+n+1);
        top=0;
        for(int i=1;i<=n;i++) {
            while(top) {
                if(p[i].x>p[st[top]].x) top--;
                else if(1.0*p[st[top]].x-p[i].x<p[st[top]].cro*(p[i].v-p[st[top]].v)) top--;
                else break;
            }
            if(top&&p[i].v>p[st[top]].v) p[i].cro=(double)(p[st[top]].x-p[i].x)/(p[i].v-p[st[top]].v);
            st[++top]=i;
        }
        printf("%d
    ",top);
        for(int i=1;i<=top;i++) vis[p[st[i]].idx]=1;
        int tot=0;
        for(int i=1;i<=n;i++) {
            if(vis[i]) {
                printf("%d",i);
                tot++;
                if(tot!=top) printf(" ");
            }
        }
        return 0;
    }
    
    「我不敢下苦功琢磨自己,怕终于知道自己并非珠玉;然而心中既存着一丝希冀,便又不肯甘心与瓦砾为伍。」
  • 相关阅读:
    中国内地、台湾、香港、澳门和国外DNS服务器地址列表
    科学、道法、哲学
    Away 3d 基本属性
    away 3d的一些问题
    Adobe Flash CC 2014 下载及破解
    html5结合flash实现视频文件在所有主流浏览器兼容播放
    Html wmode 标签参数详解
    九宫格
    flash/flex 编译错误汇总
    Redis在windows下安装过程(转)
  • 原文地址:https://www.cnblogs.com/Apocrypha/p/9434919.html
Copyright © 2020-2023  润新知