# Codeforces Round #614 (Div. 2)

## A. ConneR and the A.R.C. Markland-N

#### 题解

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef pair<int,int> PII;
#define X first
#define Y second
{
int x=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}
return x*f;
}
const int maxn=1010;
int T,n,s,k,a[maxn];
int main()
{
while(T--)
{
bool ok=0;
for(int i=1;i<=k;i++)
{
if(a[i]==s)ok=1;
}
if(!ok){printf("0\n");continue;}
sort(a+1,a+k+1);
int pos=0,ans=2147483647,tmp;
for(int i=1;i<=k;i++)if(a[i]==s)pos=i;
tmp=pos;
while(tmp && s-a[tmp]==pos-tmp)tmp--;
if(a[tmp+1]!=1)ans=pos-tmp;
tmp=pos;
while(tmp<=k && a[tmp]-s==tmp-pos)tmp++;
if(a[tmp-1]!=n)ans=min(ans,tmp-pos);
printf("%d\n",ans);
}
return 0;
}


## B. JOE is on TV!

#### 题解

$f[i]$ 表示$i$ 时候的最优解，转移很显然：$f[i]=max (f[j]+1-j/i)$ ，然后再稍微动动脑子就会发现$j=i-1$ 的时候最优，然后就递推$O(n)$ 就好了

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef pair<int,int> PII;
#define X first
#define Y second
{
int x=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}
return x*f;
}
double f[100010];
int n;
int main()
{
f[1]=1.0;
for(int i=2;i<=n;i++)f[i]=f[i-1]+1.0-(double)(i-1)/(double)i;
printf("%.10lf\n",f[n]);
return 0;
}


## C. NEKO's Maze Game

#### 题解

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef pair<int,int> PII;
#define X first
#define Y second
{
int x=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}
return x*f;
}
const int maxn=100010;
int n,Q,x,y,blo[3][maxn],blocked;
int main()
{
while(Q--)
{
blo[x][y]^=1;
if(blo[x][y])
{
for(int i=-1;i<=1;i++)
if(y+i>=1 && y+i<=n && blo[3-x][y+i])blocked++;
}
else
{
for(int i=-1;i<=1;i++)
if(y+i>=1 && y+i<=n && blo[3-x][y+i])blocked--;
}
if(!blocked)printf("Yes\n");
else printf("No\n");
}
return 0;
}


#### 题解

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef pair<int,int> PII;
#define X first
#define Y second
{
LL x=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}
return x*f;
}
const int maxn=10000;
LL X0,Y0,ax,ay,bx,by,xs,ys,t,x[maxn],y[maxn],xx[maxn],yy[maxn],End,len,ans,tans;
LL labs(LL a){return a<0 ? -a : a;}
LL dis(LL a,LL b,LL c,LL d){return labs(c-a)+labs(d-b);}
int main()
{
x[End]=X0,y[End++]=Y0;
while(dis(x[0],y[0],ax*x[End-1]+bx,ay*y[End-1]+by)<=3ll*(LL)1e16)x[End]=ax*x[End-1]+bx,y[End]=ay*y[End-1]+by,End++;
for(int i=0;i<End;i++)if(dis(xs,ys,x[i],y[i])<=t)xx[len]=x[i],yy[len++]=y[i];
for(int i=0;i<len;i++)
{
LL step=t-dis(xx[i],yy[i],xs,ys),tans=1;
int pos=i;
while(pos+1<len && step-dis(xx[pos],yy[pos],xx[pos+1],yy[pos+1])>=0)tans++,step-=dis(xx[pos],yy[pos],xx[pos+1],yy[pos+1]),pos++;
ans=max(ans,tans);
step=t-dis(xx[i],yy[i],xs,ys),tans=1;pos=i;
while(pos-1>=0 && step-dis(xx[pos],yy[pos],xx[pos-1],yy[pos-1])>=0)tans++,step-=dis(xx[pos],yy[pos],xx[pos-1],yy[pos-1]),pos--;
ans=max(ans,tans);
}
cout<<ans<<endl;
return 0;
}


## E. Xenon's Attack on the Gangs

#### 题解

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=3e3+10;
ll sz[maxn][maxn];
ll f[maxn][maxn];
ll dp[maxn][maxn];
struct Edge{
ll v,next;
}e[maxn<<1];
ll cnt=0;
e[cnt].v=v;
}
void dfs(ll u,ll fa,ll root){
sz[root][u]=1;
f[root][u]=fa;
ll v=e[i].v;
if(v==fa)continue;
dfs(v,u,root);
sz[root][u]+=sz[root][v];
}
}
ll solve(ll i,ll j){
if(dp[i][j]!=-1)return dp[i][j];
if(i==j)return dp[i][j]=0;
return dp[i][j]=sz[i][j]*sz[j][i]+max(solve(f[i][j],i),solve(f[j][i],j));
}
int main(){
memset(dp,-1,sizeof(dp));
ll n;
scanf("%lld",&n);
for(ll i=1;i<n;i++){
ll u,v;
scanf("%lld%lld",&u,&v);
}
for(ll i=1;i<=n;i++){
dfs(i,-1,i);
}
ll ans=0;
for(ll i=1;i<=n;i++){
for(ll j=1;j<=n;j++){
ans=max(ans,solve(i,j));
}
}
cout<<ans<<endl;
}


## F. Chaotic V.

#### 题解

#include <bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda

using namespace std;
const int N = 5000 + 12, mod = int(1e9)  + 7;

int n,lp[N],cnt[N],c1[N], pref[N], c2[N], d[N], pr[N], pn,num[N], dist[N][N];
ll ans;

int sz;
vector <int> g[N], all;

int main () {
scanf("%d", &n);

for(int i = 1,x; i <= n; i++){
scanf("%d", &x);
sz = max(sz, x);
if(x == 0) x++;
cnt[x]++;
}

//sz = 5000;

for(int i = 2; i <= sz; i++) if(!lp[i]){
pr[++pn] = i;
num[i] = pn;
for(int j = i; j <= sz; j += i) lp[j] = i;
}
for(int i = 2,x,p; i <= sz; i++){
x = i;
d[i] += d[i - 1];
while(x > 1){
p = lp[x];
while(x % p == 0){
x /= p;
d[i]++;
}
}
}
for(int i = 1,x,p; i <= sz; i++){
x = i;
while(x > 1){
p = lp[x];
while(x % p == 0){
x /= p;
c1[num[p]]++;
}
}
for(int j = 1; j <= pn; j++){
if(c1[j] > 0){
int x = c1[j];
while(x --> 0){
g[i].pb(j);
}
}
}
all.pb(i);
}

ans = 0;

for(int i : all){
ans += 1ll * cnt[i] * d[i];
}

while(true){
int res = 0, mx = 0, id = 0;
for(int i : all){
res += cnt[i];
if(g[i].size() > 0){
c2[g[i].back()] += cnt[i];
}
}
for(int j = 1; j <= pn; j++){
if(c2[j] > mx){
mx = c2[j];
id = j;
}
c2[j] = 0;
}
if(2 * mx <= n){
break;
}
else{
ans += n - 2 * mx;
vector <int> cur;
for(int i : all){
if(g[i].size() > 0 && g[i].back() == id){
g[i].pop_back();
cur.pb(i);
}
}
all = cur;
}
}

printf("%lld", ans);

return 0;
}


### 废话

posted @ 2020-01-21 14:12  小飞淙的云端  阅读(92)  评论(0编辑  收藏