Gym 100187M-Heaviside Function
题意:给定函数: 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的更多相关文章
- codeforces gym 100187M Heaviside Function
//大概就是没想起来怎么做 解法:首先观察seitan方程,发现我们要找的是满足seitan(si*x-ai)=1的方程数,即si*x-ai>=0的方程数,因为si=1 or -1,于是分类讨论 ...
- CF Gym 100187M Heaviside Function(二分)
题意:给你一个函数和一些系数,给你一堆询问,求函数值. 根据s的符号,分成两组讨论,函数值与比x小的系数数量有关,二分输出答案. #include<cstdio> #include< ...
- Codeforces Gym 100187M M. Heaviside Function two pointer
M. Heaviside Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/ ...
- js 创建对象的方法
<script> //1.字面量语法 var rectangle1 = {}; rectangle1.name="mindong"; rectangle1.width ...
- An Introduction to Measure Theory and Probability
目录 Chapter 1 Measure spaces Chapter 2 Integration Chapter 3 Spaces of integrable functions Chapter 4 ...
- 通过百度echarts实现数据图表展示功能
现在我们在工作中,在开发中都会或多或少的用到图表统计数据显示给用户.通过图表可以很直观的,直接的将数据呈现出来.这里我就介绍说一下利用百度开源的echarts图表技术实现的具体功能. 1.对于不太理解 ...
- 单位阶跃函数(Heaviside/unit step function)—— 化简分段函数
注意,单位阶跃函数一种不连续函数. 1. 常见定义 最经典的定义来自于 Ramp function(斜坡函数,max{x,0})的微分形式: H(x)=ddxmax{x,0} 2. 化简分段函数 如对 ...
- Codeforce Gym 100015I Identity Checker 暴力
Identity Checker 题目连接: http://codeforces.com/gym/100015/attachments Description You likely have seen ...
- Codeforces Gym 100610 Problem E. Explicit Formula 水题
Problem E. Explicit Formula Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
随机推荐
- HTML标签与表格
1.打开DREAMWEAVER,新建HTML,如下图: 2.body的属性: bgcolor 页面背景色 background 背景壁纸.图片 text 文字颜色 topmargin 上边 ...
- u-boot使用
下载与烧写 使用U-boot将映像文件烧写到板上的Flash,一般步骤是: (1)通过网络.串口.U盘.SD卡等方式将文件传输到SDRAM: (2)使用Nand Flash或Nor Flash相关的读 ...
- ☀【移动】Google Maps JavaScript API v3
Google Maps JavaScript API v3https://developers.google.com/maps/documentation/javascript/tutorial?hl ...
- 【http】client
server.js var qs = require('querystring') require('http').createServer(function(req, res) { var body ...
- android 中对apache httpclient及httpurlconnection的选择
在官方blog中,android工程师谈到了如何去选择apache client和httpurlconnection的问题: 原文见http://android-developers.blogspot ...
- [PeterDLax著泛函分析习题参考解答]第1章 线性空间
1. 证明定理 1. 2. 验证上述结论. 3. 证明定理 3. 4. 证明定理 4. 证明: 由 $$\bex x=\sum_{k=1}^{n-1}a_k\cdot \sum_{j=1}^{n-1} ...
- __str__
__str__是被print函数调用的,一般都是return一个什么东西.这个东西应该是以字符串的形式表现的.如果不是要用str()函数转换.当你打印一个类的时候,那么print首先调用的就是类里面的 ...
- 破解安装 SecureCRT 7.0.2 for mac完美破解版,mac secureCRT , apple secureCRT
mac secureCRT , apple secureCRT 下载地址:http://download.csdn.net/detail/guolichun/7733069 破解安装 SecureC ...
- C# TypeConverter 数据转换
提供一种将值的类型转换为其他类型以及访问标准值和子属性的统一方法. 自定义Converter: public class GenericListTypeConverter<T> : Typ ...
- [SAM4N学习笔记]SAM4N工程模板搭建
一.需要安装的软件: 因为笔者是使用MDK-ARM开发的版本是4.72,所以需要安装这个工具,具体在哪里下载自行放狗或问度娘.除了这个重要工具以为,还需要安装Atmel官方的Atmel Studio, ...