题意:给定函数: 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. C++的try catch到底能防止什么错误?

    我在.h文件里定义:    LoadingWidget* w;然后.cpp文件里定义: void MyClass::ModifyTask(){    // w = new LoadingWidget( ...

  2. POJ_3666_Making_the_Grade_(动态规划)

    描述 http://poj.org/problem?id=3666 给一串坡的高度,现在要调整某些点,使整个坡单调不降或单调不升.调整的花费为原高度与先高度的差的绝对值,问最小花费(可单增可单降). ...

  3. spm_预处理实验记录

    参考:<SPM8 MANNUAL> Chapter 28 Auditory fMRI data

  4. Android Volley - volley StringRequest編碼問題

    有些時候這個類並不能很好的解決中文編碼問題 如果出現亂碼,就 要重寫該類的parseNetworkResponse 方法了. 繼承StringRequest,然後重寫parseNetworkRespo ...

  5. 关于.ToList(): LINQ to Entities does not recognize the method ‘xxx’ method, and this method cannot be translated into a store expression.

    LINQ to Entities works by translating LINQ queries to SQL queries, then executing the resulting quer ...

  6. 如何从PDF文件中提取矢量图

    很多时候我们需要PDF文档中的插图,直接用pdf中的复制或者截屏软件只能提取位图格式的图片,放大缩小难免失真. 本文教大家一种一种从pdf中提取矢量图的方法. 工具软件: 1 adobe acroba ...

  7. Shell如何传递字符串

    Shell 在写函数的时候,有时候需要传递字符串,由于字符串中有空格,所以结果总是不对,下面写个小例子,解决这个问题: #!/bin/bash # value init TT="adb sh ...

  8. 我的第一个JApplet-绘制笑脸

    初学Java,有很多东西都不太理解,但是我想以前初学C语言的时候也是不太懂,先参考着书上的程序写,然后用多了就自然而然的懂了! 下面来简单的介绍一下我自学的第一个Java小应用程序-绘制笑脸,下面是源 ...

  9. 使用pupperlabs yum repo

    http://docs.puppetlabs.com/guides/puppetlabs_package_repositories.html

  10. Linux程序设计(一)入门

    1. linux程序 Linux应用程序表现为两种特殊类型的文件:可执行文件和脚本文件. 可执行文件:是计算可以直接运行的程序,相当于windows的.exe文件. 脚本文件:一组指令的集合.这些指令 ...