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));
    }
  • 相关阅读:
    AIX 第3章 指令记录
    AIX 第2章 指令记录
    Oracle Exadata体系笔记
    决定undo表空间的大小
    摘录:官方文档对ROWID虚拟行的定义
    ORA-01102 cannot mount database in EXCLUSIVE mode
    居民身份证号码含义
    ORA-00257错误
    微机原理之 输入输出与中断
    操作系统总结之 输入输出系统(下)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5348025.html
Copyright © 2011-2022 走看看