大概是CCf第三题中最麻烦的一个吧

      我的思路其实我觉得还可以,模拟...可是超时了233 只有90分 [ 可是我看网上其他人也是模拟算法啊,

      速度还是太慢了 120行, 1个半小时  大部分花在了debug上了

      总结: debug时 不要直接看中间结果,先自己仔细读一遍程序,很多bug不是逻辑错误,而是自己不细心....加油!!

  1 #include <bits/stdc++.h>
  2 using namespace std;
  3 struct node {
  4     string name;
  5     bool isok[6][65];
  6 };
  7 node ord[50];
  8 int mon[][13]={0,31,28,31,30,31,30,31,31,30,31,30,31,
  9                0,31,29,31,30,31,30,31,31,30,31,30,31};
 10 string smon[13]={"","jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"};
 11 string swek[7]={"sun","mon","tue","wed","thu","fri","sat"};
 12 map <string,int> mapp;
 13 int t[10]={0,0,1,1,4,1970}; // min 0,hou 1,day 2,mon 3,week 4,year 5
 14 int ts[10],te[10];
 15 int base[10]={60,24,0,12};
 16 bool is_r (int year) {
 17     if (year%4==0&&year%100!=0||year%400==0) return 1;
 18     return  0;
 19 }
 20 void dd(int k) {
 21     bool flag=is_r(t[5]);
 22     base[2]=mon[flag][t[3]];
 23     for (int i=0;i<=1;i++) {
 24         int tmp=t[i]+k;
 25         k=tmp/base[i]; 
 26         t[i]=tmp%base[i];
 27     }
 28     for (int i=2;i<=3;i++) {
 29         if (i==2) t[4]=(t[4]+k)%7;
 30         int tmp=t[i]-1+k;
 31         k=tmp/base[i];
 32         t[i]=tmp%base[i]+1;
 33     }
 34     t[5]+=k;
 35 }
 36 int to_int (string str) {
 37     int ans=0;
 38     for (int i=0;i<str.size();i++)
 39         ans=ans*10+str[i]-'0';
 40     return ans;
 41 }
 42 void get_t(string str,int* x) {
 43     x[5]=to_int(str.substr(0,4));
 44     for (int i=3,pos=4;i>=0;i--,pos+=2) 
 45         x[i]=to_int(str.substr(pos,2));
 46 }
 47 bool is_same (int *x,int *y) {
 48     for (int i=0;i<=3;i++)
 49         if (x[i]!=y[i]) return 0;
 50     return x[5]==y[5];
 51 }
 52 vector <string> split(string str,const char flag=',') {
 53     vector <string> ans;
 54     istringstream  iss(str);
 55     while (getline(iss,str,flag)) {
 56         if (str.size()) {
 57             for (int i=0;i<str.size();i++)
 58                 if (str[i]>='A'&&str[i]<='Z') 
 59                     str[i]=str[i]-'A'+'a';
 60             ans.push_back(str);
 61         }
 62     }
 63     return ans;
 64 }
 65 int get_num (string str) {
 66     if (str[0]>='0'&&str[0]<='9')  return to_int(str); 
 67     return mapp[str];
 68 }
 69 void get_isok(string str,bool* isok) {
 70     if (str=="*") {
 71         for (int i=0;i<=60;i++) isok[i]=1;
 72         return ;
 73     }
 74     vector <string> sv=split(str);
 75     for (int i=0;i<sv.size();i++) {
 76         string tmp=sv[i];
 77         int pos=tmp.find("-");
 78         if (pos==-1)  isok[get_num(tmp)]=1;
 79         else          {
 80             string s1=tmp.substr(0,pos),s2=tmp.substr(pos+1);
 81             int l1=get_num(s1),l2=get_num(s2);
 82             for (int j=l1;j<=l2;j++)
 83                 isok[j]=1;
 84         }
 85     }
 86 }
 87 bool isok(node x) {
 88     for (int i=0;i<5;i++)
 89         if (!x.isok[i][t[i]]) return 0;
 90     return 1;
 91 }
 92 int main ()
 93 {
 94     ios::sync_with_stdio(false);
 95     for (int i=1;i<=12;i++) mapp[smon[i]]=i;
 96     for (int i=0;i<7;i++)   mapp[swek[i]]=i;
 97     int n; string _s,_e; 
 98     cin>>n>>_s>>_e;
 99     get_t(_s,ts); get_t(_e,te);
100     t[1]=ts[1]; t[0]=ts[0];
101     while (!is_same(t,ts)) dd(24*60);
102     for (int i=1;i<=n;i++) {
103         for (int j=0;j<5;j++) {
104             string str; cin>>str;
105             get_isok(str,ord[i].isok[j]);
106         }
107         cin>>ord[i].name;
108     }
109     while (!is_same(t,te)) {
110         for (int i=1;i<=n;i++)
111             if (isok(ord[i])) {
112                 cout<<t[5];
113                 for (int j=3;j>=0;j--)
114                     cout<<setw(2)<<setfill('0')<<t[j];
115                 cout<<" "<<ord[i].name<<"\n";
116             }
117         dd(1);
118     }
119     return 0;
120 }