北大ACM训练题(1006--Biorhythms)

本文提供了一种解决 POJ 1006 的算法思路及 C 语言实现。该题涉及三个特定公差的等差数列,通过暴力搜索找出首个大于给定值且三个数列值相等的数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:http://poj.org/problem?id=1006


题目可能有点饶,简而言之,就是有三个公差分别是23,28,33的等差数列,在给定数列第一项的情况下求出三个数列同时相等时的数是多少,并且这个数要大于给定的第四个输入值,由于这个值可能比前三个数都小,所以我就将这个数先分别对23,28,33取模,得到最小的初值,然后注意特殊值就行了,由于是暴力求解,就不多赘述了

代码:

#include<stdio.h>
int main(){
	int p;
	int e;
	int j;
	int d;
	int q;
	int w;
	int r;
	int P;
	int E;
	int J;
	int i=1;
	while(scanf("%d %d %d %d",&p,&e,&j,&d),p!=-1&&e!=-1&&j!=-1&&d!=-1){
	    p=p%23;
	    e=e%28;
	    j=j%33;
	    q=0;
	    w=0;
	    r=0;
	    while(1){
	    	P=p+23*q;
	    	E=e+28*w;
	    	J=j+33*r;
	    	if(P==0&&E==0&&J==0);
	    	else if((P==E)&&(P==J)&&P>=d)
		    break;
	    	if(P<=E&&P<=J)
	    	    q++;
	        else if(E<=P&&E<=J)
	            w++;
	        else if(J<=P&&J<=E)
	            r++;
	    }
	    printf("Case %d: the next triple peak occurs in %d days.\n",i++,P-d);
	}
	return 0;
}

报告:Fence 目来源:POJ 1031 解法或类型: 计算几何 作者:杨清玄 Fence Time Limit:1S Memory Limit:1000K Total Submit:103 Accepted:26 Description There is an area bounded by a fence on some flat field. The fence has the height h and in the plane projection it has a form of a closed polygonal line (without self-intersections), which is specified by Cartesian coordinates (Xi, Yi) of its N vertices. At the point with coordinates (0, 0) a lamp stands on the field. The lamp may be located either outside or inside the fence, but not on its side as it is shown in the following sample pictures (parts shown in a thin line are not illuminated by the lamp): The fence is perfectly black, i.e. it is neither reflecting, nor diffusing, nor letting the light through. Research and experiments showed that the following law expresses the intensity of light falling on an arbitrary illuminated point of this fence: I0=k/r where k is a known constant value not depending on the point in question, r is the distance between this point and the lamp in the plane projection. The illumination of an infinitesimal narrow vertical board with the width dl and the height h is dI=I0*|cosα|*dl*h where I0 is the intensity of light on that board of the fence, α is the angle in the plane projection between the normal to the side of the fence at this point and the direction to the lamp. You are to write a program that will find the total illumination of the fence that is defined as the sum of illuminations of all its illuminated boards. Input The first line of the input file contains the numbers k, h and N, separated by spaces. k and h are real constants. N (3 <= N <= 100) is the number of vertices of the fence. Then N lines follow, every line contains two real numbers Xi and Yi, separated by a space. Output Write to the output file the total illumination of the fence rounded to the second digit after the decimal point. Sample Input 0.5 1.7 3 1.0 3.0 2.0 -1.0 -4.0 -1.0 Sample Output 5.34 Source Northeastern Eu
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值