【usaco】learning
来源:互联网 发布:淘宝显示历史价格 编辑:程序博客网 时间:2024/05/22 16:03
题目描述
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。
TJ
先按重量排个序,再在每相邻两只牛中间取个mid,再判断各种情况即可。
BC
uses math;var n,l,r,i,j,ans,mid:longint; a:array[1..100000]of longint; f:array[1..100000]of boolean; c,ch:char;procedure kp(l,r:longint);var i,j,mid,t:longint; t1:boolean;begin i:=l; j:=r; mid:=a[(l+r)div 2]; repeat while a[i]<mid do inc(i); while a[j]>mid do dec(j); if i<=j then begin t:=a[i]; a[i]:=a[j]; a[j]:=t; t1:=f[i]; f[i]:=f[j]; f[j]:=t1; inc(i); dec(j); end; until i>j; if l<j then kp(l,j); if i<r then kp(i,r);end;begin assign(input,'learning.in');reset(input); assign(output,'learning.out');rewrite(output); readln(n,l,r); for i:=1 to n do begin read(c,ch); readln(a[i]); if c='S' then f[i]:=true; end; kp(1,n); if (l<a[1])and(f[1]) then ans:=ans+a[1]-l; if (r>a[n])and(f[n]) then ans:=ans+r-a[n]; for i:=1 to n-1 do begin if r<a[i] then break; if l>=a[i+1] then continue; mid:=(a[i]+a[i+1])div 2; if(a[i]+a[i+1])mod 2=1 then begin if f[i] then if min(r,mid)-max(l,a[i])+1>0 then ans:=ans+min(mid,r)-max(a[i],l)+1; if f[i+1] then if min(a[i+1]-1,r)-max(mid+1,l)+1>0 then ans:=ans+min(r,a[i+1]-1)-max(l,mid+1)+1 end else begin if f[i] then if min(r,mid-1)-max(l,a[i])+1>0 then ans:=ans+min(mid-1,r)-max(a[i],l)+1; if f[i+1] then if min(a[i+1]-1,r)-max(mid+1,l)+1>0 then ans:=ans+min(r,a[i+1]-1)-max(l,mid+1)+1; if (f[i])or(f[i+1]) then if(mid>=l)and(mid<=r)then inc(ans); end; end; if (f[n])and(a[n]<=r) then inc(ans); writeln(ans); close(input);close(output);end.
- 【usaco】learning
- USACO
- USACO
- usaco
- USACO
- USACO
- USACO
- USACO
- USACO
- USACO
- USACO
- USACO
- USACO
- USACO
- USACO
- USACO
- USACO
- USACO
- HPUoj 1415: 小ho的01串 [字符串]
- ffmpeg + nginx + rtmp 搭建本地直播服务器
- 利比亚行动
- Populating Next Right Pointers in Each Node问题及解法
- SSL P2574 Closest
- 【usaco】learning
- could not read data from '/Users/xxxx/xxxx/Info.plist': The file “Info.plist” couldn’t be opened
- bzoj 2820 莫比乌斯反演
- 逻辑卷管理pv,vg,lv
- 开发人员必知的5种开源框架
- mysql外键的优缺点和使用
- C语言存储空间布局以及static解析
- SSL P2575 给出字符串
- java基础第八天 多态