博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1370: Biorhythms
阅读量:4686 次
发布时间:2019-06-09

本文共 3903 字,大约阅读时间需要 13 分钟。

1

0 0 0 0

0 0 0 100
5 20 34 325
4 5 6 7
283 102 23 320
203 301 203 40
-1 -1 -1 -1

Case 1: the next triple peak occurs in 21252 days.

Case 2: the next triple peak occurs in 21152 days.
Case 3: the next triple peak occurs in 19575 days.
Case 4: the next triple peak occurs in 16994 days.
Case 5: the next triple peak occurs in 8910 days.
Case 6: the next triple peak occurs in 10789 days.

分析

可以维护一个bool数组暴力模拟,也可以中国剩余定理。

(n+d)%23=a,(n+d)%28=b,(n+d)%33=c;

所以,n=(33*28*6*p+23*33*19*e+1288*i)%lcm(23,28,33)=n+d

即ans=(5544p+14421e+1288i-d)%21252

#include 
#include
#include
#include
#include
#define range(i,a,b) for(int i=a;i<=b;++i)#define rerange(i,a,b) for(int i=a;i>=b;--i)#define LL long long#define CLS(arr) memset(arr,0,sizeof(arr))using namespace std;bool days[21255];int p,e,i,d;void solve(){ int ans,cnt=0; while(cin>>p>>e>>i>>d,p!=-1&&e!=-1&&i!=-1&&d!=-1){ CLS(days); for(int k=p;k<=21252;k+=23)days[k]=true; range(k,0,21252)days[k]=(k-e)%28?false:days[k]?true:false; range(k,0,21252)days[k]=(k-i)%33?false:days[k]?true:false; range(k,d+1,21252)if(days[k]){ans=k;break;} cout<<"Case "<<++cnt<<": the next triple peak occurs in "<
<<" days."<
View Code

 

转载于:https://www.cnblogs.com/Rhythm-/p/9322606.html

你可能感兴趣的文章
Ubuntu-tomcat7目录
查看>>
189. Rotate Array
查看>>
使用ASP.Net WebAPI构建REST服务(六)——Self-Host
查看>>
asp.net 的三种开发模式
查看>>
Android 交叉编译 IPerf3
查看>>
Android原生Gallery关于图像Orientation的问题
查看>>
Android开发之ViewPager
查看>>
【NOIP2017】列队【可持久化线段树】
查看>>
python学习——通过while循环语句实现九九乘法表的四种表达方式
查看>>
[解题报告] 100 - The 3n + 1 problem
查看>>
MvvmCross[翻译] 使用Xamarin与MvvmCross完成一个跨平台App
查看>>
Entity Framework 学习高级篇1—改善EF代码的方法(上)
查看>>
027-chown命令
查看>>
Python 线程、进程和协程
查看>>
赛普系统自动拨号
查看>>
platform_device与platform_driver
查看>>
[iOS] iPad与iPhone上各种标准控件的大小
查看>>
动态规划(游船费用问题)
查看>>
[原创]Windows利用BitNami搭建Redmine
查看>>
Mybatis逆向工程配置文件详细介绍(转)
查看>>