zoukankan      html  css  js  c++  java
  • 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有多少个,加起来就行了。Σ( ° △ °|||)︴

     1 #include <cstdio>
     2 #include <cmath>
     3 #include <cstring>
     4 #include <ctime>
     5 #include <iostream>
     6 #include <algorithm>
     7 #include <set>
     8 #include <vector>
     9 #include <sstream>
    10 #include <queue>
    11 #include <typeinfo>
    12 #include <fstream>
    13 #include <map>
    14 #include <stack>
    15 using namespace std;
    16 const int maxn=200010;
    17 int up[maxn],down[maxn],x;
    18 int main()
    19 {
    20     int n,m,s,a,cnt1=0,cnt2=0;
    21     scanf("%d",&n);
    22     for(int i=1;i<=n;i++){
    23         scanf("%d%d",&s,&a);
    24         if(s>0) up[cnt1++]=a;
    25         else down[cnt2++]=-a;
    26     }
    27     sort(up,up+cnt1);
    28     sort(down,down+cnt2);
    29     scanf("%d",&m);
    30     for(int i=1;i<=m;i++){
    31         scanf("%d",&x);
    32         int ans1=upper_bound(up,up+cnt1,x)-up;
    33         int ans2=cnt2-(lower_bound(down,down+cnt2,x)-down);
    34         printf("%d
    ",ans1+ans2);
    35     }
    36     return 0;
    37 }
  • 相关阅读:
    32-Ubuntu-用户权限-03-修改文件权限
    31-Ubuntu-用户权限-02-ls输出信息介绍
    hdu2084 数塔
    hdu 1058 humble number
    HDU_2050 折线分割平面
    HDU_1030 Delta-wave 常数时间
    HDU_1021 Fibonacci Again 一些推论
    Gated Recurrent Unit(GRU)
    循环神经网络模型
    Bellman-Ford algorithm
  • 原文地址:https://www.cnblogs.com/RRirring/p/4665966.html
Copyright © 2011-2022 走看看