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\n",1.0*ans1/(1.0*720720));
}

最新文章

  1. CSS3中的动画功能(一)
  2. Eclipse安装部署(配图解)
  3. Linux下的多线程编程
  4. java 实现视频转换通用工具类:视频相互转换-总方法及Mencoder(二)
  5. ARCGIS二维三维互动
  6. IOS 创建App的最佳捷径
  7. C和指针 (pointers on C)——第一章:高速启动
  8. ZZNU 1163: 在线判题(指针专题)
  9. AIO5物料清单(BOM)列表,搜索编码和名称无效
  10. 洛谷 [P3355] 骑士共存问题
  11. Java:Java 中会存在内存泄漏吗
  12. Android ViewManager解读之requestLayout() 详解
  13. Socket/ServerSocket 选项
  14. 自己动手python打造渗透工具集
  15. springmvc概述及框架原理
  16. Redis哈希
  17. 如何优化Mysql数据库
  18. Need You Now --Lady Antebellum
  19. layui数据表格使用(一:基础篇,数据展示、分页组件、表格内嵌表单和图片)
  20. struts标签错误:Can not find the tag library descriptor for &quot;http://java.sun.com/jsp/jstl/core&quot;

热门文章

  1. password passphrase passcode 的区别
  2. thinkphp 5.0 代码执行漏洞
  3. 设计模式之笔记--解释器模式(Interpreter)
  4. nginx配置--event模块
  5. javaScript如何跳出多重循环break、continue
  6. css给奇数行或偶数行添加指定样式
  7. procedure of object 对象的函数指针
  8. socket-----爬虫&amp;&amp;文件传输
  9. python实现IMAP协议下email收取
  10. Web前端开发最佳实践(6):过时的块状元素和行内元素