Biorhythms
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 135099 | Accepted: 43146 |
Description
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
Output
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. 题目长,题意是:给出 p,e,i,d ,已知 (n+d)%23 == p ,(n+d)%28 == e , (n+d)%33 == i ,求 n (N>0)
暴力即可,写一下记录中国剩余定理,又名孙子定理
解法:
已知(n+d)%23=p; (n+d)%28=e; (n+d)%33=i
使28×33×a被23除余1,用33×28×8=5544;
使23×33×b被28除余1,用23×33×19=14421;
使23×28×c被33除余1,用23×28×2=1288。
所以:(5544×p+14421×e+1288×i)% lcm(23,28,33) = n+d
23、28、33互质,即lcm(23,28,33)= 21252;
得式子:n=(5544×p+14421×e+1288×i-d+lcm)%lcm
其实也就是凑出来这个数字
暴力的:
#include <iostream>
#include <stdio.h> using namespace std;
#define MAX 21252 int main()
{
int a,b,c,d;
int cas=;
while (scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
{
if (a==-&&b==-&&c==-&&d==-)
break;
a%=;
b%=;
c%=;
for (int i=c;i<=MAX+;i+=)
{
if ((i-a)%== && (i-b)%== && (i-c)%==)
{
if (i<=d)
i+=MAX;
printf("Case %d: the next triple peak occurs in %d days.\n",cas++,i-d);
break;
}
}
}
return ;
}
定理的: 快一些
#include <iostream>
#include <stdio.h>
using namespace std; int main()
{
int p,e,i,d;
int cas=;
while (scanf("%d%d%d%d",&p,&e,&i,&d)!=EOF)
{
if (p==-&&e==-&&i==-&&d==-) break; int n=(*p+*e+*i-d+)%;
if (n==) n+=;
printf("Case %d: the next triple peak occurs in %d days.\n",cas++,n);
}
return ;
}
Biorhythms的更多相关文章
- poj1006 / hdu1370 Biorhythms (中国剩余定理)
Biorhythms 题意:读入p,e,i,d 4个整数,已知(n+d)%23=p; (n+d)%28=e; (n+d)%33=i ,求n . (题在文末) 知识点:中国剩余定理 ...
- poj 1006:Biorhythms(水题,经典题,中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 110991 Accepted: 34541 Des ...
- POJ 1006 - Biorhythms (中国剩余定理)
B - Biorhythms Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Subm ...
- [POJ] #1006# Biorhythms : 最小公倍数/同余问题
一. 题目 Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 127263 Accepted: 403 ...
- Poj 1006 / OpenJudge 2977 1006 Biorhythms/生理周期
1.链接地址: http://poj.org/problem?id=1006 http://bailian.openjudge.cn/practice/2977 2.题目: Biorhythms Ti ...
- 算法练习之:Biorhythms
Biorhythms Time Limit: 1000MS Memory Limit: 10000KB Problem Description Some people believe that th ...
- Biorhythms(中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 127339 Accepted: 40342 Des ...
- POJ - 1006 Biorhythms 周期相遇 两个思路程序
Description Some people believe that there are three cycles in a person's life that start the day he ...
- Biorhythms(poj1006+中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 117973 Accepted: 37026 Des ...
- Biorhythms(中国剩余定理)
http://shuxueshi.jie.blog.163.com/blog/static/13611628820104179856631/ 这篇博客写的很棒! #include<stdio.h ...
随机推荐
- 论坛中不同类型的贴的排序问题(涉及数据库的:CASE... END)
在论坛中,会有不同类型的帖子,比如说:普通贴.精华帖.置顶帖: 论坛的这些贴子会根据不同的类型进行排序,当然不仅仅只是看帖子类型,还有贴子的动态情况来进行排序. 在这里演示一下简单的帖子排序,我们只关 ...
- Shell--Bash shell的操作环境
一.路径与命令查找顺序 1.以相对/绝对路径执行命令,例如“/bin/ls”或“./ls”; 2.由alias找到该命令来执行 3.由bash内置的(builtin)命令来执行 4.通过$PATH这个 ...
- 智能选择器和语义化的CSS
本文由白牙根据Heydon Pickering的<Semantic CSS With Intelligent Selectors>所译,整个译文带有我自己的理解与思想,如果译得不好或不对之 ...
- 使用Java取得本机IP和机器名
try { InetAddress addr = InetAddress.getLocalHost(); String ip=addr.getHostAddress().toString();//获得 ...
- Angular 学习笔记——$rounte
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...
- Python图像处理(11):k均值
快乐虾 http://blog.csdn.net/lights_joy/ 欢迎转载,但请保留作者信息 K均值是一个经典的聚类算法,我们试试在python下使用它. 首先以(-1.5, -1.5)和(1 ...
- ios网络学习------10 原生API文件上传
使用原生态的api上传文件的实现: #import "MainViewController.h" @interface MainViewController () @propert ...
- Database returned an invalid value in QuerySet.datetimes(). Are time zone definitions for your datab
Database returned an invalid value in QuerySet.datetimes(). Are time zone definitions for your datab ...
- 属性字符串NSMutableAttributedString
要实现如下效果: NSString * mailString = @"mymail@126.com"; NSString * mailStringWithQuotes = [NSS ...
- ios 缩放图片(平铺)
//缩放图片(平铺) - (UIImage *)resizeImage:(NSString *)imgName { UIImage *bgImage = [UIImage imageNamed:im ...