题意:给定函数: f(x) = θ(s1x - a1) + θ(s2x - a2) + ... + θ(snx - an), where si =  ± 1. Calculate its values for argument values x1, x2, ..., xm.其中      然后输入一系列si,ai,输出给定的f(xi)的值。

分析:之前一直没想到去化一化,其实就是分s=1和s=-1两种情况,然后分别算出θ(snx - an)==1有多少个,加起来就行了。Σ( ° △ °|||)︴

 #include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
using namespace std;
const int maxn=;
int up[maxn],down[maxn],x;
int main()
{
int n,m,s,a,cnt1=,cnt2=;
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d%d",&s,&a);
if(s>) up[cnt1++]=a;
else down[cnt2++]=-a;
}
sort(up,up+cnt1);
sort(down,down+cnt2);
scanf("%d",&m);
for(int i=;i<=m;i++){
scanf("%d",&x);
int ans1=upper_bound(up,up+cnt1,x)-up;
int ans2=cnt2-(lower_bound(down,down+cnt2,x)-down);
printf("%d\n",ans1+ans2);
}
return ;
}

Gym 100187M-Heaviside Function的更多相关文章

  1. codeforces gym 100187M Heaviside Function

    //大概就是没想起来怎么做 解法:首先观察seitan方程,发现我们要找的是满足seitan(si*x-ai)=1的方程数,即si*x-ai>=0的方程数,因为si=1 or -1,于是分类讨论 ...

  2. CF Gym 100187M Heaviside Function(二分)

    题意:给你一个函数和一些系数,给你一堆询问,求函数值. 根据s的符号,分成两组讨论,函数值与比x小的系数数量有关,二分输出答案. #include<cstdio> #include< ...

  3. Codeforces Gym 100187M M. Heaviside Function two pointer

    M. Heaviside Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/ ...

  4. js 创建对象的方法

    <script> //1.字面量语法 var rectangle1 = {}; rectangle1.name="mindong"; rectangle1.width ...

  5. An Introduction to Measure Theory and Probability

    目录 Chapter 1 Measure spaces Chapter 2 Integration Chapter 3 Spaces of integrable functions Chapter 4 ...

  6. 通过百度echarts实现数据图表展示功能

    现在我们在工作中,在开发中都会或多或少的用到图表统计数据显示给用户.通过图表可以很直观的,直接的将数据呈现出来.这里我就介绍说一下利用百度开源的echarts图表技术实现的具体功能. 1.对于不太理解 ...

  7. 单位阶跃函数(Heaviside/unit step function)—— 化简分段函数

    注意,单位阶跃函数一种不连续函数. 1. 常见定义 最经典的定义来自于 Ramp function(斜坡函数,max{x,0})的微分形式: H(x)=ddxmax{x,0} 2. 化简分段函数 如对 ...

  8. Codeforce Gym 100015I Identity Checker 暴力

    Identity Checker 题目连接: http://codeforces.com/gym/100015/attachments Description You likely have seen ...

  9. Codeforces Gym 100610 Problem E. Explicit Formula 水题

    Problem E. Explicit Formula Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...

随机推荐

  1. [cocos2d]cocos2d 2.1与ios 6.0

    最近把xcode升级到4.5了,ios也编程6.0 mark一下需要修改的地方(针对于cocos2d 2.1版本),虽然都是warning,但是对于强迫症患者来说无法忍受啊~ 修改一 libs-Coc ...

  2. 转载:win7JDK环境配置

    [win7JDK环境配置] 网址:http://blog.sina.com.cn/s/blog_6a9df2330100ms9q.html 系统变量下: (1) 新建->变量名:JAVA_HOM ...

  3. Visual Studio统计有效代码行数

    在网上看到别人用的方法: 按CTRL+SHIFT+F (Find in files),勾上支持正则表达式,然后输入搜索内容: ^:b*[^:b#/]+.*$ 以上表达式的统计可做到:#开头和/开头或者 ...

  4. 用C#中的params关键字实现方法形参个数可变

    个人认为,提供params关键字以实现方法形参个数可变是C#语法的一大优点.在方法形参列表中,数组类型的参数前加params关键字,通常可以在调用方法时代码更加精练. 例如,下面代码: class P ...

  5. JAVA 文件下载乱码问题解决办法

    页面设置隐藏的iframe <iframe id='reqFrame' frameborder='0' style='display:none' allowtransparency='true' ...

  6. [pod install] error: cannot open .git/FETCH_HEAD: Permission denied

    pod installAnalyzing dependencies[!] Pod::Executable pull error: cannot open .git/FETCH_HEAD: Permis ...

  7. 计算几何(凸包模板):HDU 1392 Surround the Trees

    There are a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So a ...

  8. C#读取json数据介绍

    //using System.Web.Script.Serialization; JavaScriptSerializer serializer = new JavaScriptSerializer( ...

  9. Ajax初步实现页面局部内容更替

    类似于QQ邮箱的那种局部页面跳转,单页应用常用到,目前很多网页都是这种,但是弊端就是一次加载过多资源,首次加载卡出翔啊

  10. bzoj 2618 2618: [Cqoi2006]凸多边形(半平面交)

    2618: [Cqoi2006]凸多边形 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 656  Solved: 340[Submit][Status] ...