2458

yxc

hlydxxz

Cold_heartless
EWliao

ease

hongk_bb
Fcy
wanghai673
S搁浅S

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>

using namespace std;

const int N = 5e5+10;

int n;
int a[N];
long double res,s;

int main()
{
cin>>n>>s;
for(int i=0;i<n;i++)
scanf("%d", &a[i]);

sort(a,a+n);

long double avg=s/n;
for(int i=0;i<n;i++)
{
double cur=s/(n-i);
if(a[i] < cur)//如果小于平均数就让他取自身
cur=a[i];
res+=(cur-avg)*(cur-avg);
s-=cur;
}
res/=n;
printf("%.4Lf\n",sqrt(res));

return 0;

}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

const int N = 1e3+10;

int n,d;
struct Segment
{
double l,r;
bool operator<(Segment&t)   const
{
return r<t.r;
}
}seg[N];

int main()
{
scanf("%d%d", &n, &d);
bool failed = false;
for(int i=0;i<n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
if(y>d) failed = true;
else
{
double len = sqrt(d*d-y*y);
seg[i].l = x-len, seg[i].r=x+len;
}
}
if(failed)
puts("-1");
else
{
sort(seg,seg+n);

int cnt=0;
double last=-1e20;
for(int i=0;i<n;i++)
{
if(last<seg[i].l)
{
cnt++;
last=seg[i].r;
}
}
printf("%d\n",cnt);
}

return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

const int N = 1e6+10;

typedef long long LL;

int a[N];
int n;
LL c[N];

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

LL sum=0;
for(int i=1;i<=n;i++)    scanf("%d", &a[i]),sum+=a[i];

LL avg = sum/n;
for(int i=n;i>1;i--)
c[i]=c[i+1]+avg-a[i];
c[1]=0;

sort(c+1,c+n+1);

LL res=0;
LL mid=c[(n+1)/2];
for(int i=1;i<=n;i++)   res+=abs(c[i]-mid);

printf("%lld\n",res);

return 0;

}


#include<iostream>
#include<algorithm>

using namespace std;

typedef long long LL;

const int N = 1e5+10;

int a[N];
int n;

int main()
{
scanf("%d", &n);
for(int i=0;i<n;i++)    scanf("%d",&a[i]);
sort(a,a+n);

LL ans;
int c=a[n/2];

for(int i=0;i<n;i++)    ans+=abs(a[i]-c);

printf("%lld\n",ans);

return 0;

}


#include<iostream>
#include<cstdio>

using namespace std;

const int N = 1e5+10;

int a[N];
int n,sum;

int main()
{
scanf("%d", &n);
for(int i=0;i<n;i++)    scanf("%d", &a[i]);

for(int i=0;i<n-1;i++)
if(a[i] < a[i+1])   sum+=a[i+1]-a[i];

printf("%d\n",sum);

return 0;

}


#include<iostream>

using namespace std;

const int N = 1e5+10;

void init()
{
idx=0;
}
{
}
void insert(int k,int x)
{
e[idx]=x,ne[idx]=ne[k],ne[k]=idx++;
}
void remove(int k)
{
ne[k] = ne[ne[k]];
}
int main()
{
int n;
cin>>n;
init();

char c;
int k,x;
while (n -- )
{
cin>>c;
if(c=='H')//插入头节点
{
cin>>x;
}
else if(c=='I')//第k个插入的数后面的
{
cin>>k>>x;
insert(k-1,x);
}
else//删除第k个数后面的数
{
cin>>k;
else    remove(k-1);
}
}

return 0;
}


#include<iostream>
#include<vector>

using namespace std;

struct Edge
{
int id,w;
};

const int N = 1e5+10;

int n;
vector<Edge>h[N];
int dist[N];

void dfs(int u,int father,int distance)
{
dist[u] = distance;

for(auto node:h[u])
if(node.id != father)
dfs(node.id,u,distance+node.w);
}
int main()
{
scanf("%d", &n);
for(int i=0;i<n-1;i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
h[a].push_back({b,c});
h[b].push_back({a,c});
}

dfs(1,-1,0);

int u = 1;
for(int i=1;i<=n;i++)
if(dist[i] > dist[u])
u=i;
dfs(u,-1,0);
for(int i=1;i<=n;i++)
if(dist[i] > dist[u])
u=i;

int s=dist[u];
printf("%lld\n",s*10+s*(s+1ll)/2);
return 0;
}


#include<iostream>
#include<queue>

#define x first
#define y second

using namespace std;

typedef pair<int, int> PII;

const int N = 1e3+10;

char g[N][N];
bool st[N][N];
int n;

int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

void bfs(int sx,int sy, int &total, int &bound)
{
queue<PII> q;
q.push({sx,sy});
st[sx][sy] = true;

while(q.size())
{
auto t = q.front();
q.pop();
bool is_bound=false;
total++;

for(int i=0;i<4;i++)
{
int x=t.x+dx[i], y=t.y+dy[i];
if(x<0 || x>=n || y<0 || y>=n)  continue;
if(st[x][y])    continue;
if(g[x][y]=='.')
{
is_bound=true;
continue;
}
q.push({x,y});
st[x][y] = true;
}
if(is_bound)    bound++;
}
}
int main()
{
scanf("%d", &n);
for(int i=0;i<n;i++)
scanf("%s",g[i]);

int cnt=0;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(!st[i][j] && g[i][j]=='#')
{
int total=0,bound=0;
bfs(i,j,total,bound);
if(total==bound)    cnt++;
}
printf("%d\n",cnt);
return 0;
}


#include<iostream>
#include<queue>
#include<cstring>

using namespace std;

const int N = 110;

char g[N][N][N];
int dist[N][N][N];
int l,r,c;//层 行列

int dx[6] = {1, -1, 0, 0, 0, 0};
int dy[6] = {0, 0, 1, -1, 0, 0};
int dz[6] = {0, 0, 0, 0, 1, -1};

struct Node
{
int x,y,z;
};

int bfs(Node begin,Node end)
{
memset(dist,-1,sizeof dist);
queue<Node> q;
dist[begin.x][begin.y][begin.z] = 0;
q.push(begin);

while(q.size())
{
auto t = q.front();
q.pop();

for(int i=0;i<6;i++)
{
int x=t.x+dx[i], y=t.y+dy[i], z=t.z+dz[i];
if(x<0 || x>=l || y<0 || y>=r || z<0 || z>=c || g[x][y][z] == '#')   continue;
if(dist[x][y][z] != -1)   continue;

dist[x][y][z] = dist[t.x][t.y][t.z]+1;
if(end.x == x && end.y == y && end.z == z)
return dist[x][y][z];

if(g[x][y][z] == '.')   q.push({x,y,z});
}
}
return -1;

}
int main()
{
while(scanf("%d%d%d",&l,&r,&c),l && r && c)
{
Node begin,end;
for (int i=0;i<l;i++)
for (int j=0;j<r;j ++ )
{
scanf("%s", g[i][j]);
for(int k= 0;k<c;k ++ )
{
char c = g[i][j][k];
if (c == 'S') begin = {i, j, k};
else if (c == 'E') end = {i, j, k};
}
}

int ans=bfs(begin,end);
if(ans==-1)     printf("Trapped!\n");
else     printf("Escaped in %d minute(s).\n",ans);
}

return 0;
}


#include<iostream>

using namespace std;

typedef long long LL;

const int N = 1e5+10;

LL a[N];
int n;

int maxh,max_sum;

int main()
{
scanf("%d", &n);
for(int i=1;i<=n;i++)
{
scanf("%lld", &a[i]);
a[i]+=a[i-1];
}
for(int i=1,j=1,depth=1;;depth++)
{
if(a[j]-a[i-1] > max_sum || maxh == 0)
{
maxh = depth;
max_sum = a[j]-a[i-1];
}
i = 2*i, j=2*j+1;
if(j > n)   j=n;
if(i > n)   break;
}
cout<<maxh<<endl;

return 0;
}