Skip to main content
  1. Posts/

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

·2 mins
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

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}

Related

uva 537 Artificial Intelligence?

·2 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid;=8&page;=show_problem&problem;=478 题意:给出一段文字。。其中包含了 P,U,I(功率,电压,电流)中的两个。。求第三个。 思路:字符串处理。。第一次用vim复制整段代码。。命令模式下按v,然后光标扫过的区域都会选中,按y就就复制到剪贴板了。。 所以虽然代码写了300行但只有100行是需要写的。。200行复制改下就好== WA了两次。。一次是因为I写成了小写。。另一次是因为多组数据记得初始化多次。

uva 10010 - Where's Waldorf?

·3 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=951 题意:给出一个由大小写字母组成的二维maze…给出k个询问。每个询问一个单词。问能否在maze中找到这个单词。不区分大小写。输出开头字母的坐标(从1开始)。如果有多组输出最上面的。如果还有多组,输出最左边的。数据保证至少有一组。 思路:直接找就好了。。。坑的地方是。。。格式。。数据组数之后会有一个空行。然后每两组读入数据之间会有一个空行。。输出的时候每两组数据之间也有一个空行。

uva 401 Palindromes

·2 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=96&page=show_problem&problem=342 题意:问一个字符串是不是回文串,是不是镜像串。镜像串的意思是。。从镜子里看还一样。。给定了一些存在镜像的字母和数字。。 思路:回文串的判断用c++的string要更容易一些。。直接reverse一下。。判断是否相等就行。。。然后需要注意的是。。如果某个字符补存在镜像那么一定不是镜像串

uva 10420 - List of Conquests

·1 min
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid;=8&page;=show_problem&problem;=1361 题意:给n个带空格的字符串,第一个单词是国家,统计每个国家的字符串的个数。 思路:getline函数。。。find函数。。。substr函数。。。map…..

cf 611 A||codeforces goodbye 2015 C. New Year and Domino

·1 min
http://codeforces.com/contest/611/problem/C 题意:给出一个n*m的地图,.表示可以空,#表示墙。一个东西需要占两个相邻的格子,问给定一个矩形,放一个东西的方案数。 思路:q很大。。应该是先预处理出来直接调用答案。。。计数问题累加性。。应该是前缀和之类。。需要做的就是怎么标记。。我的做法是竖着放和横着放的个数分开来存。从左往右从上往下,每次标记到后一个点。然后二维的前缀和。然后每次询问的时候,去掉最上边和最左边两条边界上对应的多加的点。