您的位置:首页 > 编程语言 > Go语言

ZOJ Problem Set - 3197 Google Book

2013-05-07 18:16 260 查看
#include <utility>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <bitset>
#include <map>
#include <iterator>
using namespace std;
#define clr(a,v) memset(a,v,sizeof(a))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
const int INF = 0x7f7f7f7f;
const int maxn = 211111;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 777777777;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
pii p[maxn];
int main() {
ios::sync_with_stdio(false);
int T, i, n;
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
for (i = 0; i < n; ++i) {
scanf("%d%d", &p[i].first, &p[i].second);
}
if (n == 1) {
puts("1");
continue;
}
sort(p, p + n);
int ma, ans = 0, now = 0;
i = 0;
while (now < n && i < n) {
ma = 0;
while (p[i].first <= now + 1 && i < n) {
ma = max(ma, p[i].second);
++i;
}
now = ma;
++ans;
}
printf("%d\n", ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: