您的位置:首页 > 其它

HDOJ 5611-Baby Ming and phone number【模拟】

2016-01-28 19:56 246 查看

Baby Ming and phone number

Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 958 Accepted Submission(s): 282

[align=left]Problem Description[/align]
Baby Ming collected lots of cell phone numbers, and he wants to sell them for money.

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.

[align=left]Input[/align]
In the first line contains a single positive integer
T,
indicating number of test case.

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

[align=left]Output[/align]
How much Baby Nero can earn.

[align=left]Sample Input[/align]

1
5
100000 1000
12319990212
11111111111
22222223456
10022221111
32165491212


[align=left]Sample Output[/align]

302000


[align=left]Source[/align]
BestCoder Round #69 (div.2)

[align=left]解题思路:[/align]
[align=left]题目大意就是:[/align]

铭宝宝收集了很多手机号码,没错,他想卖手机号码赚钱。
他觉得有如下性质的手机号码可以卖aaa元钱,其他的号码,只能卖bbb元钱。
1.末5位数字相同(比如123-4567-7777)
2.末5位是连续递增或者连续递减的,且相邻数位相差1的数(比如188-0002-3456)
3.末8位是一个表示日期的数字,并且表示的日期在1980年1月1日至2016年12月31日内(比如188-1888-0809表示1888年8月9日)
铭宝宝想知道卖掉所有的手机号码能赚多少钱。

输入T(T≤30)T(T \leq 30)T(T≤30)表示TTT组测试数据
输入n(n≤100,000)n(n \leq 100,000)n(n≤100,000)表示铭宝宝有nnn张手机号码(没有相同的手机号码)
输入222个正整数a,ba, ba,b, 表示两种类型的手机号码分别能卖aaa元和bbb元(b≤1000,a≤100,000)(b \leq 1000, a \leq 100,000)(b≤1000,a≤100,000)
接下去nnn行,每行输入111个手机号码(|phonenumber|==11,首位非0)

所以简单模拟就行了,注意最后的结果会超int.

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define ll long long
using namespace std;
char str[15];
int s[15];
int m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int check(int a,int b,int c)
{
if(a<1980||a>2016)
return 0;
if(b<1||b>12)
return 0;
if(c<1||c>31)
return 0;
if(a%400==0||(a%4==0&&a%100!=0))
{
if(b==2)
{
if(c<=29)
return 1;
else
return 0;
}
else
{
if(c>m[b])
return 0;
else
return 1;
}
}
else
{
if(b==2)
{
if(c<=28)
return 1;
else
return 0;
}
else
{
if(c>m[b])
return 0;
else
return 1;
}
}
}
int main()
{
int t,a,b,c;
int i,j,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
scanf("%d%d",&a,&b);
ll ans=0;
while(n--)
{
scanf("%s",str);
int len=strlen(str);
for(i=0;i<len;i++)
s[i]=str[i]-'0';
if(s[10]==s[9]&&s[9]==s[8]&&s[8]==s[7]&&s[7]==s[6])
{
ans+=a;
continue;
}
if((s[10]>s[9]&&s[9]>s[8]&&s[8]>s[7]&&s[7]>s[6])||(s[10]<s[9]&&s[9]<s[8]&&s[8]<s[7]&&s[7]<s[6]))
{
if(abs(s[10]-s[9])==1&&abs(s[9]-s[8])==1&&abs(s[8]-s[7])==1&&abs(s[7]-s[6])==1)
{
ans+=a;
continue;
}
}
int year=s[3]*1000+s[4]*100+s[5]*10+s[6];
int month=s[7]*10+s[8];
int day=s[9]*10+s[10];
if(check(year,month,day))
{
ans+=a;
continue;
}
ans+=b;
}
printf("%I64d\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: