zoukankan      html  css  js  c++  java
  • BZOJ1583: [Usaco2009 Mar]Moon Mooing 哞哞叫

    给n<=4000000,c,a1,b1,c1,a2,b2,c2,以c为初始得到的数,每次可以把得到的某个数x进行操作f1(x)=a1*x/c1+b1,f2(x)=a2*x/c2+b2,求最后能得到的数的第n个,保证c1<a1,c2<a2。

    由于两个函数都单调递增,而且得到的数也是单调递增的,所以就在答案数组里开两个指针,用两种函数扩展就好啦~

    一开始还以为是分开算的QAQ

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<stdlib.h>
     4 #include<algorithm>
     5 //#include<iostream>
     6 using namespace std;
     7 
     8 int n;
     9 #define LL long long
    10 LL c,a1,b1,c1,a2,b2,c2;
    11 #define maxn 4000011
    12 LL ans[maxn];
    13 int main()
    14 {
    15     scanf("%lld%d",&c,&n);
    16     scanf("%d%d%d%d%d%d",&a1,&b1,&c1,&a2,&b2,&c2);
    17     int p1=1,p2=1,la=1;ans[1]=c;
    18     LL s1=a1*c/c1+b1,s2=a2*c/c2+b2;
    19     for (;la<n;)
    20     {
    21         if (s1<s2) {if (ans[la]!=s1) ans[++la]=s1;s1=ans[++p1]*a1/c1+b1;}
    22         else {if (ans[la]!=s2) ans[++la]=s2;s2=ans[++p2]*a2/c2+b2;}
    23     }
    24     printf("%lld
    ",ans[n]);
    25     return 0;
    26 }
    View Code
  • 相关阅读:
    设计模式-适配器模式(09)
    windows电脑使用技巧及常用CMD
    接口调用方法
    矩阵对角线和
    函数基础小结
    文件处理实战之购物车系统
    文件处理小结
    Python进阶实战之三级菜单
    Python进阶小结
    Python深浅拷贝
  • 原文地址:https://www.cnblogs.com/Blue233333/p/7481874.html
Copyright © 2011-2022 走看看