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

    直线上有N个点。点i的位置是Xi。从这N个点中选择若干个,给它们加上标记。对每一个点,其距离为R以内的区域里必须又带有标记的点(自己本身带有标记的点,可以认为与其距离为0的地方有一个带有标记的点)。在满足这个条件的情况下,希望能为尽可能少的点添加标记。请问至少要有多少点被加上标记?

    #include "iostream"
    #include "algorithm"
    using namespace std;
    
    const int MAX_N = 1000;
    int N=6, R=10;
    int X[MAX_N] = {1,7,15,20,30,50};
    
    void solve() {
    	sort(X,X+N);
    	int i = 0, ans = 0;
    	while (i<N)
    	{
    		//S为最左侧没有被覆盖的点
    		int S = X[i++];
    		//一直向右前进直到距离S的距离大于R的点
    		while (i<N && X[i]<=S+R)	i++;
    		//P是新加上标记的点的位置
    		int P = X[i-1];
    		//一直向右前进找到距离P的距离大于R的点
    		while (i<N && X[i]<=P+R)	i++;
    		ans++;
    	}
    	cout << ans << endl;
    }
    
    int main() {
    	solve();
    	system("pause");
    	return 0;
    }#include "iostream"
    #include "algorithm"
    using namespace std;
    
    const int MAX_N = 1000;
    int N=6, R=10;
    int X[MAX_N] = {1,7,15,20,30,50};
    
    void solve() {
    	sort(X,X+N);
    	int i = 0, ans = 0;
    	while (i<N)
    	{
    		//S为最左侧没有被覆盖的点
    		int S = X[i++];
    		//一直向右前进直到距离S的距离大于R的点
    		while (i<N && X[i]<=S+R)	i++;
    		//P是新加上标记的点的位置
    		int P = X[i-1];
    		//一直向右前进找到距离P的距离大于R的点
    		while (i<N && X[i]<=P+R)	i++;
    		ans++;
    	}
    	cout << ans << endl;
    }
    
    int main() {
    	solve();
    	system("pause");
    	return 0;
    }
    

     

  • 相关阅读:
    Coursera Machine Learning : Regression 简单回归
    KVM 虚拟化 初体验
    Spark RDD aggregateByKey
    Spark standalone HA
    Coursera 机器学习课程 机器学习基础:案例研究 证书
    dos学习笔记
    【???】 ???? 题解
    【ural 1223】 Chernobyl' Eagle on a Roof 题解
    由《鹰蛋》一题引发的思考
    【CF1408A】 Circle Coloring 题解
  • 原文地址:https://www.cnblogs.com/sky-z/p/5595996.html
Copyright © 2011-2022 走看看