屎山代码果然不行,为难我信竞生

B2092 开关灯

Eric1012 @ 2023-10-29 10:01:44

服了家人们我的屎山代码超时唯一一个还没过wuwu;``` bool a[5001]; int main(){ int n; cin>>n; for(int i=2;i<=5000;i=i+2){ a[i]=true; } for(int j=3;j<=n;j++){ for(int m=j;m<=n;j++){ if (a[m]==true) a[m]=false; else a[m]=true; } } for (int p=1;p<=n;p++){ if (a[p]==false) { cout<<a[p]<<" "; } } }


by Kniqht @ 2023-10-29 10:03:02

emmm几行的"屎山"


by while_true @ 2023-10-29 10:03:47

@Eric1012 你这个 Markdown 格式一言难尽


by Special_Tony @ 2023-10-29 10:09:26

@Eric1012 屎山Markdown果然不行,为难我信竞生


by jqQt0220 @ 2023-10-29 10:09:27

希丰展?使 MD


by yhk1001 @ 2023-10-29 10:09:57

for(int m=j;m<=n;j++) j++改为m += j

cout<<a[p]<<" "输出的是编号,不是bool

@Eric1012


by Starry_dream @ 2023-10-29 10:16:25

MD规则好好看看(MarkDown)


by xiaoshumiao @ 2023-10-29 10:24:21


bool a[5001]; 
int main(){ 
  int n; 
  cin>>n; 
  for(int i=2;i<=5000;i=i+2){ 
    a[i]=true; 
  } 
  for(int j=3;j<=n;j++){ 
    for(int m=j;m<=n;j++){ 
      if (a[m]==true) 
        a[m]=false; 
      else 
        a[m]=true; 
     } 
  } 
  for (int p=1;p<=n;p++){ 
    if (a[p]==false) { 
      cout<<a[p]<<" "; 
    } 
  } 
}

by Zikl @ 2023-10-29 10:32:56

@Eric1012 屎山Markdown果然不行,为难我信竞生


|