http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=358

The 2014 ACM-ICPC Asia Mudanjiang Regional Contest

136 - The 2014 ACM-ICPC Asia Mudanjiang Regional Contest
Solved ID Title Ratio (AC/All)
Yes A Average Score 61.78% (456/738)
Yes B Building Fire Stations 10.40% (36/346)
  C Card Game 0.00% (0/0)
Yes D Domination 40.46% (123/304)
  E Excavator Contest 5.12% (2/39)
  F Fiber-optic Network 23.07% (3/13)
  G Garden and Sprinklers 0.00% (0/41)
  H Hierarchical Notation 9.37% (30/320)
Yes I Information Entropy 53.19% (366/688)
  J Jacobi Pattern 0.00% (0/2)
  K Known Notation 20.96% (96/458)

B Building Fire Stations

题意:给出一个树,找两个点建消防站,使离最近的消防站的距离最远的点的这个距离最小。点有20W个。

题解:这2个消防站肯定在树的直径上,二分这个距离d,分别把2个消防站放在与直径的2个端点距离d的位置。

20W个点,不碉的深搜会Segment Fault,我的深搜可是加了const &的碉深搜,才能过的。

听说的更碉的题解:在直径的中点把树切成两半,分别求直径中点,就得了。

代码:

 //#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define usll unsigned ll
#define mz(array) memset(array, 0, sizeof(array))
#define mf1(array) memset(array, -1, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("huzhi.txt","w",stdout)
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppf pop_front
#define ppb pop_back
const double pi=acos(-1.0);
const double eps=1e-; const int maxn=;
const int maxm=*maxn; int n; struct Edge {
int v,next;
} e[maxm];
int en,head[maxn]; inline void add(const int &x,const int &y) {
e[en].v=y;
e[en].next=head[x];
head[x]=en++;
} int ans[]; int anode,bnode;
int len;
inline void dfs1(const int &x,const int &f,const int &step) {
if(step>len) {
len=step;
anode=x;
}
for(int i=head[x]; i!=-; i=e[i].next) {
if(e[i].v != f) dfs1(e[i].v , x , step+);
}
} bool flag;
int b[maxn],bn;
inline void dfs2(const int &x,const int &f) {
if(x==bnode) {
flag=;
b[bn++]=x;
return;
}
for(int i=head[x]; i!=-; i=e[i].next) {
if(e[i].v != f) {
dfs2(e[i].v , x);
if(flag) {
b[bn++]=x;
return;
}
}
}
} int _dis;
int u[maxn]; inline void dfs3(const int &x,const int &f,const int &step){
if(step>_dis) {
return;
}
u[x]=;
for(int i=head[x]; i!=-; i=e[i].next) {
if(e[i].v != f) dfs3(e[i].v , x , step+);
}
} inline bool ok(const int &dis){
int i;
int nodec=b[dis];
int noded=b[bn--dis];
len=;
_dis=dis;
memset(u,,sizeof(u));
dfs3(nodec,-,);
dfs3(noded,-,);
FOR(i,,n)if(!u[i])return ;
return ;
}
inline void farm() {
int i;
len=;
dfs1(,-,);
//printf("%d!\n",anode);
bnode=anode;
len=;
dfs1(bnode,-,);
//printf("%d!\n",anode);
flag=,bn=;
dfs2(anode,-);
// FOR(i,0,bn-1)printf("%d ,",b[i]);
// printf("(a=%d , b=%d)\n",anode,bnode); int an;
int l=,r=bn-,mid;
while(l<=r){
mid=(l+r)>>;
// printf("%d,%d,%d\n",l,mid,r);
if(ok(mid))r=mid-,an=mid;
else l=mid+;
}
ans[]=an;
ans[]=b[an];
ans[]=b[bn--an];
if(ans[]==ans[])ans[]=(ans[])%n+;
return;
} int main() {
//re;
int T;
int i,j,x,y;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
memset(head,-,sizeof(head));
en=;
REP(i,n-) {
scanf("%d%d",&x,&y);
add(x,y);
add(y,x);
}
farm();
printf("%d %d %d\n",ans[],ans[],ans[]);
}
return ;
}

D Domination

题意:在棋盘上没有棋的地方随机放棋,直到每一列每一行都有棋,求步数的期望。

题解:DP。dp[i][j][k]表示已经有i行有棋、j列有棋、已经放了k个棋 这种情况的概率。

我们是6000ms险过,也许DP的方式不对?

代码:

 #include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; #define REP(i,n) for(i=0;i<n;i++)
#define FOR(i,x,y) for(i=x;i<=y;i++)
#define mz(x) memset(x,0,sizeof(x))
#define re freopen("in.txt","r",stdin)
#define pb push_back
#define ll long long
#define maxn 50005
#define mod 1000000009 double dp[][][];
int n,m; double dfs(int x,int y,int z) {
if(x== || y== || z==)return dp[x][y][z]=0.0;
if(dp[x][y][z]>=-0.5)return dp[x][y][z];
dp[x][y][z]=dfs(x-,y,z-)*(n-x+)*y + dfs(x,y-,z-)*(m-y+)*x + dfs(x-,y-,z-)*(m-y+)*(n-x+);
if(x!=n || y!=m) dp[x][y][z]+= dfs(x,y,z-)*(x*y-z+);
dp[x][y][z]/=(double)(n*m-z+);
//printf("(%d,%d,%d) %lf\n",x,y,z,dp[x][y][z]);
return dp[x][y][z];
} double farm(int _n,int _m) {
int i,j,k;
n=_n,m=_m;
FOR(i,,n)FOR(j,,m)FOR(k,,n*m)dp[i][j][k]=-1.0;
dp[][][]=1.0;
FOR(i,,n)dp[i][][i]=dp[i-][][i-]*(n-i+)/(n*m-i+);
FOR(i,,m)dp[][i][i]=dp[][i-][i-]*(m-i+)/(n*m-i+);
double ans=0.0;
FOR(i,,n*m) {
ans+=dfs(n,m,i)*i;
//printf("%d %lf\n",i,dfs(n,m,i));
}
//printf("%.12lf\n",E);
return ans;
} int main() {
//re;
int T;
int n,m;
scanf("%d",&T);
while(T--) {
scanf("%d%d",&n,&m);
printf("%.12lf\n",farm(n,m));
}
return ;
}

I Information Entropy

直接算,那啥是0的时候那个极限求完就是0。

代码:

 #include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; #define re freopen("in.txt","r",stdin)
#define pb push_back
#define ll long long
#define maxn 50005
#define mod 1000000009
const double e=2.7182818284590452353602874;
int n;
int p[];
char s[]; double farm() {
double hx=0.0;
sort(p,p+n);
if(s[]=='n') {
for(int i=; i<n; i++) {
if(p[i]!=) hx-=(1.0*p[i]) * (log(1.0*p[i]));
}
hx-=log(0.01)*100.0;
return hx;
} else if( s[]=='d') {
for(int i=; i<n; i++) {
if(p[i]!=) hx-=(1.0*p[i]) * (log10(1.0*p[i]));
}
hx+=200.0;
return hx;
} else if(s[]=='b') {
for(int i=; i<n; i++) {
if(p[i]!=) hx-=(1.0*p[i]) * (log2(1.0*p[i]));
}
hx-=log2(0.01)*100.0;
return hx;
}
} int main() {
//re;
int T;
scanf("%d",&T);
while(T--) {
scanf("%d%s",&n,s);
for(int i=; i<n; i++) {
scanf("%d",&p[i]);
}
printf("%.12lf\n",farm()/100.0);
}
return ;
}

2014 牡丹江区域赛 B D I的更多相关文章

  1. The 2014 ACM-ICPC Asia Mudanjiang Regional Contest(2014牡丹江区域赛)

    The 2014 ACM-ICPC Asia Mudanjiang Regional Contest 题目链接 没去现场.做的网络同步赛.感觉还能够,搞了6题 A:这是签到题,对于A堆除掉.假设没剩余 ...

  2. zoj 3822 Domination(2014牡丹江区域赛D称号)

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  3. 2014牡丹江区域赛H(特里)ZOJ3826

    Hierarchical Notation Time Limit: 2 Seconds      Memory Limit: 131072 KB In Marjar University, stude ...

  4. ZOJ 3827 Information Entropy (2014牡丹江区域赛)

    题目链接:ZOJ 3827 Information Entropy 依据题目的公式算吧,那个极限是0 AC代码: #include <stdio.h> #include <strin ...

  5. ACM学习历程——ZOJ 3822 Domination (2014牡丹江区域赛 D题)(概率,数学递推)

    Description Edward is the headmaster of Marjar University. He is enthusiastic about chess and often ...

  6. ACM学习历程——ZOJ 3829 Known Notation (2014牡丹江区域赛K题)(策略,栈)

    Description Do you know reverse Polish notation (RPN)? It is a known notation in the area of mathema ...

  7. zoj 3822 Domination(2014牡丹江区域赛D题) (概率dp)

    3799567 2014-10-14 10:13:59                                                                     Acce ...

  8. ZOJ 3822 ( 2014牡丹江区域赛D题) (概率dp)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 题意:每天往n*m的棋盘上放一颗棋子,求多少天能将棋盘的每行每列都至少有 ...

  9. ZOJ3827 ACM-ICPC 2014 亚洲区域赛的比赛现场牡丹江I称号 Information Entropy 水的问题

    Information Entropy Time Limit: 2 Seconds      Memory Limit: 131072 KB      Special Judge Informatio ...

随机推荐

  1. python-generator生成杨辉三角

    根据廖雪峰老师的评论区摘录. 1: def triangles(): L = [1] while True: yield L L1 = [0] + L[:] L = [L[i]+L1[i] for i ...

  2. 图像卷积、相关以及在MATLAB中的操作

    图像卷积.相关以及在MATLAB中的操作 2016年7月11日 20:34:35, By ChrisZZ 区分卷积和相关 图像处理中常常需要用一个滤波器做空间滤波操作.空间滤波操作有时候也被叫做卷积滤 ...

  3. 【BZOJ-2756】奇怪的游戏 最大流 + 分类讨论 + 二分

    2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 2925  Solved: 792[Submit][Stat ...

  4. 深入解析direct path read (转)

    文章转自:http://www.itpub.net/thread-1815281-1-1.html 传统读取数据的方式是服务器进程通过读取磁盘,然后把数据加载到共享内存中,这样后面的进程就可以通过共享 ...

  5. 一、swoole安装

    说明:swoole扩展需要安装php环境,这里就不说了. 1.有了PHP环境后,即可安装swoole扩展. swoole扩展下载地址:https://github.com/swoole/swoole- ...

  6. 洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication

    题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...

  7. 上班遇到的——关于Web安全

    恩只是流水账,内容写得可能比较随性,权当记录自己的成长:-D 今天经理特地开会跟我们讲了一下关于web安全的东西,SQL注入.文本编辑器.上传.本身程序权限管理漏洞 感觉好高级,做安全的人厉害,黑客也 ...

  8. RabbitMQ 通过记日志来看routingkey

    RoutingKey 每个项目都需要记录日志,日志则一般会分为多种级别,常见的是 Info.debug.warn.Error 对于前三种日志,在项目运行中会产生大量的消息,但是一般多数情况下是不会用到 ...

  9. HDU5671Matrix(矩阵行列交换)

    有一个nn行mm列的矩阵(1 \leq n \leq 1000 ,1 \leq m \leq 1000 )(1≤n≤1000,1≤m≤1000),在这个矩阵上进行qq (1 \leq q \leq 1 ...

  10. 理解Docker单机容器网络

    在” 理解Docker单机容器网络 “一文中,还有一个Docker容器网络的功能尚未提及,那就是Docker容器的端口映射.即将容器的服务端口P’ 绑定到宿主机的端口P上,最终达到一种效果:外部程序通 ...