Codeforces Round #515 (Div. 3) A(思維)
題意:找1~L之間 v 的倍數的個數,在區間[l,r]之間的不能算
思路:1到n之間v的倍數個數為n/v向下取整,因為是閉區間,所以區間裡v的倍數個數為r/v-(l-1)/v,l為什麼要減一?因為l-1/v是1到l-1中v的倍數個數。
#include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define ll long long const int maxn=200005; const double eps=1e-8; const double PI = acos(-1.0); #define lowbit(x) (x&(-x)) ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); int n; cin>>n; while(n--) { int L,v,l,r; cin>>L>>v>>l>>r; cout<<L/v-(r/v-(l-1)/v)<<endl; } return 0; }
相關推薦
Codeforces Round #515 (Div. 3) A(思維)
題意:找1~L之間 v 的倍數的個數,在區間[l,r]之間的不能算 思路:1到n之間v的倍數個數為n/v向下取整,因為是閉區間,所以區間裡v的倍數個數為r/v-(l-1)/v,l為什麼要減一?因為l-1/v是1到l-1中v的倍數個數。 #include<bits/stdc++.h>
Codeforces Round #515 (Div. 3) B(模擬)
題意:在數列中值為1的位置有1個加熱器,它能覆蓋它的左邊第 r-1 位置到它的右邊 r-1 的位置,問最少多少個加熱器能覆蓋整個區間。 思路:模擬這個過程,首先now=1,然後遍歷所有位置,找到最遠的滿足now這個位置能加熱的點,再另now=i+r-1+1,之所以要+1,是因為,i+r-1這個位
Codeforces Round #515 (Div. 3) D(模擬)
題意:有m個箱子,每個箱子容量為k,問你最多能裝多少個物品,你只能依次捨棄前面的,後面的必須全部裝完。 思路:題目意思是裝過東西的箱子如果你又拿了一個箱子,那麼以前的箱子就裝不了了,即使還能裝。所以倒著遍歷物品,模擬一下就行了。 #include<bits/stdc++.h> u
Codeforces Round #515 (Div. 3) C (模擬)
題意: 三種操作: L id ,將編號為id的書放在最左邊; R id,將編號為id的書放在最右邊; ?id,查詢編號為id的書左右兩邊哪一邊的數量最小,輸出最小值。 思路: 用l和r表示下一個左或右的位置,然後模擬就行了。 #include<bits/stdc++
Codeforces Round #501 (Div. 3) A(暴力)
A. Points in Segments time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output
Codeforces Round #515 (Div. 3) E(模擬+字首和)
題意:a和b是兩個01字串,現要計算a&b+a&b>>1+a&b>>2+……(直到b=0) 思路: 因為a和b的長度不確定,所以給短的那個在前面補上0,因為b每一次往右移,所以可以計算b的每一位上的貢獻,這個貢獻就是這一位及前面一共有多少1,為什麼
Codeforces Round #515 (Div. 3)A. Vova and Train【水題】
A. Vova and Train time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vova
Codeforces Round #515 (Div. 3) A. Vova and Train
題解 題目大意 總長度為L 每到v的倍數位置都有一個路燈 現有一火車在[l, r]問在火車遮擋後 能看見多少個路燈 (r - 1) / v計算左側出現路燈數量L / v - r / v計算右側出現路燈數量 AC 程式碼 #include <stdio.h&
Codeforces Round #515 (Div. 3) A、B、C、D
A. Vova and Train time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vo
Codeforces Round #515 (Div. 3) A、B、C、D
A. Vova and Train time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vova
Codeforces Round #501 (Div. 3) D(暴力)
D. Walking Between Houses time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard o
Codeforces Round #501 (Div. 3) C(貪心)
C. Songs Compression time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output
Codeforces Round #515 (Div. 3)C. Books Queries【模擬,思維】
C. Books Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You h
Codeforces Round #515 (Div. 3)B. Heaters【模擬,思維】
B. Heaters time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vova's house
B. Heaters ( Codeforces Round #515 (Div. 3) )
題解:對於每個點 i 來說,從 j = i + r - 1 開始往前找,如果找到一個 a [ j ] 是 1 ,那麼就把它選上,但是我們需要判斷交界處,也就是如果前面選的那個可以讓這個點變溫暖,就不用再選多餘的了。這樣就記錄一下前一個 last ,要滿足 j > last。找到之後
A. Vova and Train ( Codeforces Round #515 (Div. 3) )
題意:一條 L 長的路,一列車長在這條路的 l 到 r 之間,只有在 v 倍數時有燈,但是在 l 到 r 之間的燈是看不見的,問最大看見的燈的個數? 題解:L / v 表示總共的燈的個數, r / v 、( l - 1 ) / v 表示前 r 、( l - 1 ) 長的路有多少燈,
Codeforces Round #527 (Div. 3)D2(棧,思維)
括號匹配 font amp hack style def sca emp empty #include<bits/stdc++.h>using namespace std;int a[200007];stack<int>s;int main(){
Codeforces Round #486 (Div. 3) A. Diverse Team
pre table ngs href AI pop ons NPU school Codeforces Round #486 (Div. 3) A. Diverse Team 題目連接: http://codeforces.com/contest/988/problem/
Codeforces Round #501 (Div. 3) A Points in Segments
segments ble round show 默認 () for using pre 翻譯 現在有一個數軸,上面會有\(M\)個點,標號為\(1\)到\(N\),現在給你在數軸上的條\(N\)線段的起始與終止的點,問哪幾個點沒有被這樣線段覆蓋,從小到大輸出。 思路 簽到題
Codeforces Round #515 (Div. 3)
mat queue min src rain d+ round () 圖片 Codeforces Round #515 (Div. 3) 1 #include<bits/stdc++.h> 2 #include<iostream> 3 #i