# Codeforces Round #660(CF1388)

## A Captain Flint and Crew Recruitment

### 题解

div2的前几题还是简单的。。最小的几个近似质数是6,10,14 。直接将这3个作为分n时的那三个近似质数，那么能够分的条件显然就是$n>30$ ，然后把$36,40,44$ 另外判断掉就可以了。

### $Code$

#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N=3e5+10;
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void print(LL x){
if(x>9) print(x/10);
putchar(x%10+'0');
}
int n;
int main(){
int T;scanf("%d",&T);
while(T--){
scanf("%d",&n);
if(n==36){
cout<<"YES"<<endl;
cout<<"5 6 10 15"<<endl;
}
else if(n==40){
cout<<"YES"<<endl;
cout<<"9 6 10 15"<<endl;
}
else if(n==44){
cout<<"YES"<<endl;
cout<<"6 7 10 21"<<endl;
}
else if(n>30){
cout<<"YES"<<endl;
printf("%d %d %d %d\n",6,10,14,n-30);
}
else {
printf("NO\n");
}
}
return 0;
}


## B Captain Flint and a Long Voyage

### $Code$

#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N=3e5+10;
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void print(LL x){
if(x>9) print(x/10);
putchar(x%10+'0');
}
int n,m;
int main(){
int T;scanf("%d",&T);
while(T--){
scanf("%d",&n);
m=(n+3)/4;
for(int i=1;i<=n-m;++i) putchar('9');
for(int i=1;i<=m;++i) putchar('8');
puts("");
}
return 0;
}


## C Uncle Bogdan and Country Happiness

### $Code$

#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N=2e5+10;
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void print(LL x){
if(x>9) print(x/10);
putchar(x%10+'0');
}
int n,m,cnt=1;
int hed[N],p[N],h[N],vis[N],siz[N],A[N],B[N];
bool flag;
struct edge{
int r,nxt;
}e[N<<1];
void insert(int u,int v){
e[++cnt].r=v;e[cnt].nxt=hed[u];hed[u]=cnt;
}
void J(int x){
vis[x]=1;
siz[x]=p[x];
int aa=0,bb=0;
for(int i=hed[x];i;i=e[i].nxt){
if(vis[e[i].r]) continue;
J(e[i].r);
siz[x]+=siz[e[i].r];
aa+=A[e[i].r];bb+=B[e[i].r];
}
if((h[x]+siz[x])%2!=0) {
flag=0;
return;
}
A[x]=(h[x]+siz[x])/2;
B[x]=siz[x]-A[x];
if(A[x]<0||B[x]<0) flag=0;
if(aa>A[x]) flag=0;
}
int main(){
int T,u,v;scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);cnt=1;
for(int i=1;i<=n;++i) scanf("%d",&p[i]);
for(int i=1;i<=n;++i) scanf("%d",&h[i]);
for(int i=1;i<n;++i){
scanf("%d%d",&u,&v);
insert(u,v);insert(v,u);
}
flag=1;
J(1);
if(!flag) printf("NO\n");
else printf("YES\n");
for(int i=1;i<=n;++i){
hed[i]=p[i]=h[i]=vis[i]=siz[i]=A[i]=B[i]=0;
}
}
return 0;
}


## D Captain Flint and Treasure

### $Code$

#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N=2e5+10;
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void print(LL x){
if(x>9) print(x/10);
putchar(x%10+'0');
}
int n,m,cnt=1;
int du[N],b[N],p[N];
LL a[N];
queue<int> Q;
LL ans=0;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%I64d",&a[i]);
for(int i=1;i<=n;++i) {
scanf("%d",&b[i]);
if(b[i]!=-1)du[b[i]]++;
}
for(int i=1;i<=n;++i) if(!du[i]) Q.push(i);
int l=1,r=n,x;
while(!Q.empty()){
x=Q.front();Q.pop();
ans+=a[x];
if(a[x]<0){
p[r]=x;--r;
if(b[x]!=-1){
--du[b[x]];
if(!du[b[x]]) Q.push(b[x]);
}
}
else{
p[l]=x;++l;
if(b[x]!=-1){
a[b[x]]+=a[x];
--du[b[x]];
if(!du[b[x]]) Q.push(b[x]);
}
}
}
printf("%I64d\n",ans);
for(int i=1;i<=n;++i) printf("%d ",p[i]);puts("");
return 0;
}


## E Uncle Bogdan and Projections

### $Code$

#include <bits/stdc++.h>
#define LL long long
#define DB long double
using namespace std;
const int N=2e3+10;
const DB inf=1e18;
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void print(LL x){
if(x>9) print(x/10);
putchar(x%10+'0');
}
int n,m;
struct edge{
int x[2],y;
}e[N];
bool cmp(edge A,edge B){
return A.y<B.y;
}
DB ans1,ans2;
vector< pair<DB,int> > p;
vector<DB>p2,mn,mx;
struct P{
int x,y;
P(int xx=0,int yy=0){x=xx;y=yy;}
}lu,rd,a[N<<1];
P operator - (P A,P B){
return P(A.x-B.x,A.y-B.y);
}
LL cha(P A,P B){
return (LL)B.y*A.x-(LL)A.y*B.x;
}
bool cmpa(P A,P B){
if(atan2(A.y-a[1].y,A.x-a[1].x)!=atan2(B.y-a[1].y,B.x-a[1].x))
return atan2(A.y-a[1].y,A.x-a[1].x)>atan2(B.y-a[1].y,B.x-a[1].x);
if(A.y!=B.y) return A.y>B.y;
return A.x<B.x;
}

int main(){
int cnt=0;
scanf("%d",&n);m=0;
lu.x=2e9;lu.y=-2e9;rd.x=-2e9;rd.y=2e9;
for(int i=1;i<=n;++i){
scanf("%d%d%d",&e[i].x[0],&e[i].x[1],&e[i].y);
++m;a[m].x=e[i].x[0];a[m].y=e[i].y;
if(a[m].y>lu.y||(a[m].y==lu.y&&a[m].x<lu.x)) lu=a[m];
if(a[m].y<rd.y||(a[m].y==rd.y&&a[m].x>rd.x)) rd=a[m];
++m;a[m].x=e[i].x[1];a[m].y=e[i].y;
if(a[m].y>lu.y||(a[m].y==lu.y&&a[m].x<lu.x)) lu=a[m];
if(a[m].y<rd.y||(a[m].y==rd.y&&a[m].x>rd.x)) rd=a[m];
}
for(int i=1;i<=m;++i){
if(a[i].x==lu.x&&a[i].y==lu.y){
swap(a[i],a[1]);
break;
}
}
sort(a+2,a+m+1,cmpa);
cnt=2;
for(int i=3;i<=m;++i){
while((cnt>=2&&cha(a[i]-a[cnt-1],a[cnt]-a[cnt-1])==0)||
(cnt>=3&&cha(a[i]-a[cnt-2],a[cnt]-a[cnt-2])+cha(a[cnt]-a[cnt-2],a[cnt-1]-a[cnt-2])<=cha(a[i]-a[cnt-2],a[cnt-1]-a[cnt-2]))) --cnt;
a[++cnt]=a[i];
}
if(cnt>=3&&cha(a[cnt]-a[1],a[cnt-1]-a[1])==0) --cnt;
m=cnt;a[m+1]=a[1];
sort(e+1,e+1+n,cmp);
DB l=inf,r=-inf;
for(int i=1;i<=n;++i){
for(int j=i+1;j<=n;++j){
if(e[i].y==e[j].y) continue;
p.push_back({(DB)(e[i].x[0]-e[j].x[1])/(DB)(e[j].y-e[i].y),2});
p.push_back({(DB)(e[i].x[1]-e[j].x[0])/(DB)(e[j].y-e[i].y),1});
}
}
sort(p.begin(),p.end());
cnt=0;
for(int i=0;i<p.size();++i) {
if(p[i].second==2){
if(!cnt) p2.push_back(p[i].first);
++cnt;
}
else{
--cnt;
if(!cnt) p2.push_back(p[i].first);
}
}
if(!p2.size()) p2.push_back(0);
int now=m+1;
for(int i=0;i<p2.size();++i){
while((DB)a[now].y*p2[i]+(DB)a[now].x>=(DB)a[now-1].y*p2[i]+(DB)a[now-1].x&&now>1) --now;
mn.push_back((DB)a[now].y*p2[i]+(DB)a[now].x);
}
for(int i=1;i<=m;++i){
if(a[i].x==rd.x&&a[i].y==rd.y){
swap(a[i],a[1]);
break;
}
}
sort(a+2,a+m+1,cmpa);
a[m+1]=a[1];
now=m+1;
for(int i=0;i<p2.size();++i){
while((DB)a[now].y*p2[i]+(DB)a[now].x<=(DB)a[now-1].y*p2[i]+(DB)a[now-1].x&&now>1) --now;
mx.push_back((DB)a[now].y*p2[i]+(DB)a[now].x);
}
DB ans=mx[0]-mn[0];
for(int i=0;i<p2.size();++i){
if(mx[i]-mn[i]<ans) ans=mx[i]-mn[i];
}
printf("%0.8Lf\n",ans);
return 0;
}

posted @ 2020-08-02 00:19  Iscream-2001  阅读(154)  评论(0编辑  收藏  举报
/* */