J - Just Pour the Water 解题报告
2012-09-15 16:45
309 查看
本次比赛隐藏水题之一。。。
估计这题看到 M 10^9 就跪了一半了吧。。。
可是每个操作都是重复的,最多循环到一个程度,值就不会变了,所以用 a[], d[] 两个数组记录前后的两个状态,如果状态不在改变即可 break 了。。。
估计这题看到 M 10^9 就跪了一半了吧。。。
可是每个操作都是重复的,最多循环到一个程度,值就不会变了,所以用 a[], d[] 两个数组记录前后的两个状态,如果状态不在改变即可 break 了。。。
#include<cstdio> #include<cstring> #define esp 1e-5 #define sf scanf double a[25],c[25],d[25]; int k[25]; int b[25][25]; double abs(double x){ return x>0?x:-x; } int main() { int t,n,m,i,j; sf("%d",&t); while(t--){ memset(b,0,sizeof(b)); sf("%d",&n); for(i=1;i<=n;i++) sf("%lf",a+i); for(i=1;i<=n;i++){ sf("%d",k+i); for(j=0;j<k[i];j++) sf("%d",&b[i][j]); } sf("%d",&m); while(m--){ for(i=1;i<=n;i++){ if(k[i]!=0) c[i]=a[i]/(double)k[i]; d[i]=0; } for(i=1;i<=n;i++){ j=0; if(k[i]==0) {d[i]+=a[i];continue;} while(b[i][j]){ d[b[i][j]]+=c[i]; j++; } } for(i=1;i<=n;i++) if(abs(a[i]-d[i])>esp) break; if(i==n+1) break; for(i=1;i<=n;i++) a[i]=d[i]; } for(i=1;i<=n;i++) printf("%.2lf%c",d[i],i==n?'\n':' '); } return 0; }
相关文章推荐
- ZOJ 2794 Just Pour the Water 【矩阵快速幂】
- [矩阵幂运算] ZOJ 2974 Just Pour the Water
- ZOJ 2974 Just Pour the Water(矩阵快速幂)
- ZOJ 2974 Just Pour the Water【5th浙江省赛】【矩阵乘法】
- bnuoj 16493 Just Pour the Water(矩阵快速幂)
- ZOJ 2974 Just Pour the Water
- zoj 2974 Just Pour the Water
- ZOJ 1973 Just Pour the Water(矩阵快速幂)
- ZOJ 2974-Just Pour the Water(矩阵快速幂)
- HDU 5443 The Water Problem 解题报告(如题)
- ZOJ 2974 Just Pour the Water(矩阵快速幂)
- 【ACM菜逼解题报告】The Dragon of Loowater
- zoj 2974 Just Pour the Water矩阵快速幂
- [Leetcode] 755. Pour Water 解题报告
- 【矩阵快速幂】ZOJ 2974 Just Pour the Water
- ZOJ2974-Just Pour the Water
- POJ-2974 Just Pour the Water (矩阵快速冥)
- zoj 2974 Just Pour the Water (矩阵快速幂,简单)
- ZOJ 2974 Just Pour the Water
- 【矩阵快速幂】ZOJ 2974 Just Pour the Water