650A
637A

点击查看原题

650A又是一个排序去重的问题,一定要注意数据范围用long long ,而且在写计算组合函数的时候注意也要用long long 虽然10^9没有超过long的范围,但是在计算n*(n-1)/2的过程中超了,所以需要用long long ,否则会出错。

#include<iostream>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
using namespace std;

long n;

struct Point {
    long x,y;
};

bool cmpx(const Point &p1,const Point &p2)
{
    if (p1.x!=p2.x) {
        return p1.x<p2.x;
    }
    else {
        return p1.y<p2.y;
    }
}

bool cmpy(const Point &p1,const Point &p2)
{
    if (p1.y!=p2.y) {
        return p1.y<p2.y;
    }
    else {
        return p1.x<p2.x;
    }
}

long long cn2(long long n)
{
    )/;
}

Point a[];
Point ax[];
];
Point ay[];
];
Point axy[];
];

void mysortx(Point *a,Point *ax)
{
    axc[]=;
    ;
    while (p<n) {
        ;
        axc[]++;
        ax[axc[]]=a[p];
        <n && a[p+].x==a[p].x) {
            p++;
            coup++;
        }
        axc[axc[]]=coup;
        p++;
    }
}

void mysorty(Point *a,Point *ay)
{
    ayc[]=;
    ;
    while (p<n) {
        ;
        ayc[]++;
        ay[ayc[]]=a[p];
        <n && a[p+].y==a[p].y) {
            p++;
            coup++;
        }
        ayc[ayc[]]=coup;
        p++;
    }
}

void mysortxy(Point *a,Point *axy)
{
    axyc[]=;
    ;
    while (p<n) {
        ;
        axyc[]++;
        axy[axyc[]]=a[p];
        <n && a[p+].x==a[p].x && a[p+].y==a[p].y) {
            p++;
            coup++;
        }
        axyc[axyc[]]=coup;
        p++;
    }
}

int main()
{

    scanf("%ld",&n);
    ;i<n;i++) {
        scanf("%ld %ld",&a[i].x,&a[i].y);
    }
    sort(a,a+n,cmpx);
    mysortx(a,ax);
    /*for (int i=1;i<=axc[0];i++) {
        cout <<ax[i].x <<"," <<ax[i].y <<"|" <<axc[i]<<endl;
    }*/
    sort(a,a+n,cmpy);
    mysorty(a,ay);
    mysortxy(a,axy);
    ;
    ;i<=axc[];i++) {
        ans+=cn2(axc[i]);
    }
    ;i<=ayc[];i++) {
        ans+=cn2(ayc[i]);
    }
    ;i<=axyc[];i++) {
        ans-=cn2(axyc[i]);
    }
    printf("%I64d\n",ans);
    ;
}

637A原本是想的双关键字sort,但是后来发现没有那么麻烦,直接把数据存进1000000的数组扫两遍就行了。注意细节,尤其是for循环的起始位置。

#include<stdio.h>
#include<stdlib.h>

struct point {
    int o,x,y;
};

];

int main()
{
    int n;
    scanf("%d",&n);
    int i;
    ;i<=;i++) {
        a[i].o=i;
    }
    ;i<=n;i++) {
        int input;
        scanf("%d",&input);
        (a[input].x)++;
        (a[input].y)=i;
    }
    ;
    ].x;
    ;i<=;i++) {
        if (a[i].x>maxn) {
            maxn=a[i].x;
            maxj=i;
        }
    }
    ;
    ;
    ;i<=;i++) {
        if (a[i].x==maxn && a[i].y<minm) {
            mini=i;
            minm=a[i].y;
        }
    }
    printf("%d\n",a[mini].o);
    ;
}

[刷题codeforces]650A.637A的更多相关文章

  1. [刷题]Codeforces 794C - Naming Company

    http://codeforces.com/contest/794/problem/C Description Oleg the client and Igor the analyst are goo ...

  2. [刷题codeforces]651B/651A

    651B Beautiful Paintings 651A Joysticks 点击可查看原题 651B是一个排序题,只不过多了一步去重然后记录个数.每次筛一层,直到全为0.从这个题里学到一个正确姿势 ...

  3. [刷题]Codeforces 786A - Berzerk

    http://codeforces.com/problemset/problem/786/A Description Rick and Morty are playing their own vers ...

  4. [刷题]Codeforces 746G - New Roads

    Description There are n cities in Berland, each of them has a unique id - an integer from 1 to n, th ...

  5. CF刷题-Codeforces Round #481-G. Petya's Exams

    题目链接:https://codeforces.com/contest/978/problem/G 题目大意:n天m门考试,每门考试给定三个条件,分别为:1.可以开始复习的日期.2.考试日期.3.必须 ...

  6. CF刷题-Codeforces Round #481-F. Mentors

    题目链接:https://codeforces.com/contest/978/problem/F 题目大意: n个程序员,k对仇家,每个程序员有一个能力值,当甲程序员的能力值绝对大于乙程序员的能力值 ...

  7. CF刷题-Codeforces Round #481-D. Almost Arithmetic Progression

    题目链接:https://codeforces.com/contest/978/problem/D 题解: 题目的大意就是:这组序列能否组成等差数列?一旦构成等差数列,等差数列的公差必定确定,而且,对 ...

  8. [刷题]Codeforces 785D - Anton and School - 2

    Description As you probably know, Anton goes to school. One of the school subjects that Anton studie ...

  9. Codeforces刷题计划

    Codeforces刷题计划 已完成:-- / -- [Codeforces370E]370E - Summer Reading:构造:(给定某些数,在空白处填数,要求不下降,并且相邻差值<=1 ...

随机推荐

  1. django - get_or_create() 使用提醒

    [omron - debug] user_id建表的时候,不能使用unique,因为一个用户,可能有多个product_id,相对应的是,get_or_create()中的查询参数,如果在建表中有un ...

  2. 最简单的视音频播放示例3:Direct3D播放YUV,RGB(通过Surface)

    上一篇文章记录了GDI播放视频的技术.打算接下来写两篇文章记录Direct3D(简称D3D)播放视频的技术.Direct3D应该Windows下最常用的播放视频的技术.实际上视频播放只是Direct3 ...

  3. crtmpserver流媒体服务器的介绍与搭建

    crtmpserver流媒体服务器的介绍与搭建 (2012-02-29 11:28) 标签:  crtmpserver  C++ RTMP Server  rtmp  Adobe FMS(Flash ...

  4. <摘录>PS和TS流的区别

    在 MPEG-2系统中,信息复合/分离的过程称为系统复接/分接,由视频,音频的ES流和辅助数据复接生成的用于实际传输的标准信息流称为MPEG-2传送 流(TS:TransportStream).据传输 ...

  5. Android开发中如何调用摄像头的功能

    我们要调用摄像头的拍照功能,显然 第一步必须加入调用摄像头硬件的权限,拍完照后我们要将图片保存在SD卡中,必须加入SD卡读写权限,所以第一步,我们应该在Android清单文件中加入以下代码     & ...

  6. eclipse设置自定义快捷键

    eclipse有很多强大且人性化的功能,而各项功能有时又隐藏得比较深(需要点击数次菜单才能找到),而系统提供的快捷键有时比较难记住甚至根本没有提供快捷键时,就需要自己手动设置快捷键了.设置方法有两种, ...

  7. IIS应用程序池回收图文详解

    转:http://blog.sina.com.cn/s/blog_8677fcaa010138uf.html 什么是应用程序池呢?这是微软的一个全新概念:应用程序池是将一个或多个应用程序链接到一个或多 ...

  8. HTTP协议中的长连接和短连接(keep-alive状态)

    什么是长连接 HTTP1.1规定了默认保持长连接(HTTP persistent connection ,也有翻译为持久连接),数据传输完成了保持TCP连接不断开(不发RST包.不四次握手),等待在同 ...

  9. MDI端口和MDIX端口是什么? 又有什么作用?

    是网线的标准A类接法和B类接法.也就是人们通常所说的交叉网线和直联网线.直联网线就是 白黄 黄 白绿 蓝 白兰 绿 白棕 棕 另一端同样如此.交叉网线就是 另一端的1和3,2和6对调.这样就成了交叉网 ...

  10. Codevs No.1163 访问艺术馆

    2016-05-31 20:48:47 题目链接: 访问艺术馆 (Codevs No.1163) 题目大意: 一个贼要在一个二叉树结构的艺术馆中偷画,画都处于叶子节点处,偷画和经过走廊都需要时间,求在 ...