zoukankan      html  css  js  c++  java
  • Codeforces:68A-Irrational problem(暴力大法好)

    A- Irrational problem p

    Time Limit: 2000MS
    Memory Limit: 262144K
    64bit IO Format: %I64d& %I64

    Description

    Little Petya was given this problem for homework:

    You are given function Irrational problem (here Irrational problem represents the operationof taking the remainder). His task is to count the number ofintegers x inrange [a;b] withproperty f(x) = x.

    It is a pity that Petya forgot the order in which the remaindersshould be taken and wrote down only 4 numbers. Each of 24 possibleorders of taking the remainder has equal probability of beingchosen. For example, if Petya has numbers 1, 2, 3, 4 then he cantake remainders in that order or first take remainder modulo 4,then modulo 2, 3, 1. There also are 22 other permutations of thesenumbers that represent orders in which remainder can be taken. Inthis problem 4 numbers wrote down by Petya will be pairwisedistinct.

    Now it is impossible for Petya to complete the task given byteacher but just for fun he decided to find the number ofintegers Irrational problem with property thatprobability thatf(x) = x isnot less than 31.4159265352718281828459045%. In otherwords, Petya will pick up the number x if there existat least 7 permutations ofnumbersp1, p2, p3, p4, forwhich f(x) = x.

    Input

    First line of the input will contain 6 integers, separated byspaces: p1, p2, p3, p4, a, b (1 ≤ p1, p2, p3, p4 ≤ 1000, 0 ≤ a ≤ b ≤ 31415).

    It is guaranteed that numbers p1, p2, p3, p4 will be pairwisedistinct.

    Output

    Output the number of integers in the given range that have thegiven property.

    Sample Input

    2 7 1 8 2 8
    20 30 40 50 0 100
    31 41 59 26 17 43

    Sample Output

    0
    20
    9


    解题心得:

    1. 题目说了一大堆,什么mod四个数,什么不同的排列方式,满足什么什么的,其实不管怎么排列mod出来的效果都是等效mod最小的那个数,想想就能明白。
    2. 两种做法:
      • 第一种,看mod最小的那个数和a之间有多少个数,但是要注意的是mod的最小的那个数是否比b要小,不然会得到的答案会比a到b的所有的数要多,比赛就WA了,悲伤。
      • 第二种,最稳妥的方法,直接暴力,从a到b一个数一个数的跑,反正数据量这么小。

    暴力跑的代码:

    #include<stdio.h>
    typedef long long ll;
    using namespace std;
    int main()
    {
        int x[4],a,b;
        while(scanf("%d%d%d%d%d%d",&x[0],&x[1],&x[2],&x[3],&a,&b) != EOF)
        {
            int ans = 0;
            for(int i=a;i<=b;i++)
                if(i%x[0]%x[1]%x[2]%x[3] == i)
                    ans++;
            printf("%d
    ",ans);
        }
        return 0;
    }
    

    观察mod的性质来写的代码

    /*还是暴力大法好*/
    #include<stdio.h>
    #include<algorithm>
    typedef long long ll;
    using namespace std;
    int main()
    {
        int x[4],a,b;
        while(scanf("%d%d%d%d%d%d",&x[0],&x[1],&x[2],&x[3],&a,&b) != EOF)
        {
            sort(x,x+4);
            if(x[0] <= b)//注意边界的问题
                printf("%d
    ",max(x[0]-a,0));//注意x[0]和a谁大的问题
            else
                printf("%d
    ",b-a+1);
        }
        return 0;
    }
    
  • 相关阅读:
    jenkins 使用oclint 扫描 oc 代码
    mac下 jenkins 环境搭建
    jenkins 中 Poll SCM 和 Build periodically 的区别
    表单验证封装,一招学会,永远受用
    浅谈js中的执行环境和执行环境对象
    浅谈php之设计模式基础
    四条地铁线带你通往Ajax的大门
    论js结合数学的应用
    以留言本的开发打开ajax的世界
    初步学习css3之3D动画
  • 原文地址:https://www.cnblogs.com/GoldenFingers/p/9107196.html
Copyright © 2011-2022 走看看