BestCoder Round #69 (div.2)(hdu5611)
Baby Ming and phone number
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1501 Accepted Submission(s): 399
He thinks normal number can be sold for b yuan, while number with following features can be sold for a yuan.
1.The last five numbers are the same. (such as 123-4567-7777)
2.The last five numbers are successive increasing or decreasing, and the diffidence between two adjacent digits is 1. (such as 188-0002-3456)
3.The last eight numbers are a date number, the date of which is between Jar 1st, 1980 and Dec 31th, 2016. (such as 188-1888-0809,means August ninth,1888)
Baby Ming wants to know how much he can earn if he sells all the numbers.
In the second line there is a positive integer n, which means how many numbers Baby Ming has.(no two same phone number)
In the third line there are 2 positive integers a,b, which means two kinds of phone number can sell a yuan and b yuan.
In the next n lines there are n cell phone numbers.(|phone number|==11, the first number can’t be 0)
1≤T≤30,b<1000,0<a,n≤100,000
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD doublea
#define MAX 100100
#define mod 10007
using namespace std;
int s[MAX][15];
char s1[MAX][15];
int op1[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int op2[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int five(int x)//判断后五位
{
int i,j;
char y=s[x][6];
int flag=1;
for(i=7;i<11;i++)
{
if(s[x][i]!=y)
{
flag=0;
break;
}
}
if(flag==1) return 1;
flag=1;
for(i=7;i<11;i++)
{
if(s[x][i]!=s[x][i-1]+1)
{
flag=0;
break;
}
}
if(flag==1) return 1;
else return 0;
}
int judge(int x)//判断闰年
{
if((x%4==0&&x%100!=0)||x%400==0)
return 1;
else return 0;
}
int eight(int x) //判断后八位
{
int i,j;
int flag=1;
int sum=s[x][3];
int mouth=s[x][7]*10+s[x][8];
int day=s[x][9]*10+s[x][10];
for(i=4;i<=6;i++)
sum=sum*10+s[x][i];
if(sum<1980||sum>2016||mouth<1||mouth>12)
return 0;
if(sum==1980)
{
if(mouth<7||mouth>12)
return 0;
if(day==0||day>op1[mouth])
return 0;
}
if(judge(sum))
{
if(day==0||day>op2[mouth])
return 0;
}
if(!judge(sum))
{
if(day==0||day>op1[mouth])
return 0;
}
return 1;
}
int main()
{
int t,i,j,n,m;
LL ans,a,b;
scanf("%d",&t);
while(t--)
{
ans=0;
scanf("%d",&n);
scanf("%lld%lld",&a,&b);
for(i=1;i<=n;i++)
{
scanf("%s",s1[i]);
for(j=0;j<11;j++)
{
s[i][j]=s1[i][j]-'0';
}
}
for(i=1;i<=n;i++)
{
if(five(i))
ans+=a;
else if(eight(i))
ans+=a;
else ans+=b;
}
printf("%lld\n",ans);
}
return 0;
}
今天又仔细看了这道题,发现昨天少考虑一种情况,题目有三个要求1、后五位数字一样 2、后五位数字连续(可以递增也可以递减 忘记考虑递减的情况了)3、后八位可以组成一个日期,日期范围是1980年01月01号到2016年12月31号
接下来就主要处理每个月份对应时间以及闰年即可
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD doublea
#define MAX 100100
#define mod 10007
using namespace std;
int s[MAX][15];
char s1[MAX][15];
int op[13]={0,31,0,31,30,31,30,31,31,30,31,30,31};
//int op2[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int five(int x)//判断后五位
{
int i,j;
int y=s[x][6];
int flag=1;
for(i=7;i<11;i++)
{
if(s[x][i]!=y)
{
flag=0;
break;
}
}
if(flag==1) return 1;
flag=1;
for(i=7;i<11;i++)
{
if(s[x][i]!=s[x][i-1]+1)
{
flag=0;
break;
}
}
if(flag==1) return 1;
flag=1;
for(i=7;i<11;i++)
{
if(s[x][i]!=s[x][i-1]-1)
{
flag=0;
break;
}
}
if(flag==1) return 1;
else return 0;
}
int judge(int x)//判断闰年
{
if((x%4==0&&x%100!=0)||x%400==0)
return 1;
else return 0;
}
int eight(int x) //判断后八位
{
int i,j;
int flag=1;
int sum=s[x][3];
int mouth=s[x][7]*10+s[x][8];
int day=s[x][9]*10+s[x][10]; for(i=4;i<=6;i++)
sum=sum*10+s[x][i];
// printf("%d*\n",sum);
if(mouth==2)
{
if(judge(sum))
op[2]=29;
else
op[2]=28;
}
if(sum>=1980&&sum<=2016&&mouth>=1&&mouth<=12&&day>=1&&day<=op[mouth])
return 1;
else return 0;
}
int main()
{
int t,i,j,n,m;
__int64 ans,a,b;
scanf("%d",&t);
while(t--)
{
ans=0;
scanf("%d",&n);
scanf("%I64d%I64d",&a,&b);
for(i=1;i<=n;i++)
{
scanf("%s",s1[i]);
for(j=0;j<11;j++)
s[i][j]=s1[i][j]-'0';
}
for(i=1;i<=n;i++)
{
if(five(i))
ans+=a;
else if(eight(i))
ans+=a;
else ans+=b;
}
printf("%I64d\n",ans);
}
return 0;
}
BestCoder Round #69 (div.2)(hdu5611)的更多相关文章
- BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)
Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...
- Codeforces Round #219 (Div. 1)(完全)
戳我看题目 A:给你n个数,要求尽可能多的找出匹配,如果两个数匹配,则ai*2 <= aj 排序,从中间切断,分成相等的两半后,对于较大的那一半,从大到小遍历,对于每个数在左边那组找到最大的满足 ...
- BestCoder Round #73 (div.2)(hdu 5630)
Rikka with Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- BestCoder Round #71 (div.2) (hdu 5621)
KK's Point Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- BestCoder Round #71 (div.2) (hdu 5620 菲波那切数列变形)
KK's Steel Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- Codeforces Round #544 (Div. 3) (补)
D:没有注意到a==0&&b==0的情况,把自己卡崩了.对于数学公式推导一定要注意关于0的特殊情况,不可以少 #include <iostream> #include &l ...
- Codeforces Round #249 (Div. 2) (模拟)
C. Cardiogram time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #613 (Div. 2) (A-E)
A略 直接求和最大的子序列即可(注意不能全部选中整个子序列) or #include<bits/stdc++.h> using namespace std; void solve(){ i ...
随机推荐
- 关于<img>标签与文字垂直居中
要让左边的图片与后面的文字居中,如下效果 HTML代码: <img class="iconCls" alt="最新客户端" src="${bas ...
- HDU 1280 前m大的数【哈希入门】
题意:中文的题目= =将各种组合可能得到的和作为下标,然后因为不同组合得到的和可能是一样的, 所以再用一个数组num[]数组,就可以将相同的和都记录下来 #include<iostream> ...
- CSS强制英文换行
1. word-break:break-all;只对英文起作用,以字母作为换行依据 2. word-wrap:break-word; 只对英文起作用,以单词作为换行依据 3. white-space: ...
- ffmepg 指定RTSP网络连接模式UDP还是TCP
AVFormatContext *formatCtx = NULL; formatCtx = avformat_alloc_context(); AVDictionary* options = NUL ...
- Oracle 11g AMM与ASMM切换
现在的Oracle正在往智能化方向发展.如果我们现在找一些8i/9i时代的Oracle书籍,怎么样配置合适的数据库各内存池大小是非常重要的话题.但是进入10g之后,自动内存池调节成为一个重要Oracl ...
- Delphi DecodeDate和EncodeDate 拆分和聚合时间函数的用法
SysUtilsprocedure DecodeData(Date: TDateTime; var Year, Month, Day: Word);DecodeDate打断TdateTime成为年月日 ...
- Generate Parentheses java实现
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
- codeforces 691D Swaps in Permutation DFS
这个题刚开始我以为是每个交换只能用一次,然后一共m次操作 结果这个题的意思是操作数目不限,每个交换也可以无限次 所以可以交换的两个位置连边,只要两个位置连通,就可以呼唤 然后连通块内排序就好了 #in ...
- codeforces 687C - The Values You Can Make 简单dp
题意:一个数组a[i],你可以挑出若干个数(只能挑一次)加起来等于k, 针对每一种方案,你可以选出这若干个数的子集来组合新数 最后所有的方案能组合出多少种数 分析:一看数据范围n,k<=500 ...
- POJ 3621 Sightseeing Cows 01分数规划,最优比例环的问题
http://www.cnblogs.com/wally/p/3228171.html 题解请戳上面 然后对于01规划的总结 1:对于一个表,求最优比例 这种就是每个点位有benefit和cost,这 ...