[刷题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 ...
随机推荐
- string.Format 里面包含 javascript方法参数的时候 单引号变成双引号的问题解决方法
解决方法如下 StringBuilder sb = new StringBuilder(); var str =@"<label><input type='checkbox ...
- Android 超仿Path时间轴和扇形菜单的效果
网上看到的 ,仅此记录一下,用到的时候便于查找 效果如下: 源码下载地址 : http://download.csdn.net/detail/abc13939746593/7251933
- 【转】使用 Auto Layout 的典型痛点和技巧
layoutIfNeeded()强制立刻更新布局 原文网址:http://www.jianshu.com/p/0f031606e5f2 官方文档:Auto Layout Guide 加上去年WWDC上 ...
- 关于web安全
从技术到安全, 这是一个趋势. 以前追求的是比较炫酷的技术, 等实现过后发现, 自己还能做什么. 炫技完了之后,差不多就该到悟道的时候了. 用户安全, 就是一个很大的禅. 苹果拒绝 FBI, goog ...
- android 官网处理图片 代码
/** * 获取压缩后的图片 (官网大图片加载对应代码) * * @param res * @param resId * @param reqWidth * 所需图片压缩尺寸最小宽度 * @param ...
- (原创)LAMP教程6-使用SecureCRTPortable工具远程连接centos
(原创)LAMP教程6-使用SecureCRTPortable工具远程连接centos 是的,今天老柯就给大家介绍一款可以远程连接centos的工具,是的这个就是目前,最夯实的,最多人使用的Secur ...
- 2016计蒜之道复赛 百度地图的实时路况 floyd+cdq分治
链接:https://nanti.jisuanke.com/t/11217 奉上官方题解: 枚举 d(x , y , z) 中的 y,把 y 从这个图中删去,再求这时的全源最短路即可,使用 Floyd ...
- [selenium webdriver Java]元素定位——findElement/findElements
策略 语法 语法 描述 By id driver.findElement(By.id()) driver.findElements(By.id()) 通过id属性定位元素 By name driver ...
- 用Vmware安装centos5
Vmware安装过程就不详述了,这里从创建虚拟机开始记录. 选择创建虚拟机 下一步 选择稍后安装 选择安装的操作系统版本,需要说明的是,CentOs 5 就是RHEL 5 设置虚拟机名称及虚拟机位置 ...
- C语言中 v...printf类函数的用法
C语言的自学渐渐接近尾声,今天学到了标准库中的stdarg.h头,里面关联了stdio.h头里面的一类函数:v...printf函数,里面举的例子看了之后还是不太明白,google了一下依旧不是很懂, ...