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. K米APP案例分析

    关于 K米 -- 的案例分析 产品 K米的APP (全国KTV点歌,手机直播,互动,交友,预订)的Android客户端 第一部分 调研,评测 评测: 软件的bug,功能评测,黑箱测试 • 下载并使用, ...

  2. C#调用Windows API函数截图

    界面如下: 下面放了一个PictureBox 首先是声明函数: //这里是调用 Windows API函数来进行截图 //首先导入库文件 [System.Runtime.InteropServices ...

  3. Linux下python升级至2.7

    1. 下载python源码包 wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz2. 解压 tar -xjf Python-2.7 ...

  4. mysql中常用的字符串函数

    写在分割线之前,个人以为,数据库应该具备简单的的数据加工能力.如同食品在吃之前,是要经过很多到工序的,有经过初加工.粗加工.精加工.深加工等.那么mysql也应该并必须担任起数据初加工以及粗加工的责任 ...

  5. NOIp2010 关押罪犯

    二分+2-SAT 先预处理出所有的v,然后离散化一下,在那个的基础上二分,对于每次二分出的值约束边权超过所二分出的边权的两点. //OJ 1322 //by Cydiater //2015.8.26 ...

  6. SQL ALTER TABLE 语句在项目中的使用

    1.在实际的项目开发过程中,之前已经创建好的实体类可能需要增加/删除字段,亦或是更改已有字段的属性,比如主键的增长策略从自增型改为UUID型,那么就会涉及到 SQL 中 alter table 语句的 ...

  7. 用css进行布局

     用css进行布局 一,开始布局的注意事项 1.作为最佳实践,应把html(内容)和css(显示)分离: 2.网站设计主要有两大类型:固定宽度(基于像素)和响应式(也称流式,使用百分数定义) 二,构建 ...

  8. C#中int,string,char[],char的转换(待续)

    //char[]转string string mm = "woshicainiao"; char[] ss = mm.ToCharArray(); string AA = new ...

  9. SVN服务器配置说明

    1.前 言 花了72小时,终于把 Subversion 初步掌握了.从一个连“什么是版本控制”都不知道的门外汉,到配置出精确至每目录访问的入门者,中间还卡了一天时间.其中费了许多气力,摸索实验了多次, ...

  10. JavaWeb学习笔记——开发动态WEB资源(六)ServletConfig和ServletContext

    1.只有在第一次请求服务器产生实例的时候才会调用init()方法,有一种办法能在服务器一启动的时候就加载init()方法. 即服务器启动即加载Servlet,且按数字大小顺序实例化Servlet. 方 ...