hdu 5611 || BC #69 div2 1002 Baby Ming and phone number

http://acm.hdu.edu.cn/showproblem.php?pid=5611 题意:给出n个电话号码(长度为11的字符串),满足特殊条件的价格为a,否则为b.特殊条件为最后5位数字一样,最后5位严格递增或者严格递减,最后8位是一个1980年1月一日到2016年12月31日的合法日期。问最后的价值。

思路:直接搞….结果死在cin了。。。原来3E6的cin就会TLE。。。。。q神说1E5有的也会tle…..

所以方案是,能不用cin就不要用cin…

如果要读string的话。。。一个解决办法是把数据流同步关掉(是叫这个名字吗。。)

std::ios::sync_with_stdio(false); 会快很多。。。

还有一个办法是先用scanf读 char[] 然后再转化? 没试过== 哦哦还要注意要判闰年。 还有要开long long

  1/* ***********************************************
  2Author :111qqz
  3Created Time :2016年01月23日 星期六 18时58分10秒
  4File Name :code/bc/#69/1002.cpp
  5************************************************ */
  6
  7#include <cstdio>
  8#include <cstring>
  9#include <iostream>
 10#include <algorithm>
 11#include <vector>
 12#include <queue>
 13#include <set>
 14#include <map>
 15#include <string>
 16#include <cmath>
 17#include <cstdlib>
 18#include <ctime>
 19#define fst first
 20#define sec second
 21#define lson l,m,rt<<1
 22#define rson m+1,r,rt<<1|1
 23#define ms(a,x) memset(a,x,sizeof(a))
 24typedef long long LL;
 25#define pi pair < int ,int >
 26#define MP make_pair
 27
 28using namespace std;
 29const double eps = 1E-8;
 30const int dx4[4]={1,0,0,-1};
 31const int dy4[4]={0,-1,1,0};
 32const int inf = 0x3f3f3f3f;
 33int n;
 34string str;
 35LL a,b;
 36bool good1(string x)
 37{
 38    int len = x.length();
 39    if (x[10]==x[9]&&x[9]==x[8]&&x[8]==x[7]&&x[7]==x[6]&&x[6]==x[10]) return true;
 40    return false;
 41}
 42bool good2(string x)
 43{
 44    int p = 0 ;
 45    for ( int i =  6 ; i <=9  ;i++)
 46    {
 47	if (x[i+1]-x[i]==-1) p++;
 48    }
 49    if (p==4) return true;
 50    p =  0;
 51    for ( int i = 6 ; i <= 9 ; i++)
 52    {
 53	if (x[i+1]-x[i]==1) p++;
 54    }
 55    if (p==4) return true;
 56
 57    return false;
 58}
 59
 60bool runnian (int ye)
 61{
 62    if (ye0==0) return true;
 63    if (ye%4==0&&ye0!=0) return true;
 64    return false;
 65}
 66bool good3( string x)
 67{
 68    int year;
 69    string s_year;
 70    int mon;
 71    string s_mon;
 72    int day;
 73    string s_day;
 74    char ye[12],mo[10],da[10];
 75
 76    s_year = x.substr(3,4);
 77  //  cout<<"s_year:"<<s_year<<endl;
 78    sscanf(s_year.c_str(),"%d",&year);
 79    s_mon  = x.substr(7,2);
 80    sscanf(s_mon.c_str(),"%d",&mon);
 81    s_day = x.substr(9,2);
 82    sscanf(s_day.c_str(),"%d",&day);
 83//    cout<<"year:"<<year<<" month:"<<mon<<" day:"<<day<<endl;
 84    if (year<1980||year>2016) return false;
 85      if (mon<1||mon>12) return false;
 86    set<int>bigmon;
 87    bigmon.insert(1);  
 88    bigmon.insert(3);
 89       bigmon.insert(5);
 90   bigmon.insert(7);  
 91      bigmon.insert(8);
 92   bigmon.insert(10);
 93   bigmon.insert(12);
 94   bool run = runnian(year);
 95   if (bigmon.count(mon))
 96   {
 97       if (day<1||day>31) return false;
 98   }
 99   else
100    {
101	if (mon==2)
102  	{
103	    if (run)
104	    {
105		if (day<1||day>29) return false;
106	    }
107	    else
108	    {
109		if (day<1||day>28) return false;
110	    }
111	}
112	else
113	{
114	    if (day<1||day>30) return false;
115	}
116    }
117   return true;
118
119}
120
121int main()
122{
123	#ifndef  ONLINE_JUDGE 
124	freopen("code/in.txt","r",stdin);
125  #endif
126	std::ios::sync_with_stdio(false);
127	int T;
128	cin>>T;
129	while (T--)
130	{
131	    cin>>n;
132	    cin>>a>>b;
133	    LL ans = 0 ;
134	    for ( int i = 0 ; i < n ; i++)
135	    {
136		cin>>str;
137		if (good1(str)||good2(str)||good3(str))
138		    ans +=a;
139		else ans+=b;
140//		cout<<"ans:"<<ans<<endl;
141	    }
142	    cout<<ans<<endl;
143
144	}
145
146
147
148  #ifndef ONLINE_JUDGE  
149  fclose(stdin);
150  #endif
151    return 0;
152}