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. Ajax请求接口加密研究(针对网页前端的接口安全加密机制研究)

    通常我们在h5前端调用后台接口时,一般是ajax,那么接口的安全成了一个问题. 这里可以肯定的说,前端调用的接口一定要验证! 然后剖析了微信网页版.京东网页版这些,也都是通过接口的形势绑定数据,所以在 ...

  2. poj 2528 线段树+离散化

    题意:在墙上贴一堆海报(只看横坐标,可以抽象成一线段),新海报可以覆盖旧海报.求最后能看到多少张海报 sol:线段树成段更新.铺第i张海报的时候更新sg[i].x~sg[i].y这一段为i. 然而坐标 ...

  3. J-link烧写brjtag工具

    J-Link用的山寨货,不知道山寨了几代的那种....用的STM32F103C8T6的小板也是山寨了好几代那种,才25块钱...好在能用,J-Link用segger公司的软件能识别,也能找到CPU,板 ...

  4. sed命令给文本文件的每行的行首或者行尾添加文字

    在每行的头添加字符,比如"HEAD",命令如下: sed 's/^/HEAD&/g' test.file 在每行的行尾添加字符,比如“TAIL”,命令如下: sed 's/ ...

  5. 如何保持自己 fork 的项目和原始项目同步

    首先先通过 github 的 web 页面 fork 目标的项目 前提是自己已经设置好了git,并且配置了相应的权限 然后使用git clone命令在本地克隆自己 fork 的项目: git clon ...

  6. AngularJs ngInclude、ngTransclude

    这两个都是HTML DOM嵌入指令 ngInclude 读取,编译和插入外部的HTML片段. 格式:ng-include=“value”<ng-include src=”value” onloa ...

  7. python dict.get()和dict['key']的区别

    先看代码: In [1]: a = {'name': 'wang'} In [2]: a.get('age') In [3]: a['age'] --------------------------- ...

  8. 【项目】UICollectionView 对象自定

    陈述一下简单流程: 1.首先定义:UICollectionViewFlowLayout 2.初始化UICollectionView 3.注册复用的cell,定义她们的reuseIndefinite 4 ...

  9. 浅谈DDOS攻击

    preface 做过网站运维的同事来说,绝对遇到过DDOS的攻击吧,这样的攻击实属令人头疼,那么今年就说DDOS的攻击与防护吧. 原理 DDOS(Distributed Denial Of Servi ...

  10. Docker change directory

    https://forums.docker.com/t/how-do-i-change-the-docker-image-installation-directory/1169/2 How do I ...