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\n",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\n",max(x[0]-a,0));//注意x[0]和a谁大的问题
        else
            printf("%d\n",b-a+1);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我! 基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值