Vova and Train(CF-1066A)
Problem Description
Vova plans to go to the conference by train. Initially, the train is at the point 1 and the destination point of the path is the point L. The speed of the train is 1length unit per minute (i.e. at the first minute the train is at the point 1, at the second minute — at the point 2 and so on).
There are lanterns on the path. They are placed at the points with coordinates divisible by v (i.e. the first lantern is at the point v, the second is at the point 2 v and so on).
There is also exactly one standing train which occupies all the points from ll to rrinclusive.
Vova can see the lantern at the point p if pp is divisible by vv and there is no standing train at this position (p∉[l;r]). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.
Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to tt different conferences, so you should answer tt independent queries.
Input
The first line of the input contains one integer tt (1≤t≤104) — the number of queries.
Then tt lines follow. The ii-th line contains four integers Li,vi,li,ri (1≤L,v≤109, 1≤l≤r≤L) — destination point of the i-th path, the period of the lantern appearance and the segment occupied by the standing train.
Output
Print t lines. The i-th line should contain one integer — the answer for the i-th query.
Examples
Input
4
10 2 3 7
100 51 51 51
1234 1 100 199
1000000000 1 1 1000000000
Output
3
0
1134
0
————————————————————————————————————————————
題意:找 1~L 之間 v 的倍數的個數,在區間 [l,r] 之間的燈籠不能算
思路:注意最後 l/v-right/v+left/v
Source Program
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<ctime>
#include<vector>
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define N 200001
#define MOD 16007
#define E 1e-6
#define LL long long
using namespace std;
struct Node{
int x;
int step;
}q[N];
bool vis[N];
int dir[2]={-1,1};
int bfs(int n,int k){
int head=1,tail=1;
memset(vis,false,sizeof(vis));
vis[n]=1;
q[tail].x=n;
q[tail].step=0;
tail++;
while(head<tail){
int x=q[head].x;
int step=q[head].step;
if(x==k)
return step;
int nx;
for(int i=0;i<2;i++){
nx=x+dir[i];
if(nx>=0&&nx<N&&!vis[nx]){
vis[nx]=1;
q[tail].x=nx;
q[tail].step=step+1;
tail++;
}
}
nx=x*2;
if(nx>=0&&nx<N&&!vis[nx]){
vis[nx]=1;
q[tail].x=nx;
q[tail].step=step+1;
tail++;
}
head++;
}
return -1;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
int l,v,left,right;
scanf("%d%d%d%d",&l,&v,&left,&right);
int num=l/v-right/v+left/v;
if(left%v==0)
num--;
printf("%d\n",num);
}
return 0;
}
相關文章
- trainAI
- transformers、torch train demoORMAI
- tf.train.NewCheckpointReaderAI
- Codeforces 8A. Train and PeterAI
- train_test_split資料集分割AI
- 十圖詳解TensorFlow資料讀取機制tf.train.string_input_producer和tf.train.start_queue_runnersAI
- sklearn中train_test_splite的兩種用法AI
- 火車山谷Train Valley 2 中文遊戲攻略AI遊戲
- AttributeError: module‘ tensorflow_core._api.v2. train‘ has no attribute‘ AdamOptimizer‘ErrorAPIAI
- AI如何落地企業?UCloud三步走戰略:Build,Train,DeployAICloudUI
- yolov5 train報錯:TypeError: expected np.ndarray (got numpy.ndarray)YOLOAIErrorGo
- 成功解決PermissionError: [Errno 13] Permission denied: './data\\mnist\\train-images-idx3-ubyte'ErrorAI
- 訓練集(train set),驗證集(validation set)和測試集(test set)AI
- 每週開源點評:Kubernetes 網路、OpenStack Train 以及更多的行業趨勢AI行業
- 自動化kolla-ansible部署centos7.9+openstack-train-超融合單機架構CentOSAI架構
- 深度學習2.0-25.Train-Val-Test劃分檢測過擬合(交叉驗證)深度學習AI
- tf.gfile函式和gfile.MakeDirs(FLAGS.train_dir)函式的詳細說明函式AI
- 機器學習從入門到放棄:硬train一發手寫數字識別機器學習AI
- 機器學習策略篇:詳解訓練/開發/測試集劃分(Train/dev/test distributions)機器學習AIdev
- 深度學習 | sklearn的train_test_split()各函式引數含義解釋(超級全)深度學習AI函式
- python讀取資料集檔案下所有檔案並打亂劃分生成訓練測試txt檔案(生成train.txt、test.txt,順序隨機,預設比例8:2)PythonAI隨機