zoukankan      html  css  js  c++  java
  • April Fools Day Contest 2016 B. Scrambled

    B. Scrambled

    题目连接:

    http://www.codeforces.com/contest/656/problem/B

    Description

    Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht D mod M[i] = R[i], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.

    Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo.

    Input

    The first line of input contains a single integer N (1 ≤ N ≤ 16).

    The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All M[i] are positive, for each i R[i] < M[i].

    Output

    Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4.

    Sample Input

    1
    2
    0

    Sample Output

    0.500000

    Hint

    题意

    听说改变文字顺序,并不影响题目阅读 hhh

    就是两个人洗碗的故事,如果对于i天来说,存在一个j,使得i%m[j]=r[j]

    那么这一天归我洗碗,否则归他

    问一共百分之多少的天数,我在洗碗。

    题解:

    算个lcm,然后直接暴力就好了

    1到16的lcm是720720

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 20;
    
    int m[maxn],r[maxn];
    int main()
    {
        int n;scanf("%d",&n);
        for(int i=1;i<=n;i++)scanf("%d",&m[i]);
        for(int i=1;i<=n;i++)scanf("%d",&r[i]);
        int ans1=1;
        for(int i=0;i<=720720;i++)
            for(int j=1;j<=n;j++)
                if(i%m[j]==r[j]){ans1++;break;}
        printf("%.10f
    ",1.0*ans1/(1.0*720720));
    }
  • 相关阅读:
    数据挖掘实践(34):实战--高潜用户购买画像(三)特征工程
    数据挖掘实践(33):实战--高潜用户购买画像(二)EDA/探索性数据分析
    数据挖掘实践(32):实战--高潜用户购买画像(一)数据清洗
    Java 流程控制 之 顺序结构
    Java 之 运算符
    Java 之 变量
    Handmade Rust Part 1: Introduction & Allocators
    rust 强制转换
    引用与借用
    candidate #1: `std::clone::Clone`
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5348025.html
Copyright © 2011-2022 走看看