哈理工 1400 汽车比赛

编程入门 行业动态 更新时间:2024-10-14 08:28:04

哈<a href=https://www.elefans.com/category/jswz/34/1769017.html style=理工 1400 汽车比赛"/>

哈理工 1400 汽车比赛

汽车比赛

Time Limit: 1000 MS

Memory Limit: 65536 K

Total Submit: 388(95 users)

Total Accepted: 146(80 users)

Rating:

Special Judge: No

Description

XianGe非常喜欢赛车比赛尤其是像达喀尔拉力赛,这种的比赛规模很大,涉及到很多国家的车队的许多车手参赛。XianGe也梦想着自己能举办一个这样大规模的比赛,XianGe幻想着有许多人参赛,那是人山人海啊,不过XianGe只允许最多100000人参加比赛。

这么大规模的比赛应该有技术统计,在XianGe的比赛中所有车辆的起始点可能不同,速度当然也会有差异。XianGe想知道比赛中会出现多少次超车(如果两辆车起点相同速度不同也算发生一次超车)。


 

Input

本题有多组测试数据,第一行一个整数n,代表参赛人数,接下来n行,每行输入两个数据,车辆起始位置X i 和速度 V i(0<Xi,Vi<1000000)

Output

输出比赛中超车的次数,每组输出占一行

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

Author

杨和禹

 

 

 

这个是我们理工的题目。树状数组第二次做,独立做出来了 ,不过走了点儿弯路,一开始 是对位置排序 发现这样会导致很复杂,然而 如果直接对速度先排好顺序的话 ,那就会方便好多。注意到如果,位置相同,速度要递增排。

对了

#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
using namespace std;const int M=100000+2;
int cnt[M];struct A
{int s,v;
} per[M*10];bool cmp(A a,A b)
{if(a.s==b.s)return a.v<b.v;return a.s>b.s;
}int lowbit(int x)
{return x&(-x);
}
long long  sum(int x)
{long long  s=0;while(x>0){s+=cnt[x];x-=lowbit(x);}return s;
}void add(int x,int val)
{while(x<=M){cnt[x]+=val;x+=lowbit(x);}
}int main()
{int N;while(cin>>N){int x,y;memset(cnt,0,sizeof(cnt));for(int i=0; i<N; i++){cin>>x>>y;per[i].s=x;per[i].v=y;}sort(per,per+N,cmp);long long  result=0;for(int j=0; j<N; j++){add(per[j].v,1);result+=(sum(per[j].v-1));//cout<<"sum="<<sum(per[j].v-1)<<endl<<"result="<<result<<endl;}printf("%lld\n",result);}return 0;
}
/**
4
7 3
2 3
4 6
4 6
*/


 

 

 

更多推荐

哈理工 1400 汽车比赛

本文发布于:2024-02-25 19:16:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1700024.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:理工   汽车

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!