pku2437.cpp

来自「这是ACM 方面的资料 是PKU的 北京大学的出来的」· C++ 代码 · 共 53 行

CPP
53
字号
#include <stdio.h>
#include <algorithm>
#define size 10001
using namespace std;

typedef struct 
{
	int s, e;
} Mud;

bool cp(Mud a, Mud b)
{
	return a.s < b.s;
}

int Max(int x, int y)
{
	return x > y ? x : y;
}

Mud m[size];
int N, L;



int main()
{
	int i, s, e, ans, add;
	while (scanf("%d %d", &N, &L) != -1)
	{
		for (i = 0; i < N; i++)
		{
			scanf("%d %d", &m[i].s, &m[i].e);
		}
		sort(m, m + N, cp);
		s = m[0].s;
		for (i = 0, ans = 0; i < N; i++)
		{
			s = Max(s, m[i].s);
			if (s >= m[i].e)
			{
				continue;
			}
			add = (m[i].e - s - 1 + L) / L;
			ans += add;
			s += add * L;
		}
		printf("%d\n", ans);
	}
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?