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. (任寒韬)WebApp群主 - MobileTech 资料

    web app : http://www.lightapp.cn/brand/index/4101 https://github.com/jtyjty99999/mobileTech/blob/mas ...

  2. UVA 568 Just the Facts (水)

    题意: 求一个数n的阶乘,其往后数第1个不是0的数字是多少. 思路: [1,n]逐个乘,出现后缀0就过滤掉,比如12300就变成123,继续算下去.为解决爆long long问题,将其余一个数mod, ...

  3. Jquery插件写法及extentd函数

    JQuery插件写法 JQuery插件又分为类扩展方法和对象扩展方法两种,类插件是定义在JQuery命令空间的全局函数,直接通过可调用,如可调用,如可调用,如.ajax():对象插件是扩展JQuery ...

  4. ASIHttpRequest编译不通过

    转:http://blog.sina.com.cn/s/blog_67a5e47201014tof.html Undefined symbols for architecture i386:   &q ...

  5. tcprstat源码分析之tcp数据包分析

    tcprstat是percona用来监测mysql响应时间的.不过对于任何运行在TCP协议上的响应时间,都可以用.本文主要做源码分析,如何使用tcprstat请大家查看博文<tcprstat分析 ...

  6. hdu 3518(后缀数组)

    题意:容易理解... 分析:这是我做的后缀数组第一题,做这个题只需要知道后缀数组中height数组代表的是什么就差不多会做了,height[i]表示排名第i的后缀与排名第i-1的后缀的最长公共前缀,然 ...

  7. codeforces 678E Another Sith Tournament 概率dp

    奉上官方题解 然后直接写的记忆化搜索 #include <cstdio> #include <iostream> #include <ctime> #include ...

  8. [Irving]WPF Invalid character in the given encoding. Line xx, position xx.' XML is not valid.

    WPF开发中发现Xaml界面中突然抽风似的提示错误 Invalid character in the given encoding. Line xx, position xx.' XML is not ...

  9. Loadrunner模拟Json请求

    一.loadrunner脚本创建 1.Insert - New step -选择Custom Request - web_custom_request 2.填入相应参数 3.生成脚本,并修改如下(参数 ...

  10. Integer做WeakHashMap的Key应注意的问题

    WeakHashMap使用弱引用来作为Map的Key,利用虚拟机的垃圾回收机制能自动释放Map中没有被使用的条目.但是WeakHashMap释放条目是有条件的:首先条目的Key在系统中没有强引用指向: ...