Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这样都wa?为啥? who can tell me#include <stdio.h> #include <stdlib.h> #include <string.h> int k, n, num; struct edge{ int p; edge *next; }; int no1[1024]; int non[1024]; struct node{ int noe; edge* first; }nd[1024]; double tp[1024]; double p[1024]; double p2[1024]; double ans; double ans2; void init(){ int i, t; memset(no1, 0, sizeof(no1)); for(i = 0; i < 1024; i++){ t = i; while(t > 0){ no1[i] += (t & 1); non[i] += 1; t >>= 1; } } non[0] = 1; } int main(){ int e, i, a, b, j, x; edge *ep; init(); while(scanf("%d%d%d", &k, &n, &e), k != 0){ num = (1 << n); for(i = 0; i < num; i++) tp[i] = p[i] = 1 / (double)num; memset(nd, 0, sizeof(nd)); for(i = 0; i < e; i++){ scanf("%d%d", &a, &b); ep = (edge *)malloc(sizeof(edge)); ep->p = b; ep->next = nd[a].first; nd[a].first = ep; nd[a].noe++; ep = (edge *)malloc(sizeof(edge)); ep->p = a; ep->next = nd[b].first; nd[b].first = ep; nd[b].noe++; } for(i = 1; i < k; i++){ for(j = 0; j < num; j++){ p2[j] = 0; } for(j = 0; j < num; j++){ ep = nd[j].first; x = 0; while(x++ < nd[j].noe){ p2[ep->p] += p[j] / (double)nd[j].noe; ep = ep->next; } } for(j = 0; j < num; j++){ p[j] = p2[j]; tp[j] += p[j]; } } ans2 = ans = 0; for(i = 0; i < num; i++){ ans += tp[i] * no1[i]; ans2 += tp[i] * non[i]; } ans /= ans2; if(ans >= 0.25 && ans <= 0.75) printf("Yes\n"); else printf("No\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator