NOIP 2011 Day1 Problem2

#include<cstdio>
#include<iostream>
using namespace std;
struct node
{
    int color;
    int cost;
}a[200010];
int number[60],number1[60];
int main()
{
    freopen("hotel.in","r",stdin);
    freopen("hotel.out","w",stdout);
    int n,k,p;
    scanf("%d %d %d",&n,&k,&p);
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d %d",&a[i].color,&x);
        if(x>p)
            a[i].cost=1;
    }
    int flag=0;
    int sum=0;
    int sum1=0;
    for(int i=1;i<=n;i++)
    {
        sum+=number[a[i].color];
        number[a[i].color]++;
    }
    for(int i=1;i<=n;i++)
        if(a[i].cost==0)
            flag=0;
        else
        {
            if(flag==0)
                memset(number1,0,sizeof(number1));
            else
                sum1+=number1[a[i].color];
            number1[a[i].color]++;
            flag=1;
        }
    printf("%d",sum-sum1);
    return 0;
}

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页