1. 程式人生 > 實用技巧 >B - Smartphone Addiction (模擬)

B - Smartphone Addiction (模擬)

B - Smartphone Addiction

簡單模擬題,幾個需要進行判斷的點:

①. 到第一個咖啡館時有沒有電

②. 在咖啡館充滿電後就不能再充電了

③. 從咖啡館回家後有沒有電

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int a[1010], b[1010];
 5 int main(){
 6     int n, m, t;
 7     cin >> n >> m >> t;
 8     for(int i = 1; i <= m; i ++)
 9         cin >> a[i] >> b[i];
10 if(n - a[1] <= 0){ 11 cout << "No" << endl; 12 return 0; 13 }else{ 14 int sum1 = 0; 15 sum1 = n - a[1]; 16 for(int i = 1; i <= m - 1; i ++){ 17 if(sum1 + b[i] - a[i] >= n) 18 sum1 = n; 19 else
20 sum1 += b[i] - a[i]; 21 22 if(sum1 - a[i + 1] + b[i] <= 0){ 23 cout << "No" << endl; 24 return 0; 25 }else 26 sum1 -= (a[i + 1] - b[i]); 27 } 28 if(sum1 + b[m] - a[m] >= n)
29 sum1 = n; 30 else 31 sum1 += b[m] - a[m]; 32 33 if(sum1 - (t - b[m]) <= 0){ 34 cout << "No" << endl; 35 return 0; 36 } 37 cout << "Yes" << endl; 38 } 39 40 41 return 0; 42 }