本文主要是介绍CF #284 (Div. 2) A.(模拟),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:http://codeforces.com/contest/499/problem/A
解题思路:
模拟过程,如果step + x < k[i].l,那么跳过x分钟;否则计数器 + k[i].l - step + (k[i].r - k[i].l),更新step为k[i].r + 1,同时i ++ 。
完整代码:
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;
typedef double DB;
typedef unsigned uint;
typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const DB EPS = 1e-9;
const DB OO = 1e20;
const DB PI = acos(-1.0); //M_PI;
const int maxn = 100001;
struct node
{int l , r;
}k[maxn];
int main()
{#ifdef DoubleQfreopen("in.txt","r",stdin);#endifstd::ios::sync_with_stdio(false);std::cin.tie(0);int n , x;while(cin >> n >> x){for(int i = 0 ; i < n ; i ++){cin >> k[i].l >> k[i].r;}int step = 1 , cnt = 0 , i = 0 ;while(step <= k[i].r){if(step + x <= k[i].l){step += x;}else{for(int j = step ; j <= k[i].r ; j ++)cnt ++;step = k[i].r + 1;i ++;}}cout << cnt << endl;}
}
这篇关于CF #284 (Div. 2) A.(模拟)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!