1. 程式人生 > >Codeforces Round #515 (Div. 3) A. Vova and Train

Codeforces Round #515 (Div. 3) A. Vova and Train

題解

題目大意 總長度為L 每到v的倍數位置都有一個路燈 現有一火車在[l, r]問在火車遮擋後 能看見多少個路燈

(r - 1) / v計算左側出現路燈數量L / v - r / v計算右側出現路燈數量

AC 程式碼

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;

int main()
{
#ifdef LOCAL
	//freopen("C:/input.txt", "r", stdin);
#endif
int T; cin >> T; while (T--) { int L, v, l, r; cin >> L >> v >> l >> r; int ans = (l - 1) / v + L / v - r / v; cout << ans << endl; } return 0; }