北大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天.每一个周期中有一天是高峰.在高峰这 ...
随机推荐
- catch data
抓取一些有反爬机制的website 喜马拉雅 每天都有-动态class 通过网络请求
- ListTile
const ListTile({ Key key, this.leading, // item 前置图标 this.title, // item 标题 this.subtitle, // item 副 ...
- 【Python65--tkinter:button】
一.需求:在Label页面增加一个按钮,点击此按钮,页面内容进行变化 思路: 1.上面放一个Label,下面放一个Button 2.采用frame框架 from tkinter import * #定 ...
- css的再深入9(更新中···)
一 单位 1.px 就是一个基本的单位 像素 2.em 也是一个单位 用父级元素的字体大小乘以em前面的数字.如果父级没有就继承上一个父级直到body,如果body没有那就默认是16px. 3.rem ...
- python from entry to abandon2
学习Linux已经有大致两周了,依然感觉到自己仍然在运维的大门外徘徊.于是我想要找到一个在Linux之外的业余方向,可以以作为枯燥基础学习的调节.没过多久我就发现了Python可以说是钦定的选择,它作 ...
- Python作业
1使用while 循环输入1,2,3,4,5,6,,8,9,10 count = 0 while count<10: count+=1 if count ==7: continue print( ...
- vue--数据显示模版上
首先需要知道 挂载点:是index.html文件下的一个dom节点 模板:挂载点里的内容,也就是模板内容. 组件: 页面上的某一部分内容.当我们的项目比较大时,可以将页面拆分成几个部分,每个部分就是一 ...
- buntu下cutecom图像界面串口调试工具使用
一.安装,首先下载这个软件,终端和软件中心均可下载,终端下载命令: sudo apt-get install cutecom 即可快速搞定安装问题. 软件中心: 由于我已经通过终端安装成功,所以软件中 ...
- 微信小程序,加载更多
html <!-- 头部 --> <view class='tab'> <view class="tab-new {{selected_new?'active' ...
- MVC查看详细数据【四】
一.本篇文章主要讲解点击详细,将主键id的值传递到后端,或者将多个值传递给后台的三种方式,并且通过id的值在数据库中查找到相对应的数据,赋值给viewData视图. 1. 第一种将主键id的值传递给后 ...