learning

题目描述

FJ 决定用他现有牛群的数据来制造一个自动分类机;它能猜测牛身上有没有斑点。不幸的是,FJ 没有很好的数据。对于他的N 头牛,他所知道的仅仅只是牛的重量,以及这头牛是否有斑点。所有的牛都有不同的重量。为了猜测一个新牛C 是否有斑点,FJ 先找到现有牛群中和新牛重量最接近的牛C’。如果这头牛有斑点,FJ 猜测新牛也有斑点;反之,新牛没有斑点。如果有两头牛和新牛重量差相等,如果有其中之一的牛有斑点,那么FJ 就猜测新牛也有斑点。FJ 用他的这种测试机在新进的一群牛身上。这批牛重量(连续整数)都在A 和B 之间(包含A;B)。请帮助他决定其中有多少牛会被分类为有斑点。
注意新的机器只会从FJ 现有的牛群中比较数据,不会在他任何新牛中比较。还有注意,由于A 和B 都可能很大,你的程序如果从A B 一个一个的循环很可能跑不快。

输入

第一行三个数N; A;B,
接下一行N 行
每行要么是‘S W’,表示有一头有斑点的牛重量是W
要么是‘NS W’,表示有一头没有斑点的牛重量是W
数据保证任意两头牛的重量都不相等

输出

要你输出有多少牛会被看成是有斑点

样例输入

3 1 10
S 10
NS 4
S 1

样例输出

6

Explanation

1, 2, 7, 8, 9, and 10 有斑点

数据范围限制

• 对于40% 的数据,1 <= A <= B <= 10^7。
• 对于100% 的数据,N<= 5 * 10^4,1 <= A <= B <= 10^9,1 <= W <= 10^9。

思路:

快拍+两边MID判断

淼淼淼淼………………………………

代码:

var
        s,o,p,op,l,u,r,d,q:array[0..50000,1..2] of int64;
        f:array[1..50000] of char;
        w1:array[1..50000] of int64;
        c,oc:char;
        n,a,b,w,ow,i,j,k,x,y,z,ls:longint;
        ans:qword;
procedure qs(l,r:longint);
var
        i,j,mid:int64;
        ls1:char;
        ls2:int64;
begin
        i:=l;
        j:=r;
        mid:=w1[(l+r) div 2];
        while i<=j do
        begin
                while w1[j]>mid do
                begin
                        j:=j-1;
                end;
                while w1[i]<mid do
                begin
                        i:=i+1;
                end;
                if i<=j then
                begin
                        ls1:=f[i];
                        ls2:=w1[i];
                        f[i]:=f[j];
                        w1[i]:=w1[j];
                        f[j]:=ls1;
                        w1[j]:=ls2;
                        i:=i+1;
                        j:=j-1;
                end;
        end;
        if i<r then qs(i,r);
        if j>l then qs(l,j);
end;
procedure jia(l,r:longint);
begin
        if (l<=a)and(b<=r) then
        begin
                ans:=ans+b-a+1;
        end
        else
        begin
                if (l>=a)and(r<=b) then
                begin
                        ans:=ans+r-l+1;
                end
                else
                begin
                        if (r<a)or(l>b) then
                                exit;
                        if (l<=a)and(r<=b) then
                        begin
                                ans:=ans+r-a+1;
                        end
                        else
                        begin
                                ans:=ans+b-l+1;
                        end;
                end;
        end;
end;
begin
        assign(input,'learning.in');
    reset(input);
        assign(output,'learning.out');
    rewrite(output);

        readln(n,a,b);
        for i:=1 to n do
        begin
                read(c);
                if c='N' then
                begin
                        readln(c,w);
                        c:='N';
                        f[i]:=c;
                        w1[i]:=w;
                end
                else
                begin
                        readln(w);
                        f[i]:=c;
                        w1[i]:=w;
                end;
        end;
        qs(1,n);
        oc:=f[1];
        ow:=w1[1];
        if (f[1]='S')and(a<=w1[1]) then
        begin
                jia(a,w1[1]);
        end;
        for i:=2 to n do
        begin
                c:=f[i];
                if c='N' then
                begin
                        w:=w1[i];
                        if oc='S' then
                        begin
                                s[0,1]:=s[0,1]+1;
                                s[s[0,1],1]:=ow+1;
                                s[s[0,1],2]:=ow+(abs(w-ow)+1) div 2 + (abs(w-ow)+1) mod 2 -1;
                                jia(s[s[0,1],1],s[s[0,1],2]);
                        end;
                end
                else
                begin
                        w:=w1[i];
                        if oc='N' then
                        begin
                                s[0,1]:=s[0,1]+1;
                                s[s[0,1],1]:=ow+(abs(w-ow)+1) div 2;
                                s[s[0,1],2]:=w;
                                jia(s[s[0,1],1],s[s[0,1],2]);
                        end
                        else
                        begin
                                s[0,1]:=s[0,1]+1;
                                s[s[0,1],1]:=ow+1;
                                s[s[0,1],2]:=w;
                                jia(s[s[0,1],1],s[s[0,1],2]);
                        end;
                end;
                oc:=c;
                ow:=w;
        end;
        if (f[n]='S')and(b>w1[n]) then
        begin
                jia(n+1,b);
        end;
        writeln(ans);
end.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
About This Book, Leverage Python' s most powerful open-source libraries for deep learning, data wrangling, and data visualization, Learn effective strategies and best practices to improve and optimize machine learning systems and algorithms, Ask – and answer – tough questions of your data with robust statistical models, built for a range of datasets, Who This Book Is For, If you want to find out how to use Python to start answering critical questions of your data, pick up Python Machine Learning – whether you want to get started from scratch or want to extend your data science knowledge, this is an essential and unmissable resource., What You Will Learn, Explore how to use different machine learning models to ask different questions of your data, Learn how to build neural networks using Keras and Theano, Find out how to write clean and elegant Python code that will optimize the strength of your algorithms, Discover how to embed your machine learning model in a web application for increased accessibility, Predict continuous target outcomes using regression analysis, Uncover hidden patterns and structures in data with clustering, Organize data using effective pre-processing techniques, Get to grips with sentiment analysis to delve deeper into textual and social media data, Style and approach, Python Machine Learning connects the fundamental theoretical principles behind machine learning to their practical application in a way that focuses you on asking and answering the right questions. It walks you through the key elements of Python and its powerful machine learning libraries, while demonstrating how to get to grips with a range of statistical models.

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值