跳到正文

闲话

爆码风.png

__CrossBow_EXE__约 2 分钟
原文
文章信息与版本

文章信息

发布
2023年10月1日
收录
2025年12月12日
更新
2026年10月4日
篇幅
约 2 分钟

版本

  1. v1当前

啊?这么快就 4×1014 \times 10^1 粉了???

码风:

C++
#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开始
  • 相同类型变量喜欢压到一起

出处

出自我的第 4×1004 \times 10^0 篇题解。(去掉了注释)链接

原文
存档评论8 条抓取于