HDOJ 5611 Baby Ming and phone number(シミュレーション)

4849 ワード

Baby Ming and phone number
Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 222    Accepted Submission(s): 68
Problem Description
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.
 
Input
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 
Output
How much Baby Nero can earn.
 
Sample Input

   
   
   
   
1 5 100000 1000 12319990212 11111111111 22222223456 10022221111 32165491212

 
Sample Output
302000
タイトル:
            ,  ,         。
                a  ,     ,   b  。
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 )
                    。

考え方:直接シミュレーションすればいい、月と日付の判断に注意するだけで、結果が爆発する.
acコード:
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stack>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#define MAXN 1010000
#define LL long long
#define ll __int64
#define INF 0xfffffff
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
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';
            int bz=0;
            if(s[10]==s[9]&&s[9]==s[8]&&s[8]==s[7]&&s[7]==s[6])
            ans+=a,bz=1;
            //printf("bz=%d
",bz); 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]))&&bz==0) { 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,bz=1; } //printf("bz=%d
",bz); 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]; //printf("y=%d m=%d d=%d
",year,month,day); if(check(year,month,day)&&bz==0) ans+=a,bz=1; if(bz==0) ans+=b; } printf("%I64d
",ans); } return 0; }