CodeForces 948B Primal Sport】的更多相关文章

Primal Sport 题意:2个人玩游戏, 每次轮到一个人选择一个比当前值小的素数, 然后在找到比素数的倍数中最小的并且不小于当前数的一个数. 现在这个游戏玩了2轮, 现在想找到最小的那个起点X0. 题解:我们可以发现样例解释中每次都是先减去最大的那个素数, 然后再从 减去后的数+1(如果不加一那么将导致通过这个素数发现最小的公倍数是减去数的本身) 到 n, 找到最小的那个值.因为要X0尽量小, 所以每一步都要能减去尽量大的数. 因为要找到最大的数, 所以我们先 素数塞跑出 当前值能找到最大…
A. Primal Sport time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Alice and Bob begin their day with a quick game. They first choose a starting number X0 ≥ 3 and try to reach one million b…
http://codeforces.com/contest/923/problem/A 题意: 初始有一个x0,可以选择任意一个<x0的质数p,之后得到x1为≥x0最小的p的倍数 然后再通过x1按照一样的算法得出一个x2 已知x2,问x0最小可能是多少 设f[x] 表示<x 的最大的x的质因数 那么x1 ∈ [x2-f[x2]+1,x2] 同理,可以得到x0 #include<cstdio> using namespace std; ]; #define min(x,y) ( (x…
[题目链接] 点击打开链接 [算法] 不难看出,x1的范围是[x2-P(x2)+1,x2],x0的范围是[x1-P(x1)+1,x1] 我们可以先做一遍线性筛,然后暴力就可以了 [代码] #include<bits/stdc++.h> using namespace std; const int MAXN = 1e6; int i,j,k,tmp,x,l,ans; ]; vector<int> Prime; template <typename T> inline vo…
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 考虑怎么得到数字x2=N,假设是质数p的倍数 那么x1肯定在x2-p+1~x2这个范围内才行 因为p的倍数要刚好大于等于x1, 所以x1肯定是在这两个倍数之间才行 结果已经很显然了 肯定让p的值越大越好. 这样得到的x1才可能越小. 枚举x1在x2-p+1~x2之间. 用同样的方式得到x0就好. [代码] #include <bits/stdc++.h> using namespace std; const int N = 1e5; i…
Alice and Bob begin their day with a quick game. They first choose a starting number X0 ≥ 3 and try to reach one million by the process described below. Alice goes first and then they take alternating turns. In the i-th turn, the player whose turn it…
题目链接:http://codeforces.com/contest/948/problem/B 知识点: 素数 解题思路: \(f(x)\) 表示 \(x\) 的最大素因子.不难想到:\(X_1 \in [X_2 - f(X_2) + 1, X]\),对于这个范围中的每一个非素数 \(X_1\) 求出其对应的最小的 \(X_0 = X_1 - f(X_1) + 1\),找出一个最小的即为答案. 重点是要想到提前打出 \(f()\) 的表. AC代码: #include <bits/stdc++…
Description 题目链接 Solution 设f(x)为x的最大质因子 那么由题意易得\(X_1\)的范围在\([X_2-f(X_2)+1,X2]\) 同理\(X_0\)的范围在\([X_1-f(X_1)+1,X1]\) 枚举\(X_1\)即可 Code #include<cstdio> #include<algorithm> using namespace std; int n,tmp,Ans=1e9,f[1000010]; void Init(){ for(int i=…
[A]Protect Sheep 题意: 一个\(R*C\)的牧场中有一些羊和一些狼,如果狼在羊旁边就会把羊吃掉. 可以在空地上放狗,狼不能通过有狗的地方,狼的行走是四联通的. 问是否能够保护所有的羊不被狼吃掉,如果能输出方案. 题解: 判断是否有羊的旁边有狼,有的话就-1.没有的话把所有空地换成狗就好. #include<bits/stdc++.h> #define F(i,a,b) for(int i=a;i<=(b);++i) #define F2(i,a,b) for(int i…
A. Primal Sport 题意:有两个人轮流玩游戏.给出数X(i-1),轮到的人需要找到一个小于X(i-1)的素数x,然后得到Xi,Xi是x的倍数中大于等于X(i-1)的最小的数.现在已知X2,求最小的X0? 思路:根据题意,X1的取值范围为[X1-X2的最大质因子+1,X2),同理可知X0的取值范围为[X1-X1的最大质因子+1,,X1). #include<iostream> #include<cstring> #include<cstdio> #includ…