hdu5914&hdu5912

最近两天写题少了,罪过罪过罪过罪过罪过。。。。。。
第一个题,让你从1~n之间取出几个数,让剩下的数随机组不成三角形,然后就是,你可以yy一下哈,就是1,2,3,5,8,。。。。。啥意思呢?就是一个斐不那契数列(原谅我没看出来我写的时候,看别人的才知道)然后就是这么回事,需要给他来一发比如!2+3=5那么4就一定要舍掉,因为2,3,4构成三角形,同理,3+5=8,舍掉6,7,然后找出所有这种的数,其实这是斐不那契数列,我比赛的时候是直接暴力写的。。。。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int a[20];
void yu()
{
    a[1] = 1 , a[2] = 2;
    for(int i = 3 ; i <= 20 ; i++) a[i] = a[i - 1] + a[i - 2];
}
int main()
{
    int t , cnt = 1;
    yu();
    scanf("%d",&t);
    while(t--){
        int n , tot= 0;
        scanf("%d",&n);
        for(int i = 1 ; i <= n ; i++ ){
            if(a[i] > n) break;
            tot++;
        }
        printf("Case #%d: %d\n", cnt++ , n - tot);
    }
    return 0;
}

这个就是个推公式,我tm推错了!!!!主要是样例有坑,测试数据还是要自己来做,由于这个我还不会写数学公式,就是发个代码吧

#include<cstdio>
#include<cstring>
#include<cstring>
#include<algorithm>
using namespace std;

long long a[20],b[20];

long long gcd(long long x , long long y)
{
    if(y == 0) return x;
    else return gcd(y , x % y);
}
int main()
{
    int t , cnt = 1;
    scanf("%d",&t);
    while(t--){
        int n ;
        long long A , B;
        scanf("%d",&n);
        for(int i = 1 ; i <= n ; i++) scanf("%d",&a[i]);
        for(int i = 1 ; i <= n ; i++) scanf("%d",&b[i]);
        A = a[n] , B = b[1];
        for(int i = n - 1 ; i > 0 ; i--){
            b[i] *= A;
            A = A * a[i] + b[i + 1];
            //printf("A = %d\n",A);
        }
        long long yue = gcd(A , b[1]);//我一开始写个B然后就错了
        A /= yue , b[1] /= yue;//约分
            printf("Case #%d: %I64d %I64d\n",cnt,b[1],A);
        cnt++;
    }
}
/*
2
2
1 1
2 3
1
6 3
*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值