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. 【BZOJ-4519】不同的最小割 最小割树(分治+最小割)

    4519: [Cqoi2016]不同的最小割 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 393  Solved: 239[Submit][Stat ...

  2. 【BZOJ-3308】九月的咖啡店 最大费用最大流 + 线性筛素数

    3308: 九月的咖啡店 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 159  Solved: 56[Submit][Status][Discuss ...

  3. 洛谷P2242 公路维修问题(Road)

    题目描述 在一个夜黑风高,下着暴风雨的夜晚,farmer John的牛棚的屋顶.门被吹飞了. 好在许多牛正在度假,所以牛棚没有住满. 牛棚一个紧挨着另一个被排成一行,牛就住在里面过夜. 有些牛棚里有牛 ...

  4. Jsoncpp Compiler、Programming

    catalog . C++ jsoncpp简介 . Jsoncpp的下载与编译 . Linux Jsoncpp的SDK编译 & 简单实例 . Windows Jsoncpp的SDK编译 &am ...

  5. css3新增属性API

    写在前面:由于CSS5标准还未完全订下来,所以各种内核的浏览器都有自己的标准,为了不使属性混淆,所以各家在各自标准前加了一个前缀. -moz-  主要是firefox火狐 -webikt-主要是chr ...

  6. iOS - libc++abi.dylib: terminate_handler unexpectedly threw an exception

    代码出现crash,报错:libc++abi.dylib: terminate_handler unexpectedly threw an exception 当我们很明确是某一块代码执行导致了错误, ...

  7. POJMatrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 22058   Accepted: 8219 Descripti ...

  8. web前端环境搭建

    第一部分:浏览器 浏览器推荐chrome浏览器.FireFox浏览器. 1. chrome浏览器因为集成了Google Developer Tools(谷歌开发者工具),因此大受欢迎. 下载地址:ht ...

  9. ES6之let(理解闭包)和const命令

    ES6之let(理解闭包)和const命令 最近做项目的过程中,使用到了ES6,因为之前很少接触,所以使用起来还不够熟悉.因此购买了阮一峰老师的ES6标准入门,在此感谢阮一峰老师的著作. 我们知道,E ...

  10. JavaWeb---总结(七)HttpServletResponse对象(一)

    Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象. request和response对象即然代表请求和响应,那我们 ...