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
解题心得:
- 题目说了一大堆,什么mod四个数,什么不同的排列方式,满足什么什么的,其实不管怎么排列mod出来的效果都是等效mod最小的那个数,想想就能明白。
- 两种做法:
- 第一种,看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;
}
Codeforces:68A-Irrational problem(暴力大法好)的更多相关文章
- codeforces 897A Scarborough Fair 暴力签到
codeforces 897A Scarborough Fair 题目链接: http://codeforces.com/problemset/problem/897/A 思路: 暴力大法好 代码: ...
- codeforces 724B Batch Sort(暴力-列交换一次每行交换一次)
题目链接:http://codeforces.com/problemset/problem/724/B 题目大意: 给出N*M矩阵,对于该矩阵有两种操作: (保证,每行输入的数是 1-m 之间的数且不 ...
- CodeForces 687A NP-Hard Problem
Portal:http://codeforces.com/problemset/problem/687/A 二分图染色 好模板题 有SPJ 值得注意的是,因为C++的奇妙的运算机制 若在vector变 ...
- codeforces 340C Tourist Problem
link:http://codeforces.com/problemset/problem/340/C 开始一点也没思路,赛后看别人写的代码那么短,可是不知道怎么推出来的啊! 后来明白了. 首先考虑第 ...
- codeforces B. Routine Problem 解题报告
题目链接:http://codeforces.com/problemset/problem/337/B 看到这个题目,觉得特别有意思,因为有熟悉的图片(看过的一部电影).接着让我很意外的是,在纸上比划 ...
- Codeforces 527D Clique Problem
http://codeforces.com/problemset/problem/527/D 题意:给出一些点的xi和wi,当|xi−xj|≥wi+wj的时候,两点间存在一条边,找出一个最大的集合,集 ...
- Codeforces 706C - Hard problem - [DP]
题目链接:https://codeforces.com/problemset/problem/706/C 题意: 给出 $n$ 个字符串,对于第 $i$ 个字符串,你可以选择花费 $c_i$ 来将它整 ...
- Codeforces 1096D - Easy Problem - [DP]
题目链接:http://codeforces.com/problemset/problem/1096/D 题意: 给出一个小写字母组成的字符串,如果该字符串的某个子序列为 $hard$,就代表这个字符 ...
- Codeforces 793C - Mice problem(几何)
题目链接:http://codeforces.com/problemset/problem/793/C 题目大意:给你一个捕鼠器坐标,和各个老鼠的的坐标以及相应坐标的移动速度,问你是否存在一个时间点可 ...
随机推荐
- P1736 创意吃鱼法80
题目描述 回到家中的猫猫把三桶鱼全部转移到了她那长方形大池子中,然后开始思考:到底要以何种方法吃鱼呢(猫猫就是这么可爱,吃鱼也要想好吃法 ^_*).她发现,把大池子视为01矩阵(0表示对应位置无鱼,1 ...
- c#写word文档基础操作(自己控制样式)
下面一个函数,建立一个Word 文档,添加页眉.页脚,在内容中两个不同字体的Hello!!! 来自 <http://bbs.csdn.net/topics/340041961> pub ...
- JVM虚拟机 - 内存
在JVM虚拟机中,内存部分大致可以分为以下几类: Heap:堆 NonHeap:非堆 CodeCache:缓存编辑后的机器码的内存区域 CompressedClassSpace:类压缩空间 MetaS ...
- Mavlink协议理解
来源:blog.csdn.net/super_mice/article/details/44836585 之前看了mavlink协议,网上关于mavlink的资料不多.本文大概总结了下对mavlink ...
- agc015F - Kenus the Ancient Greek(结论题)
题意 题目链接 $Q$组询问,每次给出$[x, y]$,定义$f(x, y)$为计算$(x, y)$的最大公约数需要的步数,设$i \leqslant x, j \leqslant y$,求$max( ...
- CAS登录认证的简单介绍
参考博客: https://www.jianshu.com/p/8daeb20abb84 下面是CAS最基本的协议过程: 下面是CAS Web工作流程图: 名词解释 Ticket Grangting ...
- 【转发活动】Hey, 是你吗? | 寻"粉"启示
你知道吗 从 A computer on every desk and in every home 让每张办公桌上和每个家庭都有一台计算机 ▼ 到 Where do you want to go to ...
- cms-最近更新
在这一讲中有几个很重要的地方需要注意: 1.在查询帖子的时候需要把帖子类型id带到帖子类型表中把类型查询出来 2.在字帖子查询语句中用limt限制查询那个阶段的帖子 3.在界面显示的时候需要用到字符串 ...
- 关于添加IBDesignable实时building很卡问题的解决
公共库加了@IBDesignable,可以实时预览图标 但是有个问题,每次打开XIB的时候都会Building,会造成电脑会很卡 有个解决方法,在xcode的Editor下拉框取消auto refre ...
- 显示 Mac隐藏的文件夹 命令语句
默认情况下,模拟器的目录是隐藏的,要想显示出来,需要在Mac终端输入下面的命令 显示Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFil ...