[NEERC2014] Knockout Racing
题面翻译
题目简述
有NNN辆车在很长的直线赛道(可看作数轴)上行驶,每辆车在区间[Ai,Bi][A_i,B_i][Ai,Bi]间往返行驶,速度相同,有MMM个询问,每次询问一个区间[Xi,Yi][X_i,Y_i][Xi,Yi]在TiT_iTi时刻有多少辆车
题目描述
The races became more popular than ever at Pandora planet. But these races are quite unusual. There are nnn cars participating in a race on the long straight track. Each car moves with a speed of 111 meter per second. Track has coordinates in meters.
The car number iii moves between two points on the track with coordinates aia_{i}ai and bib_{i}bi starting at the second 000 in the point ai.a_{i}.ai. The car moves from aia_{i}ai to bi,b_{i},bi, then from bib_{i}bi to ai,a_{i},ai, then from aia_{i}ai to bib_{i}bi again, and so on.
Handsome Mike wants to knock some cars out of the race using dynamite. Thus he has mmm questions. The question number jjj is: what is the number of cars in the coordinates between xjx_{j}xj and yjy_{j}yj inclusive after tjt_{j}tj seconds from the start?
Your task is to answer Mike’s questions.
输入格式
The first line of the input file contains two integers nnn and m(1≤n,m≤1000)m (1 \le n , m \le 1000)m(1≤n,m≤1000) – the number of cars in the race and the number of questions.
Each of the following nnn lines contains a description of the car: two integers aia_{i}ai and bi(0≤ai,bi≤109,ai≠bi)b_{i} (0 \le a_{i}, b_{i} \le 10^{9}, a_{i} ≠ b_{i})bi(0≤ai,bi≤109,ai=bi) – the coordinates of the two points between which the car iii moves.
Each of the following mmm lines contains a description of the question: three integers xj,yjx_{j} , y_{j}xj,yj , and tj(0≤xj≤yj≤109,0≤tj≤109)t_{j} (0 \le x_{j} \le y_{j} \le 10^{9}, 0 \le t_{j} \le 10^{9})tj(0≤xj≤yj≤109,0≤tj≤109) – the coordinate range and the time for the question jjj .
输出格式
Write mmm lines to the output file. Each line must contain one integer – the answer to the corresponding question in order they are given in the input file.
样例 #1
样例输入 #1
5 5
0 1
0 2
2 3
3 5
4 5
0 5 0
0 1 2
0 2 1
2 5 2
2 5 3
样例输出 #1
5
1
2
4
3
提示
Time limit: 1 s, Memory limit: 256 MB.
C++实现
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=1010,M=1010;
struct node{
ll a,b;
}e[N];
struct qu{
ll x,y,t;
}ques[M];
ll n,m;
int main(){
cin>>n>>m;
for(ll i=1;i<=n;i++){
cin>>e[i].a>>e[i].b;
}
for(ll i=1;i<=m;i++){
cin>>ques[i].x>>ques[i].y>>ques[i].t;
ll ans=0;
for(ll j=1;j<=n;j++){
ll difference=e[j].b-e[j].a;
ll to_back=ques[i].t/difference;
ll meter=e[j].a+(to_back%2==0?ques[i].t%difference:difference-ques[i].t%difference);
if(meter>=ques[i].x&&ques[i].y>=meter) {
ans++;
}
}
cout<<ans<<endl;
}
}

后续
接下来我会不断用C++来实现信奥比赛中的算法题、GESP考级编程题实现、白名单赛事考题实现,记录日常的编程生活、比赛心得,感兴趣的请关注,我后续将继续分享相关内容
用C++信奥P6995普及组提高 NEERC2014 Knockout Racing&spm=1001.2101.3001.5002&articleId=144871963&d=1&t=3&u=59fce1f6b9b244a7ade94cb892a71f70)
236

被折叠的 条评论
为什么被折叠?



