啊?这么快就 粉了???
码风:
#include<iostream>
#include<algorithm>
using namespace std;
int read(){
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-')f=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
x=(x<<3)+(x<<1)+c-48;
c=getchar();
}
return x*f;
}
struct node {
int left,right;
} a[100005];
bool cmp(node x,node y) {
if(x.left==y.left) return x.right<y.right;
return x.left<y.left;
}
int main() {
/*
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
*/
int n=read();
for(int i=1; i<=n; i++) {
a[i].left=read();
a[i].right=read();
}
sort(a+1,a+n+1,cmp);
int tmp,ans=0;
for(int i=1; i<=n; i++) {
if(a[i].right<tmp) ans++;
else tmp=a[i].right;
}
cout<<ans;
return 0;
}总结
- 总是喜欢将相似的代码封装成函数
- 越来越喜欢用快读
- if语句后方如果就1行,会压行
- 输出不换行(AT除外)
- 结构体后方直接定义数组
- cmp函数中喜欢使用if+return的组合,而不是只有return
- 结构体数组等重要数组总喜欢叫a
- 不爱用万能头
- 数组下标、for循环喜欢从1开始,而不是0开始
- 相同类型变量喜欢压到一起
出处
出自我的第 篇题解。(去掉了注释)链接