O2优化什么鬼!

P2010 [NOIP2016 普及组] 回文日期

无欢 @ 2018-02-03 14:11:45

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
struct node
{
    char d[17];
};
node c[17];
char a[9],b[9],e[17],len=0;
int se[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int year1,moon1,date1;
int year2,moon2,date2;
int i,j,k,sum=0;
int main()
{
    k=0;
    i=0;
    while(len<16)
    {
        scanf("%s",c[i].d);
        for(j=0;j<=strlen(c[i].d)-1;j++)
        {
            e[k]=c[i].d[j];
            k++;
        }
        len+=strlen(c[i].d);
        i++;
    }
    for(i=0;i<=7;i++)
    {
        a[i]=e[i];
        b[i]=e[i+8];
    }
    year1=(a[0]-'0')*1000+(a[1]-'0')*100+(a[2]-'0')*10+(a[3]-'0')*1;
    year2=(b[0]-'0')*1000+(b[1]-'0')*100+(b[2]-'0')*10+(b[3]-'0')*1;
    moon2=(b[4]-'0')*10+(b[5]-'0')*1;
    date2=(b[6]-'0')*10+(b[7]-'0')*1;
    for(i=year1;i<=year2;i++)
    {
        moon1=(i/1%10*10)+(i/10%10*1);
        date1=(i/100%10*10)+(i/1000%10*1);
        if(moon1!=2)
        {
            if(i!=year2)
            {
                if(date1<=a[moon1])
                {
                    sum++;
                }
            }
            else
            {
                if(moon1<moon2)
                {
                    sum++;
                }
                if(moon1==moon2)
                {
                    if(date1<=date2)
                    {
                         sum++;
                    }
                }
            }
        }
        else
        {
            if((i%4==0&&i%100!=0)||(i%400==0))
            {
                if(i!=year2)
                {
                    if(date1<=29)
                    {
                        sum++;
                    }
                }
                else
                {
                    if(moon1<moon2)
                    {
                        if(date1<=se[moon1])
                        {
                            sum++;
                        }
                    }
                    if(moon1==moon2)
                    {
                        if(date1<=date2)
                        {
                             sum++;
                        }
                    }
                }
            }
            else
            {
                if(i!=year2)
                {
                    if(date1<=28)
                    {
                        sum++;
                    }
                }
                else
                {
                    if(moon1<moon2)
                    {
                        if(date1<=se[moon1])
                        {
                            sum++;
                        }
                    }
                    if(moon1==moon2)
                    {
                        if(date1<=date2)
                        {
                             sum++;
                        }
                    }
                }
            }
        }
    }
    cout<<sum;
    return 0;
}

没有O2优化60分 O2后70分 谁能告诉我O2优化是干嘛的!


by Velix @ 2020-07-26 21:27:06

考古

想必各位都是搜O2优化来的(


by chinagreat @ 2020-07-31 21:48:45

@Lonely_zongqing 领君一席言,胜读十年书!


by Schrodinger @ 2020-08-04 09:38:53

@朕是蒟蒻 考古(百度搜O2进来的)


by E_ghost @ 2020-08-22 18:42:12

就是在代码面前加了这样一句话:

#pragma GCC optimize(2)

让编译器预编译所有能够预编译的东西,耗费更多的编译时间来换取更少的运行时间,评测时可以根据题目和程序情况选择是否开启来达到更短的时间


by E_ghost @ 2020-08-22 18:43:14

@Schrodinger 同道中人 :)


by Schrodinger @ 2020-08-22 19:42:14

@E_ghost


by DeepSkyBlue__ @ 2020-08-28 08:30:15

考古(百度搜O2进来的)


by 屑稻香 @ 2020-08-28 19:36:38

考古(不错,百度进来的)


by Miraii @ 2020-09-03 21:32:26

考古(百度)


by Chisato @ 2020-09-22 17:22:39

@Lonely_zongqing 魔鬼,宁是学过汇编,read过机器码,还是C++DALAO


上一页 | 下一页