列表

详情


NC200037. Days passing

描述

LYX is the most handsome boy  in HNU who likes math very much. One day his girlfriend JY asked LYX a simple problem: "Today is Sunday , what day of week will it be after 400^600 days, and what about 120^714?"  LYX is very smart and answered: It will be Monday and Monday.
Now LYX abstracts this problem as follows:
'a' denote the day of week today('a' belong to {Mon, Tue, Wed, Thu,  Fri, Sat, Sun}), what is the date after N^M(1<=N<10^10000,6<=M<10000) days ? Where M is exactly divided by 6.

输入描述

There is 1 line, 1 string, 2 integers,
there are a, N and M, separated by a space.

输出描述

Output a string(Mon, Tue, Wed, Thu,  Fri, Sat, Sun), the day of the week.

示例1

输入:

Sun 2 12

输出:

Mon

说明:

The day(Sunday) after 212(4,096) days will be  Monday.

示例2

输入:

Wed 7 6

输出:

Wed

说明:

The day(Wednesday) after 76(117,649) days will be Wednesday.

示例3

输入:

Thu 1 6

输出:

Fri

说明:

The day(Thursday) after 16(1) days will be Friday.

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 6ms, 内存消耗: 488K, 提交时间: 2020-01-11 14:05:43

#include <bits/stdc++.h>
using namespace std;
const int N=1e4+5;
char a[N],s[5],t[7][5]={"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
int main() {
	int n=0,m;
	scanf("%s%s%d",s,a,&m);
	for(int i=0;a[i];i++) {
		n=(n*10+a[i]-'0')%7;
	}
	int ans=1;
	for(int i=0;i<m;i++) {
		ans=ans*n%7;
	}
	int now;
	for(int i=0;i<7;i++) {
		if(strcmp(t[i],s)==0) now=i;
	}
	now=(now+ans)%7;
	printf("%s\n",t[now]);
	return 0;
}

C++(clang++11) 解法, 执行用时: 3ms, 内存消耗: 376K, 提交时间: 2021-03-07 11:35:54

#include<bits/stdc++.h>
using namespace std;
int b,c;
string s,a,s0[]={"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
map<string,int>m;
int main()
{
	m["Mon"]=0,m["Tue"]=1,m["Wed"]=2,m["Thu"]=3,m["Fri"]=4,m["Sat"]=5,m["Sun"]=6;
	cin>>s>>a>>b;
	for(int i=0;i<a.size();++i)
	c*=10,c+=a[i]-'0',c%=7;
	cout<<s0[(m[s]+(c%7+6)/7)%7];
	return 0; 
}

Python3(3.5.2) 解法, 执行用时: 32ms, 内存消耗: 3400K, 提交时间: 2020-01-14 13:25:34

res=['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
s,n,m=input().split()
s=res.index(s)
if pow(int(n),int(m)//6,7)==0:
    print(res[s])
else:
    print(res[(s+1)%7])

pypy3(pypy3.6.1) 解法, 执行用时: 59ms, 内存消耗: 18652K, 提交时间: 2020-01-11 15:56:42

arr=input().split()
d=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]
n=int(arr[1])
m=int(arr[2])
r=((n%7)**m)%7
ini=d.index(arr[0])
#print(ini)
print(d[(ini+r)%7])

上一题