zoukankan      html  css  js  c++  java
  • 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


    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)

    1T30,b<1000,0<a,n100,000
     
    Output
    How much Baby Nero can earn.
     
    Sample Input
    1
    5
    100000 1000
    12319990212
    11111111111
    22222223456
    10022221111
    32165491212
     
    Sample Output
    302000
     
    分步判断是否符合题意即可   休要细心,代码未ac  还有细节未处理好  先记录下来
    #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
    ",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*
    ",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
    ",ans);
    	}
    	return 0;
    } 
    

      

  • 相关阅读:
    Unity3d-反编译C#和提取资源
    让年轻程序员少走弯路的14个忠告
    Objective-C的陷阱与缺陷
    Android中处理Touch Icon的方案
    常用的Java代码汇总
    cocos2dx游戏资源加密之XXTEA
    9种常见的Android开发错误及解决方案
    Linux 系统常用命令汇总(三) 用户和用户组管理
    Linux 系统常用命令汇总(四) 程序和资源管理
    Linux 系统常用命令汇总(二) vi 文本编辑
  • 原文地址:https://www.cnblogs.com/tonghao/p/5229062.html
Copyright © 2011-2022 走看看