• 2019.5.3备战省赛组队训练赛第十八场


    传送门

    比赛状况:

    题解:https://www.cnblogs.com/QLU-ACM/p/10816527.html

    A : 

    打表找规律(手动艾特mxl)
    
    a1=3,a2=5
    
    a3=7,a4=9
    
    .................
    
    ai=2*i+1,a(i+1)=2*(i+1)+1 (i为奇数)
    
    假设 n 在 ai 中,如果 i 为奇数,输出 odd,反之,输出 even;
    解析
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define ll long long
     4 #define INF 0x3f3f3f3f3f3f3f3f
     5  
     6 ll n;
     7  
     8 int main()
     9 {
    10     int test;
    11     scanf("%d",&test);
    12     for(int kase=1;kase <= test;++kase)
    13     {
    14         scanf("%lld",&n);
    15         double d=sqrt(4+4*n);
    16         ll x=(d-2)/2;//求根公式
    17         if(x*x+2*x-n >= 0)
    18             printf("Case %d: %s
    ",kase,(x&1) ? "odd":"even");
    19         else
    20             printf("Case %d: %s
    ",kase,((x+1)&1) ? "odd":"even");
    21     }
    22     return 0;
    23 }
    数学公式
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define ll long long
     4 #define INF 0x3f3f3f3f3f3f3f3f
     5 const int maxn=1e6+6;
     6 ll sum[maxn];
     7 ll n;
     8  
     9 int main()
    10 {
    11     for(int i=1;i;i++)
    12     {
    13         sum[i]=3*i+i*(i-1);
    14         if(sum[i]>=1000000000)
    15         {
    16             sum[i+1]=INF;
    17             break;
    18         }
    19     }
    20  
    21     int test;
    22     scanf("%d",&test);
    23     for(int kase=1;kase <= test;++kase)
    24     {
    25         scanf("%lld",&n);
    26         for(int i=1;i<=31623;i++)
    27         {
    28             if(sum[i]>=n&&sum[i-1]<n)
    29             {
    30                 if(sum[i]&1)//sum[i]为奇数,在奇数项
    31                     printf("Case %d: odd
    ",kase);
    32                 else
    33                     printf("Case %d: even
    ",kase);
    34                 break;
    35             }
    36         }
    37  
    38     }
    39     return 0;
    40 }
    求出sum判断(by mxl)
    初始,没往数学公式上推导,想到了二分答案,因为sum[i](前i项和)是升序的;
    
    看了一下数据范围,直接让 l = 0, r = 1e9+1;
    
    wa了两发,仔细想了一下,r 太大时,sum[ mid ]会爆long long 的;
    
    所以,以后碰到这种题,要多往数学公式方面推导,不要动不动就交给代码去实现;
    
    缺乏数学思维,会一直菜下去的;
    反思

    B :

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 const int utc[5]={0,-5,0,3,8};
     4 const string area[5]={"","Washington","London","Moscow","Beijing"};
     5  
     6 int nowH;
     7 int nowM;
     8 string nowArea;
     9 int ansH;
    10 int ansM;
    11 string ansArea;
    12 char s[10];
    13 int day;
    14 map<string ,int >mymap;
    15  
    16 void Solve()
    17 {
    18     int diff=mymap[ansArea]-mymap[nowArea];
    19     ansH=nowH+diff;
    20     string ansDay="Today";
    21     if(ansH >= 24)
    22     {
    23         day=1;
    24         ansH -= 24;
    25         ansDay="Tomorrow";
    26     }
    27     else if(ansH < 0)
    28     {
    29         day=-1;
    30         ansH += 24;
    31         ansDay="Yesterday";
    32     }
    33     string am="AM";
    34     if(ansH >= 12)
    35     {
    36         ansH -= 12;
    37         am="PM";
    38     }
    39     ansM=nowM;
    40     cout<<ansDay<<" ";
    41     printf("%d:%02d ",ansH == 0 ? 12:ansH,ansM);
    42     cout<<am<<endl;
    43 }
    44 int main()
    45 {
    46 //    freopen("C:/Users/14685/Desktop/stdin&&stdout/contest","r",stdin);
    47     for(int i=1;i <= 4;++i)
    48         mymap[area[i]]=utc[i];
    49     int test;
    50     scanf("%d",&test);
    51     for(int kase=1;kase <= test;++kase)
    52     {
    53         day=0;
    54         scanf("%d:%d%s",&nowH,&nowM,s);
    55         cin>>nowArea>>ansArea;
    56         if(s[0] == 'A' && nowH == 12)
    57             nowH=0;
    58         if(s[0] == 'P' && nowH != 12)
    59             nowH += 12;
    60         printf("Case %d: ",kase);
    61         Solve();
    62     }
    63     return 0;
    64 }
    模拟

    注意一点:中午12点为PM;

    补题:C  H

  • 相关阅读:
    HDU 1358 Period (KMP)
    POJ 1042 Gone Fishing
    Csharp,Javascript 获取显示器的大小的几种方式
    css text 自动换行的实现方法 Internet Explorer,Firefox,Opera,Safar
    Dynamic Fonts动态设置字体大小存入Cookie
    CSS Image Rollovers翻转效果Image Sprites图片精灵
    CSS three column layout
    css 自定义字体 Internet Explorer,Firefox,Opera,Safari
    颜色选择器 Color Picker,Internet Explorer,Firefox,Opera,Safar
    CSS TextShadow in Safari, Opera, Firefox and more
  • 原文地址:https://www.cnblogs.com/violet-acmer/p/10817737.html
Copyright © 2020-2023  润新知