比赛状况:
题解: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[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;