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 |
哪位兄弟帮忙看下,为什么我的代码是RUNTIME ERROR!!!真的想不通!!!!!!!!#include<iostream> #include<cstdio> #include <ctype.h> using namespace std; int father[100000]; int result[100000],n; void init() { memset(father,0,sizeof(father)); memset(result,0,sizeof(result)); } void read() { void solve(int t1,int t2); for(int i=0;i<n;++i) { int k1,k; scanf("%d:(%d)",&k1,&k); for(int j=1;j<=k;++j) { int k2; scanf("%d",&k2); father[k2]=k1;//k2的父亲结点是k1 } } int k; scanf("%d",&k); int t1,t2; for(int i=0;i<k;++i) { char c,c3; while(c=getchar()){ if(isdigit(c)||c=='('||c==')') break; } scanf("%d%d%c",&t1,&t2,&c3); //cout<<"t1="<<t1<<",c2="<<c2<<",t2="<<t2<<",c3="<<c3<<endl; solve(t1,t2); } } bool is_farther(int t1,int t2)//判断t1是否是t2的father { while(t2!=0&&father[t2]!=0) { if(father[t2]==t1) return true; t2=father[t2]; } return false; } void solve(int t1,int t2) { if(t1==t2) {++result[t1];return ;} if(is_farther(t1,t2)) {++result[t1];return ;} if(is_farther(t2,t1)) {++result[t2];return ;} while(father[t1]!=0) { t1=father[t1]; if(is_farther(t1,t2)) { ++result[t1];//t1是两者的公共父亲 return ; } } } void out() { for(int i=1;i<=n;++i) if(result[i]!=0) printf("%d:%d\n",i,result[i]); } int main() { while(scanf("%d",&n)) { init(); read(); out(); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator