HCPC2014校赛训练赛 4 H.Car Race Game (3.16)

H.Car Race Game
Time Limit: 2000 MS Memory Limit: 32768 K
Total Submit: 93 (39 users) Total Accepted: 21 (21 users) Special Judge: No
Description

Bob is a game programming specialist. In his new car race game, there are some racers (n means the amount of racers (1<=n<=100000)). Racers start from someplace (xi means Starting point coordinate), and they possibly have different speed (V means speed). So it possibly takes place to overtake (include starting at the same point). Now he wants to calculate the maximal amount of overtaking.

Input

The first line of the input contains an integer n-determining the number of racers. Next, n lines follow. Each line contains two integers Xi and Vi. (Xi means the ith racer's Starting point coordinate, Vi means the ith racer's speed.0<Xi, Vi<1000000).

Output

For each data set in the input print on a separate line, on the standard output, the integer that represents the maximal amount of overtaking.

Sample Input

2

2 1

2 2

5

2 6

9 4

3 1

4 9

9 1

7

5 5

6 10

5 6

3 10

9 10

9 5

2 2

Sample Output

1

6

7

Hint
Including the same starting points~
Author
BH


#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
int x[100010],y;
struct mp
{
    int x,v;
};
bool cmp(mp a,mp b)
{
    if(a.x==b.x) return a.v>b.v;
    return a.x<b.x;
}
int lowbit(int x)
{
    return x&(-x);
}
void add(int u,int v)
{
    while(u<=y)
    {
        x[u]+=v;
        u+=lowbit(u);
    }
}
long long getsum(int u)
{
    long long  s=0;
    while(u>0)
    {
        s+=x[u];
        u-=lowbit(u);
    }
    return s;
}
int main()
{
    int n,i,j;
    while(~scanf("%d",&n))
    {
        mp a[n];long long sum=0; y=0;
        memset(x,0,sizeof(x));
        for(i=0; i<n; i++)
        {
            scanf("%d%d",&a[i].x,&a[i].v);
            if(y<a[i].v) y=a[i].v;
        }
        sort(a,a+n,cmp);
        for(i=0; i<n; i++)
        {
            add(a[i].v,1);
            sum+=(i-getsum(a[i].v)+1);
        }
        printf("%lld\n",sum);
    }
    return 0;
}


     结果:
     
78319 H Accepted G++ 292ms 2144k 975B 2014-03-16 15:18:15
    同题:hrbust OJ  1400 http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1400


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据问题的描述,技术人员结合其他线索进行分析后,得出密码应该是字符串中子序列"ahcpc2023"的出现次数的除法结果。 子序列是由原字符串中的字符按照相对顺序构成的且不一定连续的序列。所以我们需要找到字符串中所有包含子序列"ahcpc2023"的子序列,并计算出现次数。然后将出现次数进行除法运算,得到密码。 为了更好地理解问题,我们可以举一个例子来说明。 假设待分析的字符串为"ahhpcc2023hchcpc2023ahcacpc2023",该字符串中"ahcpc2023"的子序列有"a", "h", "c", "p", "c", "2", "0", "2", "3", "ah", "ac", "ap", "a2", "a0", "a3", "hh", "hc", "2h", "hc", "hh", "cc", "c2", "c0", "c3", "hhc", "hhp", "hh2", "hh0", "hh3", "hcc", "hc2", "hc0", "hc3", "hhcc", "hhc2", "hhc0", "hhc3", "hcc2", "hcc0", "hcc3", "hc2h", "hc2c", "hc20", "hc2c", "hchh", "hchc", "hchh", "hcch", "hcc2", "hcc0", "hcc3", "hcpc", "hc2p", "hc0p", "hc3p", "ahcp", "ahc2", "ahc0", "ahc3", "hhcp", "hhc2", "hhc0", "hhc3", "hccp", "hc2p", "hc0p", "hc3p", "hhcpp", "hhc2p", "hhc0p", "hhc3p", "hc2cp", "hc0cp", "hc3cp", "hhccp", "hhc2p", "hhc0p", "hhc3p", "hcc2p", "hcc0p", "hcc3p", "hcpcp", "hc2cp", "hc0cp", "hc3cp", "hhcppp", "hhc2pp", "hhc0pp", "hhc3pp", "hc2cpp", "hc0cpp", "hc3cpp", "hhccpp", "hcc2pp", "hcc0pp", "hcc3pp", "hcpcpp", "hc2cpp", "hc0cpp", "hc3cpp", "ahcpp", "ahc2pp", "ahc0pp", "ahc3pp", "hhcppp", "hhc2pp", "hhc0pp", "hhc3pp", "hccppp", "hc2cpp", "hc0cpp", "hc3cpp", "hhcpppp", "hhc2ppp", "hhc0ppp", "hhc3ppp", "hc2cppp", "hc0cppp", "hc3cppp", "hhccppp", "hcc2ppp", "hcc0ppp", "hcc3ppp", "hcpcppp", "hc2cppp", "hc0cppp", "hc3cppp", "ahcppp", "ahc2ppp", "ahc0ppp", "ahc3ppp"。 我们可以看到,子序列"ahcpc2023"在字符串中共出现2次。因此,密码应为2。 总结来说,通过分析原字符串中子序列"ahcpc2023"的出现次数,我们可以得到密码。但具体的密码值需要根据实际分析的字符串来确定。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值