[刷题codeforces]650A.637A
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的更多相关文章
- [刷题]Codeforces 794C - Naming Company
http://codeforces.com/contest/794/problem/C Description Oleg the client and Igor the analyst are goo ...
- [刷题codeforces]651B/651A
651B Beautiful Paintings 651A Joysticks 点击可查看原题 651B是一个排序题,只不过多了一步去重然后记录个数.每次筛一层,直到全为0.从这个题里学到一个正确姿势 ...
- [刷题]Codeforces 786A - Berzerk
http://codeforces.com/problemset/problem/786/A Description Rick and Morty are playing their own vers ...
- [刷题]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 ...
- CF刷题-Codeforces Round #481-G. Petya's Exams
题目链接:https://codeforces.com/contest/978/problem/G 题目大意:n天m门考试,每门考试给定三个条件,分别为:1.可以开始复习的日期.2.考试日期.3.必须 ...
- CF刷题-Codeforces Round #481-F. Mentors
题目链接:https://codeforces.com/contest/978/problem/F 题目大意: n个程序员,k对仇家,每个程序员有一个能力值,当甲程序员的能力值绝对大于乙程序员的能力值 ...
- CF刷题-Codeforces Round #481-D. Almost Arithmetic Progression
题目链接:https://codeforces.com/contest/978/problem/D 题解: 题目的大意就是:这组序列能否组成等差数列?一旦构成等差数列,等差数列的公差必定确定,而且,对 ...
- [刷题]Codeforces 785D - Anton and School - 2
Description As you probably know, Anton goes to school. One of the school subjects that Anton studie ...
- Codeforces刷题计划
Codeforces刷题计划 已完成:-- / -- [Codeforces370E]370E - Summer Reading:构造:(给定某些数,在空白处填数,要求不下降,并且相邻差值<=1 ...
随机推荐
- UVALive 2238 Fixed Partition Memory Management(二分完美匹配)
题意:计算机中有一些固定大小的内存,内存越大,处理速度越快.对于一个程序,加入不同的内存空间,处理所需时间不同.现给出m个内存空间,n个程序,对于每个程序程序,有k组数据(s,t),分别表示当程序 i ...
- LeetCode: divideInteger
Title: Divide two integers without using multiplication, division and mod operator. If it is overflo ...
- HTML5 随音乐节奏变化的频谱图动画
这里将要介绍的HTML5 音频处理接口与Audio标签是不一样的.页面上的Audio标签只是HTML5更语义化的一个表现,而HTML5提供给JavaScript编程用的Audio API则让我们有能力 ...
- 你所不知道的 URL
0.说明 第一幕 产品:大叔有用户反映账户不能绑定公众号.大叔:啊咧咧?怎么可能,我看看?大叔:恩?这也没问题啊,魏虾米.大叔:还是没问题啊,挖叉类.大叔:T T,话说产品姐姐是不是Java提供接口的 ...
- FTP文件上传与下载
实现FTP文件上传与下载可以通过以下两种种方式实现(不知道还有没有其他方式),分别为:1.通过JDK自带的API实现:2.通过Apache提供的API是实现. 第一种方式:使用jdk中的ftpClie ...
- Number Sequence(KMP,判断子串 模板)
题意: 给两数组,求一个是否是另一个的子数组,若是返回匹配的首位置 分析: KMP 入门 //扫描字符串A,并更新可以匹配到B的什么位置. #include <map> #include ...
- mysql EF
使用 mysql-installer-community-5.6.26.0.msi visual studio 2013 update 4版 Install-Package EntityFramewo ...
- C++实现网格水印之调试笔记(六)——补充
调用matlab生成的网格水印特征向量矩阵 从文件中读取的原始网格的特征向量矩阵 好吧,之前得出的结果不正确是因为代码写错了.因为实现论文中的提取方案时代码写错了,自己想了另外一个方法,结果方向两者在 ...
- 关于DISPLAY变量显示问题
DISPLAY用来设置将图形显示到何处 在本机上直接登录之后,startx,可以发现display变量自动设置为 [oracle@kel ~]$ echo $DISPLAY :0.0 不论使用何种用户 ...
- Canvas入门(2):图形渐变和图像形变换
来源:http://www.ido321.com/986.html 一.图形渐变(均在最新版Google中测试) 1.绘制线性渐变 1: // 获取canvas 的ID 2: var canvas = ...