zoukankan      html  css  js  c++  java
  • POJ 3069 Saruman's Army (贪心)

    题意 : 这个题是说给你n个点,然后让你标记其中尽可能少的点,使得n个点都处于被标记点左右不超过R的区间内

    分析 :

     

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 1e3 + 10;
    int arr[maxn];
    int main(void)
    {
        int n, radius;
        while(~scanf("%d %d", &radius, &n) && !(radius==-1 && n==-1)){
            for(int i=1; i<=n; i++)
                scanf("%d", &arr[i]);
    
            sort(arr+1, arr+1+n);
    
            int ans = 0;
            int L = 1;
            for(int i=1; i<=n; i++){
                if(i == n) { ans++; break; }
                if(arr[i+1] - arr[L] > radius){
                    ans++;
                    for(int j=i; j<=n; j++){
                        if(arr[j+1] - arr[i] > radius){
                            L = j+1;
                            i = j;
                            break;
                        }
                        if(j == n){
                            i = n;
                            break;
                        }
                    }
                }
            }
            printf("%d
    ", ans);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    费用流入门
    网络最大流入门
    假期编程
    假期编程
    假期编程
    假期编程
    假期编程
    假期编程
    假期编程
    假期编程
  • 原文地址:https://www.cnblogs.com/qwertiLH/p/7931941.html
Copyright © 2011-2022 走看看