北大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天.每一个周期中有一天是高峰.在高峰这 ...
随机推荐
- inux下输入ifconfig命令,没有eth0,怎么解决
用ifconfig命令,只有lo,没有eth0的解决方案 问题描述:视频中输入ifconfig命令,显示eth0和lo,但是自己在虚拟机中并非得到这样的结果,而是只有lo,即网卡未启动,也没有ip,无 ...
- 将Bdd100k数据集转为CoCo数据集
小可爱,加油噻~ 添加上级目录 import sys sys.append('../..') 这样 from ... import 就会把加入的路径要扫描哒 os.walk() 方法用于通过在目录树中 ...
- 【酷】JS+CSS打造沿Y轴纵深运动的3D球体
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- Consul 常用指令
Consul 常用指令 # 通告地址 -advertise # 集群节点之间通信地址 -bind # 设置服务器为bootstrap模式.在一个dc中只有一个server处于bootstrap模式.一 ...
- 尚硅谷面试第一季-13git分支相关命令
课堂重点:分支相关命令 实际应用-工作流程 实操命令及运行结果: 创建master分支并提交 git init git add . git commit -m "V1.0" git ...
- container(容器),injection(注入)
1.container为什么会出现? 在书写程序的时候,我们常常需要对大量的对象引用进行管理.为了实现有效的归类管理,我们常常将同类的引用放置在同一数据容器中.由于数据容器中存放了我们随时可能需要使用 ...
- 论文阅读:Deep Attentive Tracking via Reciprocative Learning
Deep Attentive Tracking via Reciprocative Learning 2018-11-14 13:30:36 Paper: https://arxiv.org/abs/ ...
- Java对象的访问方式
之前写过一篇随笔 https://www.cnblogs.com/qianjinyan/p/10352749.html 现在看看,貌似不是很准确,方法区和栈应当区分开来,两者有很大的区别 看下面的一个 ...
- 综述 - 染色质可及性与调控表观基因组 | Chromatin accessibility and the regulatory epigenome
RNA-seq这个工具该什么时候用?ATAC-seq该什么时候用?有相当一部分项目设计不行,导致花大钱测了一些没有意义的数据. 还是在中心法则这个框架下来解释,这是生物信息的核心.打开华大科技服务官网 ...
- android -------- OkGo (让网络请求更简单的框架)
项目地址:https://github.com/jeasonlzy 该库是封装了okhttp的网络框架,可以与RxJava完美结合,比Retrofit更简单易用.支持大文件上传下载,上传进度回调,下载 ...