北大poj- 1006
生理周期
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 133189 | Accepted: 42577 |
Description
Input
当p = e = i = d = -1时,输入数据结束。
Output
采用以下格式:
Case 1: the next triple peak occurs in 1234 days.
注意:即使结果是1天,也使用复数形式“days”。
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
Translator
#include <stdio.h>
#include <stdlib.h> #define SUCCESS 1
#define FAILURE 0 int p = ;
int e = ;
int i = ;
int d = ; int Search(int j, int M, int *inm, int i)
{
int m = *inm;
int result = FAILURE;
while()
{
if(p+*j == i+M*m)
{
result = SUCCESS;
break;
}
else if(p+*j > i+M*m)
m++;
else if(p+*j < i+M*m)
{
m = ;
result = FAILURE;
break;
}
}
*inm = m;
return result;
} int Match(int *j, int *k, int *m)
{
while(*j<)
{
if(SUCCESS == Search(*j,,m,i))
{
if(SUCCESS == Search(*j,,k,e))
return SUCCESS;
} (*j)++;
}
return FAILURE;
} int main(void)
{
int j = ;
int k = ;
int m = ;
int ans = ;
int n = ;
while(==scanf("%d %d %d %d", &p, &e, &i, &d) && (p!=- || e!=- || i!=- || d!=-))
{
getchar();
n++;
p = p % ;
e = e % ;
i = i % ; Match(&j,&k,&m); ans = p+*j; if(ans < d)
ans = + ans - d;
else
ans = ans -d; if(ans% > d)
ans %= ; printf("Case %d: the next triple peak occurs in %d days.\n", n, ans);
}
return ;
}
第二次:
#include <stdio.h>
#include <stdlib.h> int p = ;
int e = ;
int i = ;
int d = ; int main(void)
{
int ans = ;
int n = ;
while(==scanf("%d %d %d %d", &p, &e, &i, &d) && (p!=- || e!=- || i!=- || d!=-))
{
getchar();
n++;
p = p % ;
e = e % ;
i = i % ; for(ans=d+;;ans++)
{
if((ans-p)%== && (ans-e)%== && (ans-i)%==)
{
break;
}
} if(ans < d)
ans = + ans - d;
else
ans = ans - d; if(ans% > d)
ans %= ; printf("Case %d: the next triple peak occurs in %d days.\n", n, ans);
}
return ;
}
第三次:
#include <stdio.h> int p = ;
int e = ;
int i = ;
int d = ; int main(void)
{
int ans = ;
int n = ;
int flag = ;
while(==scanf("%d %d %d %d", &p, &e, &i, &d) && (p!=- || e!=- || i!=- || d!=-))
{
getchar();
p = p % ;
e = e % ;
i = i % ;
ans = i+;
flag = ; if(p==e && e==i && p>d)
{
ans=p-d;
flag=;
}
if(p==e && e==i && p<=d)
{
ans=p+-d;
flag=;
} if(flag)
{
while(((ans-p)%)!=||((ans-e)%)!=||ans-d<)
ans+=;
ans -= d;
} printf("Case %d: the next triple peak occurs in %d days.\n", ++n, ans);
}
return ;
}
北大poj- 1006的更多相关文章
- 北大POJ题库使用指南
原文地址:北大POJ题库使用指南 北大ACM题分类主流算法: 1.搜索 //回溯 2.DP(动态规划)//记忆化搜索 3.贪心 4.图论 //最短路径.最小生成树.网络流 5.数论 //组合数学(排列 ...
- POJ 1006 - Biorhythms (中国剩余定理)
B - Biorhythms Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Subm ...
- POJ 1006 Biorhythms(中国剩余定理)
题目地址:POJ 1006 学习了下中国剩余定理.參考的该博客.博客戳这里. 中国剩余定理的求解方法: 假如说x%c1=m1,x%c2=m2,x%c3=m3.那么能够设三个数R1,R2,R3.R1为c ...
- POJ 1006 生理周期(中国剩余定理)
POJ 1006 生理周期 分析:中国剩余定理(注意结果要大于d即可) 代码: #include<iostream> #include<cstdio> using namesp ...
- POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理)
POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理) 题意分析 不妨设日期为x,根据题意可以列出日期上的方程: 化简可得: 根据中国剩余定理求解即可. 代码总览 #include & ...
- Poj 1006 / OpenJudge 2977 1006 Biorhythms/生理周期
1.链接地址: http://poj.org/problem?id=1006 http://bailian.openjudge.cn/practice/2977 2.题目: Biorhythms Ti ...
- 【中国剩余定理】POJ 1006 & HDU 1370 Biorhythms
题目链接: http://poj.org/problem?id=1006 http://acm.hdu.edu.cn/showproblem.php?pid=1370 题目大意: (X+d)%23=a ...
- 中国剩余定理 (POJ 1006)
http://poj.org/problem?id=1006 在<孙子算经>中有这样一个问题:“今有物不知其数,三三数之剩二(除以3余2),五五数之剩三(除以5余3),七七数之剩 ...
- POJ 1006 Biorhythnms(中国剩余定理)
http://poj.org/problem?id=1006 题意: (n+d) % 23 = p ;(n+d) % 28 = e ;(n+d) % 33 = i ; 求最小的n. 思路: 这道题就是 ...
- poj 1006 Biorhythms (中国剩余定理模板)
http://poj.org/problem?id=1006 题目大意: 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这 ...
随机推荐
- Mysql 书写语句时避免出现关键字导致报错 关键字大全
ADD ALL ALTER ANALYZE AND AS ASC ASENSITIVE BEFORE BETWEEN BIGINT BINARY BLOB BOTH BY CALL CASCADE C ...
- dva构建react项目
第一步:安装 dva-cli 1 cnpm install dva-cli -g 第二步:采用dva来创建项目: 1 dva new react_two 2 cd react_two 用webstor ...
- Python socket实现处理多个连接
socket实现处理多个连接 实现处理多个连接 使用whlie循环实现多个客户端,排队请求服务端 循环监听端口发送信息(windos,Linux) 1.Linux 系统如果客户端断开连接,会循环 ...
- FL Studio的模式剪辑是什么?
FL Studio里的模式剪辑功能里,有一个模式菜单.模式剪辑菜单和模式选择器面板.模式可以作为模式剪辑放置在播放列表中,模式剪辑的名称显示在剪辑的标题栏中.(注意:模式注释和事件自动化可以共享相同的 ...
- VC++ 异常处理 __try __except的用法
转载:https://blog.csdn.net/jiaxiaokai/article/details/50983867 __try __except的用法: __try __except是windo ...
- Lintcode481-Binary Tree Leaf Sum-Easy
481. Binary Tree Leaf Sum Given a binary tree, calculate the sum of leaves. Example Example 1: Input ...
- 微生物组学数据分析工具综述 | 16S+宏基因组+宏病毒组+宏转录组--转载
转载:https://mp.weixin.qq.com/s/xsL9GuLs7b3nRF8VeRtinQ 建立在高通量测序基础上的微生物群落研究,当前主要有三大类:基于16S/18S/ITS等扩增子做 ...
- lambda Helper
/// <summary> /// 操作表达式共通类,条件并且,或者操作等 /// </summary> public static class PredicateBuilde ...
- C# Cache 设定过期时间的方法
1. 设定绝对过期时间 /// <summary> /// 设定绝对的过期时间 /// </summary> /// <param name="CacheKey ...
- IDEA中更改Tomcat服务器的URL
先别参考以下的做法,貌似出了点状况,后续修正!!! 直接上图吧 看IDEA的右上角 点击黄色方框内的Edit Configurations,进入以下的编辑面 后面四个框内的都可以修改,当然不要修改和其 ...