xtracer @ 2021-01-27 16:01:33
我用结构体开了个超级大暴力,开了O2才过。。。这道题是教练让我们做的,并且他说今晚要检查,不能有O2字样。请各位大佬帮一下忙,谢谢!
#include<iostream>
#include<string>
using namespace std;
typedef long long ll;
ll str_to_ll(string str){
ll ans=0;
for(ll i=0;i<str.length();i++)ans=ans*10+str[i]-48;
return ans;
}
string ll_to_str(ll n){
string ans="";
while(n){
ans=char(n%10+48)+ans;
n/=10;
}
return ans;
}
class date{
public:
ll year,month,day;
date getdate(ll a,ll b,ll c){
date ans;
ans.year=a;
ans.month=b;
ans.day=c;
return ans;
}
bool runyear(ll y){
if(y%400==0)return true;
else if(y%100!=0 and y%4==0)return true;
else return false;
}
ll dayofmonth(ll y,ll m){
if(m==2){
if(runyear(y))return 29;
else return 28;
}
else{
if(m==1 or m==3 or m==5 or m==7 or m==8 or m==10 or m==12)return 31;
else return 30;
}
}
void get_date(string str){
string y=str.substr(0,4);
string m=str.substr(4,2);
string d=str.substr(6,2);
year=str_to_ll(y);
month=str_to_ll(m);
day=str_to_ll(d);
}
date plus(ll num){
day+=1;
ll dom=dayofmonth(year,month);
if(day>dom){
day-=dom;
month+=1;
}
if(month>12){
month-=12;
year+=1;
}
return getdate(year,month,day);
}
string add0(ll n){
if(n>=10)return ll_to_str(n);
else return '0'+ll_to_str(n);
}
void output(){
cout<<add0(year)<<add0(month)<<add0(day);
}
};
date makedate(string str){
string x,y,z;
ll a,b,c;
x=str.substr(0,4);
y=str.substr(4,2);
z=str.substr(6,2);
a=str_to_ll(x);
b=str_to_ll(y);
c=str_to_ll(z);
date res={a,b,c};
return res;
}
bool cmp(date x,date y){
if(x.year!=y.year)return x.year>=y.year;
else if(x.month!=y.month)return x.month>=y.month;
else return x.day>=y.day;
}
bool huiwen(date n){
string str;
str+=n.add0(n.year);
str+=n.add0(n.month);
str+=n.add0(n.day);
string rev;
for(ll i=0;i<str.length();i++)rev+=str[str.length()-i-1];
return rev==str;
}
string str;
date a,b;
ll ans=0;
int main(){
cin>>str;
a=makedate(str);
cin>>str;
b=makedate(str);
for(date i=a;cmp(b,i);i.plus(1)){
if(huiwen(i))ans+=1;
}
cout<<ans;
return 0;
}
by xtracer @ 2021-01-27 16:04:21
T了第10个点
by xfrvq @ 2021-01-27 16:22:39
您...
by xfrvq @ 2021-01-27 16:23:03
正解的时间复杂度是O(1)
by xtracer @ 2021-01-27 16:23:03
@滑翔翼 额
by xtracer @ 2021-01-27 16:23:27
@滑翔翼 知道,但我就只想到暴力23333
by xfrvq @ 2021-01-27 16:23:31
从1月1日枚举到12月31日
by xfrvq @ 2021-01-27 16:24:08
再判断对应的年份在不在给定的范围里面
by xtracer @ 2021-01-27 16:24:33
https://www.luogu.com.cn/discuss/show/41033?page=3514
居然有人抄我的暴力代码......连函数名、变量名都不改......有UKE那味了......
by xfrvq @ 2021-01-27 16:24:37
可能有几个坑点
by xtracer @ 2021-01-27 16:26:49
https://www.luogu.com.cn/discuss/show/41033?page=3514
居然有人抄我的暴力代码......连函数名、变量名都不改......有UKE那味了......