lightoj 1016

来源:互联网 发布:阿里云 ddos 黑洞 编辑:程序博客网 时间:2024/05/08 12:42

水题,排个序直接搞。

#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int MAXN = 50010;int y[MAXN];int main(){    int t, x, n, w, CASE(0);    scanf("%d", &t);    while(t--){        scanf("%d%d", &n, &w);        for(int i = 0;i < n;i ++) scanf("%d%d", &x, y+i);        sort(y, y+n);        int ans(0);        for(int i = 0;i < n;i ++){            ans ++;            for(int j = i; y[i]-y[j] <= w; i ++);            i--;        }        printf("Case %d: %d\n", ++CASE, ans);    }    return 0;}


0 0
原创粉丝点击