C艹,求助!!!

P2669 [NOIP2015 普及组] 金币

luox2019 @ 2020-08-25 09:00:17

#include <bits/stdc++.h>
#pragma GCC optimize(150)
using namespace std;
int main()
{
    int k;
    long long ans=0;
    int l=0;
    cin>>k;
    for(int i=1;;i++)
    {
        for(int j=1;j<=i;j++)
        {
            ans+=i;
            l++;
        }
        if(k==l)
        {
            cout<<ans;
            return 0;
        }
    }
}

by BlankAo @ 2020-08-25 09:05:09

        for(int j=1;j<=i;j++)
        {
            ans+=i;
            l++;
        }
        if(k==l)
        {
            cout<<ans;
            return 0;
        }

改成

        for(int j=1;j<=i;j++)
        {
            ans+=i;
            l++;
            if(k==l)
            {
               cout<<ans;
               return 0;
            }
        }

by BlankAo @ 2020-08-25 09:05:31

@luox2019


by lnwsh @ 2020-08-25 09:16:33

#pragma GCC optimize(150)


by Kobe_Bryant824 @ 2020-08-25 09:45:15

看题解得了


by dead_X @ 2020-08-25 09:49:29

@lnwsh

我还用过 #pragma GCC optimize(114514) /shake


by David_H_ @ 2020-08-25 09:51:28

@dead_X 这么臭的优化有用的必要吗(恼


by lnwsh @ 2020-08-25 13:45:28

@dead_X 啊这


by luox2019 @ 2020-08-25 14:27:17

@BlankAo 蟹蟹大佬


by kongyuner @ 2020-08-26 14:01:04

c艹可还行鹅鹅鹅


by 小程序猿 @ 2020-09-05 22:14:04

直接一个for循环,嗯。


| 下一页