别乱写代码,会RE

P1001 A+B Problem

CyaNgw_DyG @ 2021-08-13 20:35:24

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,o;
    cin>>a>>b;
    if(b<=0)for(o=0;o>b;o--)a+=-1;
    else for(o=1;o<=b;o++)a+=1;
    cout<<a;
    return o;
} 

by chiyuye @ 2021-08-23 16:02:03

你直接输出a+b不就行了吗?这样会对吗?


by CyaNgw_DyG @ 2021-08-24 08:46:55

@chiyuye a+b??我不会写A+B,老师叫我用循环做,开O2优化就过了,但是别写return o就行了


by Wang1006 @ 2021-08-26 20:42:59

真要乱写的话可以这么写。。。 ac记录

#include<iostream>
using namespace std;
int main(){
intt:
    int a,b;
init:
    cin>>a>>b;
out:
    cout<<a+b;
    goto end;
rp:
    while(1)cout<<"rp++";
end:
    return 0;
}

by CyaNgw_DyG @ 2021-08-27 08:57:09


by Wang1006 @ 2021-08-28 15:45:10

这个过不了TLE

#include<bits/stdc++.h>
using namespace std;
struct AC{
    int u,v,w;
}edge[20000005];
int fa[50000005],n,m,ans,eu,ev,cnt;
bool cmp(AC a,AC b){
    return a.w<b.w;
}
int find(int x){
    while(x!=fa[x]) x=fa[x]=fa[fa[x]];
    return x;
}
int main(){
init:
    cin>>n>>m;
    if(n<=0||m<=0){
        cout<<n+m;
        return 0;
    }
    for(int i=1;i<=n;i++){
        fa[i]=i;
    }
    for(int i=1;i<=n-1;++i){
        edge[i].u=1,edge[i].v=n,edge[i].w=1;
    }
kruskal:
    sort(edge,edge+m,cmp);
    for(int i=0;i<m;i++){
        eu=find(edge[i].u), ev=find(edge[i].v);
        if(eu==ev){
            continue;
        }
        ans+=edge[i].w;
        fa[ev]=eu;
        if(++cnt==n-1){
            break;
        }
    }
out:
    printf("%d",ans+1+m);
    return 0;
}

by CyaNgw_DyG @ 2021-09-11 09:54:34

@Wang1006 开O2能过(真是个天才啊你


上一页 |