90分,有一个点没过求助

P2669 [NOIP2015 普及组] 金币

Furina_why @ 2024-10-20 08:37:02

代码附上

#include<bits/stdc++.h>
using namespace std;
int main()

{
//freopen("coin.in","r",stdin);
//freopen("coin.out","w",stdout);
long long k,num=0,i=0,j=0,c=2,x=0;
cin>>k;
if(k==1)
{
//cout<<1<<endl;
return 1;
}
//x=2;

else {
num=1;
for(i=2;i<=k;i++)
{
    for(j=1;j<=i;j++)
    {
    if(c==k+1)
    break;
    else {
    num=num+i;
    //cout<<num<<" ";
    c=c+1;
    }
    }
}
}
cout<<num<<endl;
return 0;
}

老师给我测的时候告诉我炸了一个测试点,以上是我在洛谷测,路过的大佬看一下,谢谢


by Jean_Gunnhildr @ 2024-10-20 08:51:51

@Furina_why 是不是退出循环有问题, break 只会退出一层循环。我写的时候是满足条件后直接结束程序。


by Furina_why @ 2024-10-20 08:52:52

@Alicezhou 好的,我试试


by Furina_why @ 2024-10-20 08:54:56

@Alicezhou 好像不行唉


by Jean_Gunnhildr @ 2024-10-20 08:56:57

呃,,,参考一下


by Furina_why @ 2024-10-20 08:59:15

@Alicezhou

#include<bits/stdc++.h>
using namespace std;
int main()

{
//freopen("coin.in","r",stdin);
//freopen("coin.out","w",stdout);
long long k,num=0,i=0,j=0,c=2,x=0;
cin>>k;
if(k==1)
{
//cout<<1<<endl;
return 1;
}
//x=2;

else {
num=1;
for(i=2;i<=k;i++)
{
    for(j=1;j<=i;j++)
    {
    if(c==k+1)
    {
        cout<<num<<endl;
    return 0;
    }
    else {
    num=num+i;
    //cout<<num<<" ";
    c=c+1;
    }
    }
}
}
cout<<num<<endl;
return 0;
}

你是这个意思吗?好像还是RE


by sundingjia @ 2024-10-20 09:00:57

main函数中,return 1算RE @Furina_why


by sundingjia @ 2024-10-20 09:01:32

here:

if(k==1)
{
//cout<<1<<endl;
return 1;
}
//x=2;

by Furina_why @ 2024-10-20 09:03:12

@sundingjia 谢谢大佬,已经全部AC了


|