2020 China Collegiate Programming Contest Weihai Site
文章目录
威海赛的签到题
A Golden Spirit
思路:假设初始时我们在左边,那么运完2* n个人后,我们又回到左边,这时只有两种选择,
一:运左边的人,但有两种情况,1:最早来到左边的人休息完毕,可以直接运走。 2:最早来到左边的人尚未休息完,需要等待 x-(2* n* t-2* t)的时间。
所以,这时多花的时间就是max(0,x-(2* n* t -2* t))
二: 运右边的人,首先需要过河时间t,但之后也有两种情况, 1: 最早来到右边的人已经休息完毕,可以直接运走。 2: 最早来到右边的人尚未休息完,需要等待的时间为x-(t+2* n* t-t),即x-2* n* t。
所以,此时多花的时间就是max(t,t+x-2* n* t)
综上,多花时间就是min(max(0,x-(2* n* t-2* t)),max(t,t+x-2* n* t))
之后,我们容易证明,接下来的人都是已经休息完毕的,所以答案就是2* n* t+min(max(0,x-(2* n* t-2* t )),max(t,t+x-2* n* t))+2* n* t
代码如下:
#include <iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
int T;
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
while(cin>>T){
while(T--){
ll n,x,t;
cin>>n>>x>>t;
ll ans=4*n*t;
ans+=min(max(0ll,x-2*n*t+2*t),max(x-2*n*t+t,t));
cout<<ans<<endl;
}
}
return 0;
}
D ABC Conjecture
思路:
按题目公式来,发现,对于数c,如果c为质数,则rad(abc)>=c恒成立,如果c为合数,且rad(c)>=c,那么同样rad(abc)>=c,所以,既是合数又满足rad(c)<c的c,输出yes,反之,no.
代码直接大整数分解找质因子,米勒测试判断素数
代码如下:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
const int Times = 10;
const int N = 5500;
using namespace std;
typedef long long LL;
LL ct, cnt;
LL fac[N];
LL gcd(LL a, LL b)
{
return b? gcd(b, a % b) : a;
}
LL multi(LL a, LL b, LL m)
{
LL ans = 0;
a %= m;
while(b)
{
if(b & 1)
{
ans = (ans + a) % m;
b--;
}
b >>= 1;
a = (a + a) % m;
}
return ans;
}
LL quick_mod(LL a, LL b, LL m)
{
LL ans = 1;
a %= m;
while(b)
{
if(b & 1)
{
ans = multi(ans, a, m);
b--;
}
b >>= 1;
a = multi(a, a, m);
}
return ans;
}
bool Miller_Rabin(LL n)
{
if(n == 2) return true;
if(n < 2 || !(n & 1)) return false;
LL m = n - 1;
int k = 0;
while((m & 1) == 0)
{
k++;
m >>= 1;
}
for(int i=0; i<Times; i++)
{
LL a = rand() % (n - 1) + 1;
LL x = quick_mod(a, m, n);
LL y = 0;
for(int j=0; j<k; j++)
{
y = multi(x, x, n);
if(y == 1 && x != 1 && x != n - 1) return false;
x = y;
}
if(y != 1) return false;
}
return true;
}
LL pollard_rho(LL n, LL c)
{
LL i = 1, k = 2;
LL x = rand() % (n - 1) + 1;
LL y = x;
while(true)
{
i++;
x = (multi(x, x, n) + c) % n;
LL d = gcd((y - x + n) % n, n);
if(1 < d && d < n) return d;
if(y == x) return n;
if(i == k)
{
y = x;
k <<= 1;
}
}
}
void find(LL n, int c)
{
if(n == 1) return;
if(Miller_Rabin(n))
{
fac[ct++] = n;
return ;
}
LL p = n;
LL k = c;
while(p >= n) p = pollard_rho(p, c--);
find(p, k);
find(n / p, k);
}
bool rad(LL ji,LL n){
ct = 0;
memset(fac,0,sizeof(fac));
find(ji, 120);
set<LL> fact;
for(int i=0;i<ct;i++){
fact.insert(fac[i]);
}
set<LL>:: iterator it;
LL ans=1;
for(it=fact.begin();it!=fact.end();it++)
ans*=*it;
if(ans<n)
return 1;
return 0;
}
int main()
{
int T;
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>T;
while(T--){
LL n;
cin>>n;
{
if(!Miller_Rabin(n)&&rad(n,n))
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
}
return 0;
}
L Clock Master
思路:
不难发现,我们要把b分成的a1,a2,a3,……,an求出其lcm(a1,a2,a3,……,an),并使得lcm最大,所以,我们在构造时,就应当使得ai尽可能的为素数或者是素数的整数次幂。而在这其中,每种质数或者质数的k次幂,我们只能选一个,因此,这就有点像在花费log(a1)的情况下,我们要使得容量也就是lcm最大,经过学长指点,原来这是分组背包。。。。
代码如下:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
const int maxn=3e4+5;
double f[maxn];
double Log[maxn];
int prime[maxn];
bool vis[maxn];
void urla(){
for(int i=2;i<=maxn;i++){
if(!vis[i])
prime[++prime[0]]=i;
for(int j=1;j<=prime[0]&&i*prime[j]<=maxn;j++){
vis[i*prime[j]]=1;
if(i%prime[j]==0)
break;
}
}
}
void init(){
for(int i=1;i<=maxn;i++){
f[i]=0;
Log[i]=log(i);
}
urla();
for(int k=1;k<=prime[0];k++) //从最小的质数开始找
for(int v=maxn;v>=prime[k];v--) //容量要从大往小找,不然容易漏,截止条件就是能装得下当前的质数
for(int i=prime[k];i<=v;i*=prime[k])
f[v]=max(f[v],f[v-i]+Log[i]);
}
int main(){
int T;
init();
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>T;
while(T--){
int b;
cin>>b;
cout<<fixed<<setprecision(6)<<f[b]<<endl;
}
return 0;
}