蒟蒻42分贪心求教

P1803 凌乱的yyy / 线段覆盖

``` #include<cstdio> #include<algorithm> #define N 1000000 using namespace std; struct Thing{long long int b,e;}thing[N]; bool cmp(Thing a,Thing b) { return a.e < b.e; } int main() { int n,ans = 1; scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%lld%lld",&thing[i].b,&thing[i].e); sort(thing+1,thing+1+n,cmp); // for(int i=1;i<=n;i++)printf("%d %d\n",thing[i].b,thing[i].e); long long int t = thing[1].e; for(int i=1;i<=n;i++) { if (t <= thing[i].b)ans++,t = thing[i].e; } printf("%d",ans); return 0; }```
by Merci @ 2019-02-03 13:18:10


@[石破天惊](/space/show?uid=9032) 你的循环有错,我代码发给你了QwQ
by Merci @ 2019-02-03 13:18:43


@[sam上帝](/space/show?uid=122822) 为什么要从 **1** 开始
by 石破天惊 @ 2019-02-03 13:23:46


@[sam上帝](/space/show?uid=122822) 谢谢**dalao**,过了( ̄▽ ̄)/
by 石破天惊 @ 2019-02-03 13:26:36


@[石破天惊](/space/show?uid=9032) 1和2都行
by Merci @ 2019-02-03 13:37:14


上一页 |