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