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

/* ***********************************************
Author :111qqz
Created Time :2016年01月23日 星期六 18时58分10秒
File Name :code/bc/#69/1002.cpp
************************************************ */
 1#include <cstdio>
 2#include <cstring>
 3#include <iostream>
 4#include <algorithm>
 5#include <vector>
 6#include <queue>
 7#include <set>
 8#include <map>
 9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
 1using namespace std;
 2const double eps = 1E-8;
 3const int dx4[4]={1,0,0,-1};
 4const int dy4[4]={0,-1,1,0};
 5const int inf = 0x3f3f3f3f;
 6int n;
 7string str;
 8LL a,b;
 9bool good1(string x)
10{
11    int len = x.length();
12    if (x[10]==x[9]&&x[9]==x[8]&&x[8]==x[7]&&x[7]==x[6]&&x[6]==x[10]) return true;
13    return false;
14}
15bool good2(string x)
16{
17    int p = 0 ;
18    for ( int i =  6 ; i <=9  ;i++)
19    {
20	if (x[i+1]-x[i]==-1) p++;
21    }
22    if (p==4) return true;
23    p =  0;
24    for ( int i = 6 ; i <= 9 ; i++)
25    {
26	if (x[i+1]-x[i]==1) p++;
27    }
28    if (p==4) return true;
    return false;
}
 1bool runnian (int ye)
 2{
 3    if (ye0==0) return true;
 4    if (ye%4==0&&ye0!=0) return true;
 5    return false;
 6}
 7bool good3( string x)
 8{
 9    int year;
10    string s_year;
11    int mon;
12    string s_mon;
13    int day;
14    string s_day;
15    char ye[12],mo[10],da[10];
 1    s_year = x.substr(3,4);
 2  //  cout<<"s_year:"<<s_year<<endl;
 3    sscanf(s_year.c_str(),"%d",&year);
 4    s_mon  = x.substr(7,2);
 5    sscanf(s_mon.c_str(),"%d",&mon);
 6    s_day = x.substr(9,2);
 7    sscanf(s_day.c_str(),"%d",&day);
 8//    cout<<"year:"<<year<<" month:"<<mon<<" day:"<<day<<endl;
 9    if (year<1980||year>2016) return false;
10      if (mon<1||mon>12) return false;
11    set<int>bigmon;
12    bigmon.insert(1);  
13    bigmon.insert(3);
14       bigmon.insert(5);
15   bigmon.insert(7);  
16      bigmon.insert(8);
17   bigmon.insert(10);
18   bigmon.insert(12);
19   bool run = runnian(year);
20   if (bigmon.count(mon))
21   {
22       if (day<1||day>31) return false;
23   }
24   else
25    {
26	if (mon==2)
27  	{
28	    if (run)
29	    {
30		if (day<1||day>29) return false;
31	    }
32	    else
33	    {
34		if (day<1||day>28) return false;
35	    }
36	}
37	else
38	{
39	    if (day<1||day>30) return false;
40	}
41    }
42   return true;
}
 1int main()
 2{
 3	#ifndef  ONLINE_JUDGE 
 4	freopen("code/in.txt","r",stdin);
 5  #endif
 6	std::ios::sync_with_stdio(false);
 7	int T;
 8	cin>>T;
 9	while (T--)
10	{
11	    cin>>n;
12	    cin>>a>>b;
13	    LL ans = 0 ;
14	    for ( int i = 0 ; i < n ; i++)
15	    {
16		cin>>str;
17		if (good1(str)||good2(str)||good3(str))
18		    ans +=a;
19		else ans+=b;
20//		cout<<"ans:"<<ans<<endl;
21	    }
22	    cout<<ans<<endl;
	}
1  #ifndef ONLINE_JUDGE  
2  fclose(stdin);
3  #endif
4    return 0;
5}