多线段覆盖 求覆盖区间的总和

/*
本算法的缺点 在于开的空间太大
分三类情况
线段 
(-10,-1)在负区间
(-10,10)双区间
(1,10)正区间
一下给出正区间的代码,已考虑小数
思路是
绝对正区间,覆盖到数轴 sz[]数组上    小数部分 用sum1 累计
*/

//#include "header.h"	//AnycodeX includes the header.h by default, needn‘t cancle the notation.
#include <bits/stdc++.h>
using namespace std;

#define   max   1000   //数轴长度
int  sz[2*max];        // 以max 位置为0  sz[0]为 -max  最后一个为max -1
#define   n   10       //测试线段条数  坐标入下(a[],b[])
double a[n]={1,3,5,7,9,11,13,15,17,19};
double b[n]={2,4,6,8,10,12,14,16,18,20};
  
double funadd(int s,int t)
{
 for(int i=s;i<=t;i++)   
  {
      sz[i]=1;
  }
}
double fun()
//数轴上置1   小数部分 用sum1 累计   sum2为整数部分求和
{   double sum=0;double sum1=0;double sum2=0;
    int  s=0;  int   t=0;
    for(int i=0;i<n;i++)
    {
         s=ceil(a[i]);t=floor(b[i]);
         sum1+=s-a[i];sum1+=b[i]-t;
         funadd(a[i],b[i]);
    }
    for(int i=0;i<2*max;i++)
    {
        if(sz[i]==1)sum2+=1;
    }
    sum=sum1+sum2;
    return sum;
}
int main()
{
    cout<<fun()<<endl; 
	cout << "Hello,C++ world of AnycodeX!" << endl;
	return 0;
}
时间: 2024-08-06 06:17:59

多线段覆盖 求覆盖区间的总和的相关文章

HDU 1542 Atlantis (线段树求矩阵覆盖面积)

题意:给你n个矩阵求覆盖面积. 思路:看了别人的结题报告 给定一个矩形的左下角坐标和右上角坐标分别为:(x1,y1).(x2,y2),对这样的一个矩形,我们构造两条线段,一条定位在x1,它在y坐标的区间是[y1,y2],并且给定一个cover域值为1:另一条线段定位在x2,区间一样是[y1,y2],给定它一个cover值为-1.根据这样的方法对每个矩形都构造两个线段,最后将所有的线段根据所定位的x从左到右进行排序 #include <iostream> #include <stdio.h

每次输出有几条线段能完全覆盖大于自己和hdu5372相反 树状数组或线段树 poj 2481 Cows

http://poj.org/problem?id=2481 Cows Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 14762   Accepted: 4886 Description Farmer John's cows have discovered that the clover growing along the ridge of the hill (which we can think of as a one

SPOJ 1043 Can you answer these queries I 求任意区间最大连续子段和 线段树

题目链接:点击打开链接 维护区间左起连续的最大和,右起连续的和.. #include <cstdio> #include <iostream> #include <algorithm> #include <string.h> #include <math.h> #include <vector> #include <map> using namespace std; #define N 50050 #define Lson

2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)

原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthesis sequence P=p1 p2…pn of length n and q questions. The i-th question is whether P remains balanced after pai and pbi  swapped. Note that questions ar

poj 3264 Balanced Lineup(线段数求区间最大最小值)

链接:http://poj.org/problem?id=3264 Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 32772   Accepted: 15421 Case Time Limit: 2000MS Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order.

当前插入的线段能完整覆盖存在的几条线段 树状数组 HDU 5372 Segment Game

http://acm.hdu.edu.cn/showproblem.php? pid=5372 Segment Game Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1284    Accepted Submission(s): 375 Problem Description Lillian is a clever girl so

POJ 3308 Paratroopers 最小点权覆盖 求最小割

不懂这个建模是什么原理,以后把二分图相关的东西看完再补上把= = #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <string> #include <iostream> #include <map> #include <cstdlib> #i

hdu 2665 可持久化线段树求区间第K大值(函数式线段树||主席树)

http://acm.hdu.edu.cn/showproblem.php?pid=2665 Problem Description Give you a sequence and ask you the kth big number of a inteval. Input The first line is the number of the test cases. For each test case, the first line contain two integer n and m (

HDU6447 YJJ&#39;s Salesman-2018CCPC网络赛-线段树求区间最值+离散化+dp

目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门 ?原题目描述在最下面. ?1e5个点,问从(0,0)走到(1e9,1e9)的最大收益. ?当你从(u-1,v-1)走到(u,v)时,你可以获得点(u,v)的权值. Solution: ?十分详细了. ?直接线段树区间最值.当然也可以树状数组,不能st表. ?\(dp[i] = max(query\_max(0,dp[i]-1,1)+val[i] ,