poj1006

『杭电1370』Biorhythms Problem Description Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they have periods of lengths 23, 28, and 33 days, re 阅读详情
Biorhythms

Description

Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they have periods of lengths 23, 28, and 33 days, respectively. There is one peak in each period of a cycle. At the peak of a cycle, a person performs at his or her best in the corresponding field (physical, emotional or mental). For example, if it is the mental curve, thought processes will be sharper and concentration will be easier. 
Since the three cycles have different periods, the peaks of the three cycles generally occur at different times. We would like to determine when a triple peak occurs (the peaks of all three cycles occur in the same day) for any person. For each cycle, you will be given the number of days from the beginning of the current year at which one of its peaks (not necessarily the first) occurs. You will also be given a date expressed as the number of days from the beginning of the current year. You task is to determine the number of days from the given date to the next triple peak. The given date is not counted. For example, if the given date is 10 and the next triple peak occurs on day 12, the answer is 2, not 3. If a triple peak occurs on the given date, you should give the number of days to the next occurrence of a triple peak. 

Input

You will be given a number of cases. The input for each case consists of one line of four integers p, e, i, and d. The values p, e, and i are the number of days from the beginning of the current year at which the physical, emotional, and intellectual cycles peak, respectively. The value d is the given date and may be smaller than any of p, e, or i. All values are non-negative and at most 365, and you may assume that a triple peak will occur within 21252 days of the given date. The end of input is indicated by a line in which p = e = i = d = -1.

Output

For each test case, print the case number followed by a message indicating the number of days to the next triple peak, in the form: 

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

Use the plural form ``days'' even if the answer is 1.

Sample Input

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

Sample Output

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.

Source


中国剩余定理。
公元前后的《孙子算经》中有“物不知数”问题:“今有物不知其数,三三数之余二 ,五五数之余三 ,七七数之余二,问物几何?”答为“23”。也就是求同余式组x≡2 (mod3),x≡3 (mod5 ),x≡2 (mod7)(式中a≡b (modm)表示m整除a-b )的正整数解。明朝程大位用歌谣给出了该题的解法:“三人同行七十稀,五树梅花廿一枝,七子团圆月正半,除百零五便得知。”即解为x≡2×70+3×21+2×15≡233≡23(mod105)。此定理的一般形式是设m = m1 ,… ,mk 为两两互素的正整数,m=m1,…mk ,m=miMi,i=1,2,… ,k 。则同余式组x≡b1(modm1),…,x≡bk(modmk)的解为x≡M'1M1b1+…+M'kMkbk (modm)。式中M'iMi≡1 (modmi),i=1,2,…,k 。直至18世纪 C.F.高斯才给出这一定理。孙子定理对近代数学如环论,赋值论都有重要影响。 
  孙子问题的解法,以现代的说法,是找出三个关键数70,21,15。解法的意思就是用70乘3除所得的馀数,21乘5除所得的馀数,15乘7除所得的馀数,然後总加起来,除以105的余数就是答案。
  即题目的答案为 70×2+21×3+15×2
  =140+63+30
  =233
  233-2×105=23
  公式:70a+21b+15c-105n

  关键:解法中的三个关键数70,21,15,有何妙用,有何性质呢?首先70是除3余1而5与7都除得尽的数,所以70a是3除除a,而5与7都除得尽的数,21是5除除1,而3与7都除得尽的数,所以21b是5除余b,而3与7除得尽的数。同理,15c是7除余c,3与5除得尽的数,总加起来 70a+21b+15c 是3除余a,5除余b ,7除余c的数,也就是可能答案之一,但可能不是最小的,这数减105(105=3*5*7)仍有这样性质,可以多次减去105而得到最小的正数解。因为28*33 mod 23=4,要使得28*33*x mod 23=1,x可以等于6,因为6*4 mod 23=1。同理同理,要使23*33*y mod 28=1,y可以取19。23*28*z mod 33=1,z可以取2。

代码如下:

#include<stdio.h>

int main(void) {
    int p;
    int e;
    int i;
    int d;
    int j=0;
    while (scanf("%d%d%d%d", &p, &e, &i, &d), p + 1) {
        j++;
        int day;
        day = (p * 5544 + e * 14421 + i * 1288) % (23 * 28 * 33);
        day -= d;
        if (day <= 0)
            day += 21252;
        printf("Case %d: the next triple peak occurs in %d days.\n", j, day);
    }
    return 0;
}




Robot Arm 机械臂源码解析 由于我们用的是步进电机,运动的时候是一步一步的,并不是平滑的,这里假设在一个平面上面,一个x步进电机,一个y步进电机。那么放大它们所走的轨迹就会是阶梯状的。而它们也只能沿着网格运动。相当于有了一个最小的分辨率,这个分辨率就是一步。如下图所示,如果x,y电机同时走就能走出45度的斜线。在三维空间里面运动也是如此,你应该可以想象的出来;首先,是updateActualPosition,用来时时更新此时的差补位置,得到的是一个路径与时间t的函数(其中路径的范围为0,1,时间范围为0,dist/v)... 阅读详情

相关推荐

携程登录风控逆向踩坑实录:从滑块到点选验证码,我是如何一步步拿到phantom-token的

本文详细解析了携程登录风控系统的逆向过程,从滑块验证码到点选验证码的破解,再到设备指纹生成和加密协议逆向,最终成功获取phantom-token。文章提供了关键代码示例和实战技巧,帮助开发者理解并绕过复杂的风控机制。

weixin_28049429的博客 973

POJ 1006

POJ 1006 原题 Description Some people believe that there are three cycles in a person’s life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles...

Kingdeguo 871

ANSYS APDL学习(6):ANSYS APDL部分命令流介绍

介绍APDL 部分命令流

娱乐至上的博客 1万+

中国剩余定理-(POJ - 1006)

题目 Some people believe that there are three cycles in a person’s life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they have perio...

扬弃 519

Protege新手入门:5分钟搞定本体建模基础(附实战案例)

本文为Protege本体建模新手提供了一份快速入门指南。通过构建一个关于“披萨”的实战案例,详细讲解了从环境准备、定义核心类(Classes)、建立对象属性(Object Properties)到设置数据属性(Data Properties)和创建个体的完整流程。文章旨在帮助读者绕过复杂理论,在5分钟内直观掌握本体建模的基础操作,快速建立知识图谱构建的信心。

weixin_28335283的博客 284

[AI] 企业内网部署大模型的三种常见方案:从“能用”到“好用”的技术选型指南

企业内网部署大模型的三种方案解析:本地模型安全但门槛高,平台方案(如Dify)最平衡推荐,混合架构适合进阶需求。关键路径是渐进式演进,从快速验证到平台化建设,核心在于流程优化而非单纯选模型。数据安全、成本可控和工程落地能力是决策重点。

技术小甜甜:传播可落地技术,帮助个人和企业降低解决真实场景问题的成本 772

Poj 1006 Biorhythms 中国剩余定理

Description Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they ...

zamaochick的博客 268

【OpenClaw从入门到精通】命令行操作指南——TUI模式高效管理OpenClaw(2026避坑版)

本文将详细介绍OpenClaw的命令行操作,重点介绍TUI(Text User Interface)模式的高效使用方法,以及在实际使用中需要避免的常见陷阱。通过本文的学习,你将掌握OpenClaw命令行的精髓,提升工作效率。

一键难忘的博客 1692

POJ 1006 Biorhythms

POJ 1006 Biorhythms Description Some people believe that there are three cycles in a person’s life that start the day he or she is born. These three cycles are the physical, emotional, and intellectua...

旺崽的博客 2914

安卓新奇玩机工具全攻略___联发科MTK v6 限时免费 刷写固件工具操作

摘要:该文介绍一款限时免费的联发科V6刷机工具,支持小米、Vivo、Moto等多品牌设备,包括红米Note14Pro等机型(Klimt/Goya等代码)。工具需注册使用,提供EFS分区备份功能。作者提示工具可能触发杀毒警报,强调禁止非法用途,并说明部分联网工具可能失效。

小马哥的专栏 1322

IEC 61850标准协议解读 3.MMS服务

摘要:本文系统介绍了MMS(制造报文规范)的基础知识及其在IEC61850中的应用。首先解析MMS的核心定义、通信流程(带确认/不带确认服务)、虚拟制造设备(VMD)概念及核心对象(域/有名变量等)。重点阐述IEC61850与MMS的映射关系,包括对象分层映射、服务转换规则及数据类型对应。深入分析ASN.1编解码机制,说明MMS PDU的分层结构与解码流程。最后通过典型报文案例(报告服务、控制服务、文件传输等)和通信初始化流程,展示MMS在智能变电站中的实际应用。全文揭示了MMS作为抽象应用层协议如何通过标

张二狗的博客 728

POJ1006

POJ1006其实不能算是一道编程难题,只是里面用到了剩余定理。首先说一下数学上的计算。具体的资料可以在网上搜索一下“剩余定理”或者是“韩信点兵”。因为23、28、33这3个数互质,那么由剩余定理有:R1为28*33*a%23==1的最小的正整数(a为正整数),即a=6,R1=5544R2为23*33*b%28==1的最小的正整数(b为正整数),即b=...

163

华为OD机试真题 新系统-等距二进制判断(C/C++/Py/Java/Js/Go)

华为OD机试 新系统真题【等距二进制判断】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【等距二进制判断】

qq_45776114的博客 1091

Poj1006

import java.util.Scanner; public class Poj1006 { //p体力,e是情感,i智力,d给定时间 //使用中国剩余定理解决 public static void main(String[] args) { int p = 0,e = 0,i = 0,d = 0,count = 0; Scanner scan = new Scan

tan313的专栏 567

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

poj解题报告——poj1006

这次做了poj1006,忽然想起小时候韩信点兵的故事,

Lingfu74的专栏 622

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

【POJ】[1006]Biorhythms

题目地址:【POJ】[1006]Biorhythms

BoilTask Talk Show 377

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

POJ1006 Biorhythms

题目链接:http://poj.org/problem?id=1006&lang=default&change=true 题目分析: 输入四个整数,即题目中所说的生理周期的三个时间(这里的时间都是距离本年第一天的天数)和开始计算日期的时间。 通过中国剩余算法计算求得时间。求得公式为: days = (5544 * p + 14421 * e + 1288 * i - d + 21252

Hugo的编程学习记录 892

POJ1006 Biorhythms 题解

孙子定理 中国剩余定理 中国余数定理 POJ1006题解 Biorhythms题解

Nothing gonna but our heart change 1243

poj 1006

poj 1006 题的思路不是很难的,可以转化数学式:现设 num 是下一个相同日子距离开始的天数 p,e,i,d 如题中所设! 那么就可以得到三个式子:( num + d ) % 23 == p; ( num + d ) % 28 == e; ( num + d ) % 33 == i;p,e,i,d 是我们输入的,那么我们需要求出num即可,为了方便,我们将num+d暂时作为一个整体!令

人面桃花 396

POJ 1006 中国剩余定理

初见poj1006用的暴力破解写的代码,写完以后发现很搓。上网一查原来古人早就对此类问题有了解答规则。 一、中国剩余定理 一元线性同余方程组问题最早可见于中国南北朝时期(公元5世纪)的数学著作《孙子算经》卷下第二十六题,叫做“物不知数”问题,原文如下: 有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二。问物几何? 即,一个整数除以三余二,除以五余三,除以七余二

理想国 1262

POJ_1006

http://poj.org/problem?id=1006 根据题意很自然地写出了暴破解法如下: //POJ_1006 #include<stdio.h> int main(){ int n,i,j,k; int p,q,r,d; n = 0; while(true){ scanf("%d %d %d %d",&p,&q,&r,&d)...

ABC827300139的专栏 174

POJ 1006 Biorhythms - 数学逻辑

POJ 1006 Biorhythms 题意:三个正整数的最小公约数相关。难度:1星。 根据相关逻辑关系直接计算,也不算复杂。注意,在current day就是next triple peak day时,答案应为一个周期(21252);next triple peak day有可能小于current day,此时答案应在下一个周期内(即再加21252)。 讨论区中有同学用“中国剩余定理”解决

ChenK在学习! 773

poj 1006 java_poj1006的java实现

本文参考了http://blog.youkuaiyun.com/lyy289065406/article/details/6648551解题思路:中国剩余定理,本题难点不在编程,而是分析题目并转化为数学公式要引入本题解法,先来看一个故事“韩信点兵”:传说西汉大将韩信,由于比较年轻,开始他的部下对他不很佩服。有一次阅兵时,韩信要求士兵分三路纵队,结果末尾多2人,改成五路纵队,结果末尾多3人,再改成七路纵队,结...

weixin_34005314的博客 303
上一篇: poj2407
下一篇: poj1061
lulining
博客等级 码龄15年 8粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值