[April Fools Day Contest 2016B] [폭력] Scrambled는 최소한 하나의 모델 a여b를 만족시킨다

B. Scrambled
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output
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.
Examples
input
1
2
0

output
0.500000

input
2
2 3
1 0

output
0.666667
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 20, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int a[N], b[N];
int n;
int main()
{
	while (~scanf("%d", &n))
	{
		for (int i = 1; i <= n; ++i)scanf("%d", &a[i]);
		for (int i = 1; i <= n; ++i)scanf("%d", &b[i]);
		double ans = 0;
		for (int i = 1; i <= 1000000; ++i)
		{
			bool flag = 1;
			for (int j = 1; j <= n; ++j)
			{
				if (i%a[j] == b[j]) { flag = 0; break; }
			}
			if (flag==0)ans += 1e-6;
		}
		printf("%.15f
", ans); } return 0; } /* 【 】 n(16) a[] b[] , x, i x mod a[i] == b[i] , x 。 【 】 【 】 , 。 LCM , 。 AC ! */

좋은 웹페이지 즐겨찾기