URAL 1105 Observers Coloring (构造法)

大体题意:

你在一个考场里做题,做题时间是t0~t1,有n (n <= 10000)个监考员,告诉你每一个监考员的入场时间和出场时间,现在你可以给一定量的监考员进行染色,使得考场内只有一个且染色监考员的总时间不小于 你做题时间的2/3,如果可行输出你染色的监考员,如果不可行输出0!  输入保证在你做题时间至少有一个监考员!

思路:

构造法!

知道了每个监考员的入场时间和出场时间,我们可以把它看成一个区间!  最后要求你保留一些区间,使得这个区间只有一个线段的数值总和不小于考试时间 的2/3.

我们把 去掉后没有空白的区间给删掉!这样最后给剩下的区间按照左端点进行排序,那么第i 个区间和第i+1个区间一定相交,并且第i 个区间一定不和第i+2个区间相交,否则第i+2个区间或者第i+1个区间可以被删掉!

这样我们选出所有奇数号的区间,这些区间一定都不相交,加起来如果大于2/3  输出!

如果上述情况不合适   那么我们在加偶数号区间,这些区间同样也都不想交 ,加起来如果大于2/3  输出!

如果还是不大于2/3

那么我们来看看全选的时间!

令a =  奇数号的区间时间总和!

令b = 偶数号区间的时间总和!

令T 为你的做题时间!

如果全选,那么剩下的“单独时间”  的总和为   T-a  + T - b(这个式子画个图就很明了了!)

现在a < 2*T/3    b  < 2*T/3

那么单独时间  为2*T - (a+b) >= 2*T/3

所以说 如果上述奇偶都不合理的情况下   全选一定有解! 所以此题一定有解!

因为是浮点数  注意好精度控制就好了!

贴个图 帮助大家理解:


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const double eps = 1e-10;
const double inf = 1e18;
const int maxn = 10000 + 7;
double t0,t1;
double dcmp(double a,double b){ // 比较浮点数大小
    if (fabs(a-b) < eps) return 0;
    if (a > b) return 1;
    return -1;
}
struct Node{
    double l,r;
    int id;
    void read() { scanf("%lf %lf",&l, &r);}
    bool operator < (const Node& rhs) const {
        return dcmp(l,rhs.l) == -1 || (dcmp(l,rhs.l) == 0 && dcmp(r,rhs.r) == 1);
    }
}p[maxn];
vector<int>ans;
int main(){
    while(~scanf("%lf %lf",&t0, &t1)){
        int n;
        ans.clear();
        double T = 2.0*(t1-t0)/3.0; // 总时间值!
        scanf("%d",&n);
        for (int i = 0; i < n; ++i){
            p[i].read();
            p[i].id = i+1;
        }
        sort(p,p+n);
        int len = 0;
        for (int i = 0; i < n; ++i){
            bool ok = 0;
            if (len == 0){
                ans.push_back(i);
                ok = 1;
                len++;
            }
            else if (len == 1){
                int id = ans[0];
                if (dcmp(p[i].l,p[id].l) == 1 && dcmp(p[i].r,p[id].r) == 1) ans.push_back(i),ok = 1,++len;
            }
            else {
                int laa = ans[len-2];
                int la = ans[len-1];
                if (dcmp(p[laa].r,p[i].l) == -1 && dcmp(p[i].r,p[la].r) == 1){
                    ans.push_back(i);
                    ++len;
                    ok = 1;
                }
                else if (dcmp(p[laa].r,p[i].l) != -1 && dcmp(p[i].r,p[la].r) != -1){
                    ans.pop_back();
                    ans.push_back(i);
                    ok = 1;
                }

            }
            if (!ok) continue;
            int cur = i;
            while(i+1 < n && dcmp(p[i+1].l,p[cur].l) == 0)++i;
        }
        double sum1 = 0,sum2 = 0; //  分奇数偶数的形式来讨论!
        int cnt1=0,cnt2=0;
        for (int i = 0; i < ans.size(); i+=2){
            int id = ans[i];
            sum1 += p[id].r - p[id].l;
            ++cnt1;
        }
        if (dcmp(sum1,T) != -1) {
            printf("%d\n",cnt1);
            for (int i = 0; i < ans.size(); i+=2){
                int id = ans[i];
                printf("%d\n",p[id].id);
            }
        }
        else {
            for (int i = 1; i < ans.size(); i+=2){
                int id = ans[i];
                sum2 += p[id].r - p[id].l;
                ++cnt2;
            }
            if (dcmp(sum2,T) != -1) {
                printf("%d\n",cnt2);
                for (int i = 1; i < ans.size(); i+=2){
                    int id = ans[i];
                    printf("%d\n",p[id].id);
                }
            }
            else {
                printf("%d\n",ans.size());
                for (int i = 0; i < ans.size(); ++i){
                    printf("%d\n",p[ans[i]].id);
                }
            }
        }
    }
    return 0;
}
/**
0 6
3
0 3
2 5 4 6
**/

1105. Observers Coloring

Time limit: 0.5 second
Memory limit: 64 MB
Nikifor told us that once he solved problem at mathematical tournament of S.Petersburg's secondary school N239 in 1994. Nikifor said that he solved a problem from the moment  T 0 to the moment  T 1. He remembers that  N observers appeared in the room. The  i-th observer entered the room at the moment t 0, i and went out at the moment  t 1, i. At every moment there was at least one observer in the room.
When the tournament was finished, Nikifor claimed that it is possible to color some observers, and the summary time when there was only one colored observer in the room is not less than 2/3 of the time when Nikifor solved problem.
You are to answer whether Nikifor right or not.

Input

The first line of input contains real numbers  T 0 and  T 1 ( T 0 <  T 1). The second line contains number N — number of observers ( N < 10000). Next  N lines contain real numbers  t 0, i and  t 1, i ( T 0 ≤ t 0, i <  t 1, i ≤  T 1).

Output

If Nikifor is not right output should contain the only number 0. If Nikifor is right you should write to the first line the quantity of colored observers, and next lines should contain their numbers. Do not write more than one number in a line. You may write these numbers in any order. If there are more than one solution exist you may find any of them.

Sample

input output
0.0 20.0
7
1.0 1.5
0.0 10.0
9.0 10.0
18.0 20.0
9.0 18.0
2.72 3.14
19.0 20.0
3
2
5
7
Problem Author: Dmitry Filimonenkov feat Igor Goldberg
Problem Source: Tetrahedron Team Contest May 2001


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
图像识别技术在病虫害检测中的应用是一个快速发展的领域,它结合了计算机视觉和机器学习算来自动识别和分类植物上的病虫害。以下是这一技术的一些关键步骤和组成部分: 1. **数据收集**:首先需要收集大量的植物图像数据,这些数据包括健康植物的图像以及受不同病虫害影响的植物图像。 2. **图像预处理**:对收集到的图像进行处理,以提高后续分析的准确性。这可能包括调整亮度、对比度、去噪、裁剪、缩放等。 3. **特征提取**:从图像中提取有助于识别病虫害的特征。这些特征可能包括颜色、纹理、形状、边缘等。 4. **模型训练**:使用机器学习算(如支持向量机、随机森林、卷积神经网络等)来训练模型。训练过程中,算会学习如何根据提取的特征来识别不同的病虫害。 5. **模型验证和测试**:在独立的测试集上验证模型的性能,以确保其准确性和泛化能力。 6. **部署和应用**:将训练好的模型部署到实际的病虫害检测系统中,可以是移动应用、网页服务或集成到智能农业设备中。 7. **实时监测**:在实际应用中,系统可以实时接收植物图像,并快速给出病虫害的检测结果。 8. **持续学习**:随着时间的推移,系统可以不断学习新的病虫害样本,以提高其识别能力。 9. **用户界面**:为了方便用户使用,通常会有一个用户友好的界面,显示检测结果,并提供进一步的指导或建议。 这项技术的优势在于它可以快速、准确地识别出病虫害,甚至在早期阶段就能发现问题,从而及时采取措施。此外,它还可以减少对化学农药的依赖,支持可持续农业发展。随着技术的不断进步,图像识别在病虫害检测中的应用将越来越广泛。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值