2014 UESTC Training for Data Structures F - 天下归晋

时间:2014-05-01 20:00:43   收藏:0   阅读:275

F - 天下归晋

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
 

晋朝统一天下已有十年,曹魏、孙吴、蜀汉这些曾与天下相争的王朝,都成为了过眼云烟,仅留于故事之中。

“爷爷,讲嘛讲嘛,再讲一次赤壁之战的故事嘛!”

“你个死小子,都讲多少遍了,还听!”

“就是想听打仗嘛!”

“你小子啊...行,我就再讲一次。当时曹公率领八十万大军欲渡长江,那船队规模才叫一壮观啊,长江都铺成陆地啰。当时是这样部署的....”

曹操的船队自西向东铺于长江之上,为了方便指挥,每艘船都被赋予了相应的等级。这个等级由该船西南方船只的数量决定,即不比该船靠东并且不比该船靠北的船的数目。那是一只多么庞大的船队啊,只惜周郎一把火,樯橹灰飞烟灭......

“太刺激了,打仗好好玩啊!爷爷你怎么那么清楚当时的事儿,你的腿就是赤壁时断的吗?”

通天的火光,被激流卷去的兄弟,无数的惨叫,折断后砸向自己左腿的船柱...

看了眼激动的孙子,老者咂咂嘴,淡淡说道:“爬山采药时摔的”。

Input

第一行,一个整数n表示曹军船只的数量。

接下来n行,每行一个对整数xi,yi。表示第i艘船的坐标。

数据保证不会有两艘船在同一位置。

1n100000,0xi,yi32000

Output

n行,每行1个整数,分别表示从0级到n?1级的船的数量。

行末不要有空格。

Sample input and output

Sample Input Sample Output
5
1 1
5 1
7 1
3 3
5 5
1
2
1
1
0

 

这道题其实和E - 休生伤杜景死惊开几乎是一样的,就是多了一个y值有可能是0,我们把y值全部加1就好了,直接先按x排序,x相同时按y排序,就把数据处理得跟E题一样了,于是按E题的思路打一遍就过了.

 

mamicode.com,码迷
#include <iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
struct node{
    int x;
    int y;
}chuan[100005];
int maxn=-1;;
bool cmp(const node &j,const node &k)
{
    if (j.x!=k.x) return j.x<k.x;
    else return j.y<k.y;
}
int tree[100005]={},ans[100005]={},a[100005]={};
int suan(int j)
{
    int a=0;
    while (j>0){
        a+=tree[j];
        j-=j&-j;
    }
    return a;
}
void jia(int j)
{
    while (j<=maxn){
        tree[j]+=1;
        j+=j&-j;
    }
}
int main()
{
    int n,j;
    cin>>n;
    for (j=1;j<=n;j++) {
        scanf("%d%d",&chuan[j].x,&chuan[j].y);
        chuan[j].y++;
        if (chuan[j].y>maxn) maxn=chuan[j].y;
    }
    sort(chuan+1,chuan+n+1,cmp);
    for (j=1;j<=n;j++){
        ans[j]=suan(chuan[j].y);
        jia(chuan[j].y);
    }
    for (j=1;j<=n;j++) a[ans[j]]++;
    for (j=0;j<=n-1;j++) printf("%d\n",a[j]);
    return 0;
}
mamicode.com,码迷

 

 

 

2014 UESTC Training for Data Structures F - 天下归晋,码迷,mamicode.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!