http://acm.hdu.edu.cn/contests/contest_show.php?cid=867
A题,直接分块,不知道正解是什么。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll sum(int n){
ll ans=0;
for(ll l=1,r;l<=n;l=r+1){
r=n/(n/l);
ans+=(r-l+1)*(n/l);
}
return ans;
}
int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
//freopen("Yinku.out", "w", stdout);
#endif // Yinku
int q;
while(~scanf("%d", &q)) {
for(int qi = 1; qi <= q; qi++) {
int n;
scanf("%d", &n);
printf("Case %d: %s
", qi, sum(n) & 1 ? "odd" : "even");
}
}
}
B题,不是很懂12小时为什么把0写作12,中午12点是12:00 PM。半夜是12:00 AM。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int h, m;
char ap[4];
void input_time() {
scanf("%d:%d %s", &h, &m, ap);
if(strcmp(ap, "AM") == 0) {
if(h == 12)
h -= 12;
} else {
if(h != 12)
h += 12;
}
}
void input_city() {
char s1[40], s2[40];
scanf("%s%s", s1, s2);
int dh = 0,dh2;
switch(s1[0]) {
case 'B':
dh = +8;
break;
case 'W':
dh = -5;
break;
case 'L':
dh = 0;
break;
case 'M':
dh = 3;
break;
}
switch(s2[0]) {
case 'B':
dh2 = +8;
break;
case 'W':
dh2 = -5;
break;
case 'L':
dh2 = 0;
break;
case 'M':
dh2 = 3;
break;
}
h+=dh2-dh;
}
void output_time() {
if(h<0){
printf("Yesterday ");
h+=24;
}
else if(h>=24){
printf("Tomorrow ");
h-=24;
}
else{
printf("Today ");
}
if(h<12){
if(h==0)
h+=12;
strcpy(ap,"AM");
}
else{
if(h!=12)
h-=12;
strcpy(ap,"PM");
}
printf("%d:%02d %s",h,m,ap);
}
int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
//freopen("Yinku.out", "w", stdout);
#endif // Yinku
int q;
while(~scanf("%d", &q)) {
for(int qi = 1; qi <= q; qi++) {
input_time();
input_city();
printf("Case %d: ", qi);
output_time();
putchar('
');
}
}
}