【Codeforces World Finals】做题总结(模拟)

Codeforces World Finals

2000ms 262144K

Description:

The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for training and competing. Recently Copa understood that to conquer the world he needs to organize the world Codeforces tournament. He hopes that after it the brightest minds will become his subordinates, and the toughest part of conquering the world will be completed.

The final round of the Codeforces World Finals 20YY is scheduled for DD.MM.YY, where DD is the day of the round, MM is the month and YY are the last two digits of the year. Bob is lucky to be the first finalist form Berland. But there is one problem: according to the rules of the competition, all participants must be at least 18 years old at the moment of the finals. Bob was born on BD.BM.BY. This date is recorded in his passport, the copy of which he has already mailed to the organizers. But Bob learned that in different countries the way, in which the dates are written, differs. For example, in the US the month is written first, then the day and finally the year. Bob wonders if it is possible to rearrange the numbers in his date of birth so that he will be at least 18 years old on the day DD.MM.YY. He can always tell that in his motherland dates are written differently. Help him.

According to another strange rule, eligible participant must be born in the same century as the date of the finals. If the day of the finals is participant’s 18-th birthday, he is allowed to participate.

As we are considering only the years from 2001 to 2099 for the year of the finals, use the following rule: the year is leap if it’s number is divisible by four.

Input:
The first line contains the date DD.MM.YY, the second line contains the date BD.BM.BY. It is guaranteed that both dates are correct, and YY and BY are always in [01;99].

It could be that by passport Bob was born after the finals. In this case, he can still change the order of numbers in date.

Output:
If it is possible to rearrange the numbers in the date of birth so that Bob will be at least 18 years old on the DD.MM.YY, output YES. In the other case, output NO.

Each number contains exactly two digits and stands for day, month or year in a date. Note that it is permitted to rearrange only numbers, not digits.

Sample Input:

01.01.98
01.01.80

Sample Output:

YES

Sample Input:

20.10.20
10.02.30

Sample Output:

NO

Sample Input:

28.02.74
28.02.64

Sample Output:

NO

题意:给出两个日期,由于每个国家日期写法不同,因此第二个日期可以年月日任意交换,要求找出是否存在有已满18岁的情况。
思路:写出所有的情况,看是否满足对应年月日的要求。
ac代码:(本人写的比较麻烦,可以直接列举所有情况不必用dfs,直接列举要方便得多,这里就不再演示)

#include<iostream>
#include<algorithm>
using namespace std;
int dd,mm,yy,flag;
int a[4],b[4],book[4];
int y1[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int y2[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int judge(int d,int m,int y)
{
	if(y<1||y>99)return 0;
	if(m<1||m>12)return 0;
	if(y%4)
	{
		if(d>y2[m])
		return 0;
	}
	if(y%4==0)
	{
		if(d>y1[m])
		return 0;
	}
	if(yy-y>18)return 1;
	if(yy-y==18&&mm-m>0)return 1;
	if(yy-y==18&&mm-m==0&&dd-d>=0)return 1;
	return 0;
}
void dfs(int step)
{
	if(step==4&&flag==0)//保证flag变为1后不会再变为0
	{
		flag=judge(b[1],b[2],b[3]);
		return;
	}
	for(int i=1;i<=3;i++)
	{
		if(book[i]==0)
		{
			b[step]=a[i];
			book[i]=1;
			dfs(step+1);
			book[i]=0;
		}
	}
	return ;
}

int main()
{
	flag=0;
	scanf("%d.%d.%d",&dd,&mm,&yy);
	scanf("%d.%d.%d",&a[1],&a[2],&a[3]);
	dfs(1);
	if(flag)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
}

均为本人理解,如有纰漏欢迎指出。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值